[MediaRouter] Update MR-2-Extension's PostMessage to return boolean.
[chromium-blink-merge.git] / net / websockets / websocket_handshake_stream_create_helper.h
blob83bb1ac75618ec9e9e73758744a04a6138c60e54
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_
8 #include <string>
9 #include <vector>
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"
16 namespace net {
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 {
28 public:
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 ~WebSocketHandshakeStreamCreateHelper() override;
36 // WebSocketHandshakeStreamBase::CreateHelper methods
38 // Create a WebSocketBasicHandshakeStream.
39 WebSocketHandshakeStreamBase* CreateBasicStream(
40 scoped_ptr<ClientSocketHandle> connection,
41 bool using_proxy) override;
43 // Unimplemented as of November 2013.
44 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;
60 protected:
61 // This is used by DeterministicKeyWebSocketHandshakeStreamCreateHelper.
62 // The default implementation does nothing.
63 virtual void OnStreamCreated(WebSocketBasicHandshakeStream* stream);
65 private:
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
72 // succeeded.
73 WebSocketHandshakeStreamBase* stream_;
75 WebSocketStream::ConnectDelegate* connect_delegate_;
76 std::string* failure_message_;
78 DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeStreamCreateHelper);
81 } // namespace net
83 #endif // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_CREATE_HELPER_H_