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.
5 #ifndef NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_CREATE_HELPER_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_CREATE_HELPER_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "net/base/net_export.h"
13 #include "net/websockets/websocket_handshake_stream_base.h"
14 #include "net/websockets/websocket_stream.h"
18 class WebSocketBasicHandshakeStream
;
20 // Implementation of WebSocketHandshakeStreamBase::CreateHelper. This class is
21 // used in the implementation of WebSocketStream::CreateAndConnectStream() and
22 // is not intended to be used by itself.
24 // Holds the information needed to construct a
25 // WebSocketBasicHandshakeStreamBase.
26 class NET_EXPORT_PRIVATE WebSocketHandshakeStreamCreateHelper
27 : public WebSocketHandshakeStreamBase::CreateHelper
{
29 // |connect_delegate| must out-live this object.
30 explicit WebSocketHandshakeStreamCreateHelper(
31 WebSocketStream::ConnectDelegate
* connect_delegate
,
32 const std::vector
<std::string
>& requested_subprotocols
);
34 virtual ~WebSocketHandshakeStreamCreateHelper();
36 // WebSocketHandshakeStreamBase::CreateHelper methods
38 // Create a WebSocketBasicHandshakeStream.
39 virtual WebSocketHandshakeStreamBase
* CreateBasicStream(
40 scoped_ptr
<ClientSocketHandle
> connection
,
41 bool using_proxy
) OVERRIDE
;
43 // Unimplemented as of November 2013.
44 virtual WebSocketHandshakeStreamBase
* CreateSpdyStream(
45 const base::WeakPtr
<SpdySession
>& session
,
46 bool use_relative_url
) OVERRIDE
;
48 // Call Upgrade() on the WebSocketHandshakeStream and return the result. This
49 // must only be called if the handshake succeeded.
50 scoped_ptr
<WebSocketStream
> Upgrade();
52 // Set a pointer to the std::string into which to write any failure messages
53 // that are encountered. This method must be called before CreateBasicStream()
54 // or CreateSpdyStream(). The |failure_message| pointer must remain valid as
55 // long as this object exists.
56 void set_failure_message(std::string
* failure_message
) {
57 failure_message_
= failure_message
;
61 // This is used by DeterministicKeyWebSocketHandshakeStreamCreateHelper.
62 // The default implementation does nothing.
63 virtual void OnStreamCreated(WebSocketBasicHandshakeStream
* stream
);
66 const std::vector
<std::string
> requested_subprotocols_
;
68 // This is owned by the caller of CreateBaseStream() or
69 // CreateSpdyStream(). Both the stream and this object will be destroyed
70 // during the destruction of the URLRequest object associated with the
71 // handshake. This is only guaranteed to be a valid pointer if the handshake
73 WebSocketHandshakeStreamBase
* stream_
;
75 WebSocketStream::ConnectDelegate
* connect_delegate_
;
76 std::string
* failure_message_
;
78 DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeStreamCreateHelper
);
83 #endif // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_CREATE_HELPER_H_