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 #include "net/websockets/websocket_stream.h" 14 15 namespace net { 16 17 // Implementation of WebSocketHandshakeStreamBase::CreateHelper. This class is 18 // used in the implementation of WebSocketStream::CreateAndConnectStream() and 19 // is not intended to be used by itself. 20 // 21 // Holds the information needed to construct a 22 // WebSocketBasicHandshakeStreamBase. 23 class NET_EXPORT_PRIVATE WebSocketHandshakeStreamCreateHelper 24 : public WebSocketHandshakeStreamBase::CreateHelper { 25 public: 26 // |connect_delegate| must out-live this object. 27 explicit WebSocketHandshakeStreamCreateHelper( 28 WebSocketStream::ConnectDelegate* connect_delegate, 29 const std::vector<std::string>& requested_subprotocols); 30 31 virtual ~WebSocketHandshakeStreamCreateHelper(); 32 33 // WebSocketHandshakeStreamBase::CreateHelper methods 34 35 // Create a WebSocketBasicHandshakeStream. 36 virtual WebSocketHandshakeStreamBase* CreateBasicStream( 37 scoped_ptr<ClientSocketHandle> connection, 38 bool using_proxy) OVERRIDE; 39 40 // Unimplemented as of November 2013. 41 virtual WebSocketHandshakeStreamBase* CreateSpdyStream( 42 const base::WeakPtr<SpdySession>& session, 43 bool use_relative_url) OVERRIDE; 44 45 // Return the WebSocketHandshakeStreamBase object that we created. In the case 46 // where CreateBasicStream() was called more than once, returns the most 47 // recent stream, which will be the one on which the handshake succeeded. 48 // It is not safe to call this if the handshake failed. 49 WebSocketHandshakeStreamBase* stream() { return stream_; } 50 51 // Set a pointer to the std::string into which to write any failure messages 52 // that are encountered. This method must be called before CreateBasicStream() 53 // or CreateSpdyStream(). The |failure_message| pointer must remain valid as 54 // long as this object exists. 55 void set_failure_message(std::string* failure_message) { 56 failure_message_ = failure_message; 57 } 58 59 private: 60 const std::vector<std::string> requested_subprotocols_; 61 62 // This is owned by the caller of CreateBaseStream() or 63 // CreateSpdyStream(). Both the stream and this object will be destroyed 64 // during the destruction of the URLRequest object associated with the 65 // handshake. This is only guaranteed to be a valid pointer if the handshake 66 // succeeded. 67 WebSocketHandshakeStreamBase* stream_; 68 69 WebSocketStream::ConnectDelegate* connect_delegate_; 70 std::string* failure_message_; 71 72 DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeStreamCreateHelper); 73 }; 74 75 } // namespace net 76 77 #endif // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_CREATE_HELPER_H_ 78