Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ | 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ |
| 6 #define NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ | 6 #define NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 class IOBuffer; | 27 class IOBuffer; |
| 28 class URLRequestContext; | 28 class URLRequestContext; |
| 29 | 29 |
| 30 // Transport-independent implementation of WebSockets. Implements protocol | 30 // Transport-independent implementation of WebSockets. Implements protocol |
| 31 // semantics that do not depend on the underlying transport. Provides the | 31 // semantics that do not depend on the underlying transport. Provides the |
| 32 // interface to the content layer. Some WebSocket concepts are used here without | 32 // interface to the content layer. Some WebSocket concepts are used here without |
| 33 // definition; please see the RFC at http://tools.ietf.org/html/rfc6455 for | 33 // definition; please see the RFC at http://tools.ietf.org/html/rfc6455 for |
| 34 // clarification. | 34 // clarification. |
| 35 class NET_EXPORT WebSocketChannel { | 35 class NET_EXPORT WebSocketChannel { |
| 36 public: | 36 public: |
| 37 // The type of a WebSocketStream factory callback. Must match the signature of | 37 // The type of a WebSocketStream creator callback. Must match the signature of |
| 38 // WebSocketStream::CreateAndConnectStream(). | 38 // WebSocketStream::CreateAndConnectStream(). |
| 39 typedef base::Callback<scoped_ptr<WebSocketStreamRequest>( | 39 typedef base::Callback<scoped_ptr<WebSocketStreamRequest>( |
| 40 const GURL&, | 40 const GURL&, |
| 41 const std::vector<std::string>&, | 41 const std::vector<std::string>&, |
| 42 const GURL&, | 42 const GURL&, |
| 43 URLRequestContext*, | 43 URLRequestContext*, |
| 44 const BoundNetLog&, | 44 const BoundNetLog&, |
| 45 scoped_ptr<WebSocketStream::ConnectDelegate>)> WebSocketStreamFactory; | 45 scoped_ptr<WebSocketStream::ConnectDelegate>)> WebSocketStreamCreator; |
| 46 | 46 |
| 47 // Creates a new WebSocketChannel in an idle state. | 47 // Creates a new WebSocketChannel in an idle state. |
| 48 // SendAddChannelRequest() must be called immediately afterwards to start the | 48 // SendAddChannelRequest() must be called immediately afterwards to start the |
| 49 // connection process. | 49 // connection process. |
| 50 WebSocketChannel(scoped_ptr<WebSocketEventInterface> event_interface, | 50 WebSocketChannel(scoped_ptr<WebSocketEventInterface> event_interface, |
| 51 URLRequestContext* url_request_context); | 51 URLRequestContext* url_request_context); |
| 52 virtual ~WebSocketChannel(); | 52 virtual ~WebSocketChannel(); |
| 53 | 53 |
| 54 // Starts the connection process. | 54 // Starts the connection process. |
| 55 void SendAddChannelRequest( | 55 void SendAddChannelRequest( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 81 // connection. There is no API to close the connection without a closing | 81 // connection. There is no API to close the connection without a closing |
| 82 // handshake, but destroying the WebSocketChannel object while connected will | 82 // handshake, but destroying the WebSocketChannel object while connected will |
| 83 // effectively do that. |code| must be in the range 1000-4999. |reason| should | 83 // effectively do that. |code| must be in the range 1000-4999. |reason| should |
| 84 // be a valid UTF-8 string or empty. | 84 // be a valid UTF-8 string or empty. |
| 85 // | 85 // |
| 86 // This does *not* trigger the event OnClosingHandshake(). The caller should | 86 // This does *not* trigger the event OnClosingHandshake(). The caller should |
| 87 // assume that the closing handshake has started and perform the equivalent | 87 // assume that the closing handshake has started and perform the equivalent |
| 88 // processing to OnClosingHandshake() if necessary. | 88 // processing to OnClosingHandshake() if necessary. |
| 89 void StartClosingHandshake(uint16 code, const std::string& reason); | 89 void StartClosingHandshake(uint16 code, const std::string& reason); |
| 90 | 90 |
| 91 // Starts the connection process, using a specified factory function rather | 91 // Starts the connection process, using a specified creator function rather |
|
tyoshino (SeeGerritForStatus)
2013/11/12 11:29:42
s/function/callback/ for consistency?
Adam Rice
2013/11/13 03:16:53
Done.
| |
| 92 // than the default. This is exposed for testing. | 92 // than the default. This is exposed for testing. |
| 93 void SendAddChannelRequestForTesting( | 93 void SendAddChannelRequestForTesting( |
| 94 const GURL& socket_url, | 94 const GURL& socket_url, |
| 95 const std::vector<std::string>& requested_protocols, | 95 const std::vector<std::string>& requested_protocols, |
| 96 const GURL& origin, | 96 const GURL& origin, |
| 97 const WebSocketStreamFactory& factory); | 97 const WebSocketStreamCreator& creator); |
| 98 | 98 |
| 99 // The default timout for the closing handshake is a sensible value (see | 99 // The default timout for the closing handshake is a sensible value (see |
| 100 // kClosingHandshakeTimeoutSeconds in websocket_channel.cc). However, we can | 100 // kClosingHandshakeTimeoutSeconds in websocket_channel.cc). However, we can |
| 101 // set it to a very small value for testing purposes. | 101 // set it to a very small value for testing purposes. |
| 102 void SetClosingHandshakeTimeoutForTesting(base::TimeDelta delay); | 102 void SetClosingHandshakeTimeoutForTesting(base::TimeDelta delay); |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 // Methods which return a value of type ChannelState may delete |this|. If the | 105 // Methods which return a value of type ChannelState may delete |this|. If the |
| 106 // return value is CHANNEL_DELETED, then the caller must return without making | 106 // return value is CHANNEL_DELETED, then the caller must return without making |
| 107 // any further access to member variables or methods. | 107 // any further access to member variables or methods. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 // Implementation of WebSocketStream::ConnectDelegate for | 135 // Implementation of WebSocketStream::ConnectDelegate for |
| 136 // WebSocketChannel. WebSocketChannel does not inherit from | 136 // WebSocketChannel. WebSocketChannel does not inherit from |
| 137 // WebSocketStream::ConnectDelegate directly to avoid cluttering the public | 137 // WebSocketStream::ConnectDelegate directly to avoid cluttering the public |
| 138 // interface with the implementation of those methods, and because the | 138 // interface with the implementation of those methods, and because the |
| 139 // lifetime of a WebSocketChannel is longer than the lifetime of the | 139 // lifetime of a WebSocketChannel is longer than the lifetime of the |
| 140 // connection process. | 140 // connection process. |
| 141 class ConnectDelegate; | 141 class ConnectDelegate; |
| 142 | 142 |
| 143 // Starts the connection progress, using a specified factory function. | 143 // Starts the connection progress, using the supplied creator function. |
|
tyoshino (SeeGerritForStatus)
2013/11/12 11:29:42
ditto
tyoshino (SeeGerritForStatus)
2013/11/12 11:29:42
progress -> process
Adam Rice
2013/11/13 03:16:53
Done.
Adam Rice
2013/11/13 03:16:53
Done.
| |
| 144 void SendAddChannelRequestWithFactory( | 144 void SendAddChannelRequestWithSuppliedCreator( |
| 145 const GURL& socket_url, | 145 const GURL& socket_url, |
| 146 const std::vector<std::string>& requested_protocols, | 146 const std::vector<std::string>& requested_protocols, |
| 147 const GURL& origin, | 147 const GURL& origin, |
| 148 const WebSocketStreamFactory& factory); | 148 const WebSocketStreamCreator& creator); |
| 149 | 149 |
| 150 // Success callback from WebSocketStream::CreateAndConnectStream(). Reports | 150 // Success callback from WebSocketStream::CreateAndConnectStream(). Reports |
| 151 // success to the event interface. May delete |this|. | 151 // success to the event interface. May delete |this|. |
| 152 void OnConnectSuccess(scoped_ptr<WebSocketStream> stream); | 152 void OnConnectSuccess(scoped_ptr<WebSocketStream> stream); |
| 153 | 153 |
| 154 // Failure callback from WebSocketStream::CreateAndConnectStream(). Reports | 154 // Failure callback from WebSocketStream::CreateAndConnectStream(). Reports |
| 155 // failure to the event interface. May delete |this|. | 155 // failure to the event interface. May delete |this|. |
| 156 void OnConnectFailure(uint16 websocket_error); | 156 void OnConnectFailure(uint16 websocket_error); |
| 157 | 157 |
| 158 // Returns true if state_ is SEND_CLOSED, CLOSE_WAIT or CLOSED. | 158 // Returns true if state_ is SEND_CLOSED, CLOSE_WAIT or CLOSED. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 // Called if the closing handshake times out. Closes the connection and | 231 // Called if the closing handshake times out. Closes the connection and |
| 232 // informs the |event_interface_| if appropriate. | 232 // informs the |event_interface_| if appropriate. |
| 233 void CloseTimeout(); | 233 void CloseTimeout(); |
| 234 | 234 |
| 235 // The URL of the remote server. | 235 // The URL of the remote server. |
| 236 GURL socket_url_; | 236 GURL socket_url_; |
| 237 | 237 |
| 238 // The object receiving events. | 238 // The object receiving events. |
| 239 const scoped_ptr<WebSocketEventInterface> event_interface_; | 239 const scoped_ptr<WebSocketEventInterface> event_interface_; |
| 240 | 240 |
| 241 // The URLRequestContext to pass to the WebSocketStream factory. | 241 // The URLRequestContext to pass to the WebSocketStream creator. |
| 242 URLRequestContext* const url_request_context_; | 242 URLRequestContext* const url_request_context_; |
| 243 | 243 |
| 244 // The WebSocketStream on which to send and receive data. | 244 // The WebSocketStream on which to send and receive data. |
| 245 scoped_ptr<WebSocketStream> stream_; | 245 scoped_ptr<WebSocketStream> stream_; |
| 246 | 246 |
| 247 // A data structure containing a vector of frames to be sent and the total | 247 // A data structure containing a vector of frames to be sent and the total |
| 248 // number of bytes contained in the vector. | 248 // number of bytes contained in the vector. |
| 249 class SendBuffer; | 249 class SendBuffer; |
| 250 // Data that is currently pending write, or NULL if no write is pending. | 250 // Data that is currently pending write, or NULL if no write is pending. |
| 251 scoped_ptr<SendBuffer> data_being_sent_; | 251 scoped_ptr<SendBuffer> data_being_sent_; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 // The current state of the channel. Mainly used for sanity checking, but also | 286 // The current state of the channel. Mainly used for sanity checking, but also |
| 287 // used to track the close state. | 287 // used to track the close state. |
| 288 State state_; | 288 State state_; |
| 289 | 289 |
| 290 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel); | 290 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel); |
| 291 }; | 291 }; |
| 292 | 292 |
| 293 } // namespace net | 293 } // namespace net |
| 294 | 294 |
| 295 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ | 295 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ |
| OLD | NEW |