Home | History | Annotate | Download | only in websockets
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_CREATE_HELPER_H_
      6 #define NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_CREATE_HELPER_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "net/base/net_export.h"
     12 #include "net/websockets/websocket_handshake_stream_base.h"
     13 
     14 namespace net {
     15 
     16 // Implementation of WebSocketHandshakeStreamBase::CreateHelper. This class is
     17 // used in the implementation of WebSocketStream::CreateAndConnectStream() and
     18 // is not intended to be used by itself.
     19 //
     20 // Holds the information needed to construct a
     21 // WebSocketBasicHandshakeStreamBase.
     22 class NET_EXPORT_PRIVATE WebSocketHandshakeStreamCreateHelper
     23     : public WebSocketHandshakeStreamBase::CreateHelper {
     24  public:
     25   explicit WebSocketHandshakeStreamCreateHelper(
     26       const std::vector<std::string>& requested_subprotocols);
     27 
     28   virtual ~WebSocketHandshakeStreamCreateHelper();
     29 
     30   // WebSocketHandshakeStreamBase::CreateHelper methods
     31 
     32   // Create a WebSocketBasicHandshakeStream.
     33   virtual WebSocketHandshakeStreamBase* CreateBasicStream(
     34       scoped_ptr<ClientSocketHandle> connection,
     35       bool using_proxy) OVERRIDE;
     36 
     37   // Unimplemented as of November 2013.
     38   virtual WebSocketHandshakeStreamBase* CreateSpdyStream(
     39       const base::WeakPtr<SpdySession>& session,
     40       bool use_relative_url) OVERRIDE;
     41 
     42   // Return the WebSocketHandshakeStreamBase object that we created. In the case
     43   // where CreateBasicStream() was called more than once, returns the most
     44   // recent stream, which will be the one on which the handshake succeeded.
     45   WebSocketHandshakeStreamBase* stream() { return stream_; }
     46 
     47  private:
     48   const std::vector<std::string> requested_subprotocols_;
     49 
     50   // This is owned by the caller of CreateBaseStream() or
     51   // CreateSpdyStream(). Both the stream and this object will be destroyed
     52   // during the destruction of the URLRequest object associated with the
     53   // handshake.
     54   WebSocketHandshakeStreamBase* stream_;
     55 
     56   DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeStreamCreateHelper);
     57 };
     58 
     59 }  // namespace net
     60 
     61 #endif  // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_CREATE_HELPER_H_
     62