| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // definition; please see the RFC at http://tools.ietf.org/html/rfc6455 for | 43 // definition; please see the RFC at http://tools.ietf.org/html/rfc6455 for |
| 44 // clarification. | 44 // clarification. |
| 45 class NET_EXPORT WebSocketChannel { | 45 class NET_EXPORT WebSocketChannel { |
| 46 public: | 46 public: |
| 47 // The type of a WebSocketStream creator callback. Must match the signature of | 47 // The type of a WebSocketStream creator callback. Must match the signature of |
| 48 // WebSocketStream::CreateAndConnectStream(). | 48 // WebSocketStream::CreateAndConnectStream(). |
| 49 typedef base::Callback<std::unique_ptr<WebSocketStreamRequest>( | 49 typedef base::Callback<std::unique_ptr<WebSocketStreamRequest>( |
| 50 const GURL&, | 50 const GURL&, |
| 51 const std::vector<std::string>&, | 51 const std::vector<std::string>&, |
| 52 const url::Origin&, | 52 const url::Origin&, |
| 53 const std::string&, |
| 53 URLRequestContext*, | 54 URLRequestContext*, |
| 54 const BoundNetLog&, | 55 const BoundNetLog&, |
| 55 std::unique_ptr<WebSocketStream::ConnectDelegate>)> | 56 std::unique_ptr<WebSocketStream::ConnectDelegate>)> |
| 56 WebSocketStreamCreator; | 57 WebSocketStreamCreator; |
| 57 | 58 |
| 58 // Methods which return a value of type ChannelState may delete |this|. If the | 59 // Methods which return a value of type ChannelState may delete |this|. If the |
| 59 // return value is CHANNEL_DELETED, then the caller must return without making | 60 // return value is CHANNEL_DELETED, then the caller must return without making |
| 60 // any further access to member variables or methods. | 61 // any further access to member variables or methods. |
| 61 using ChannelState = WebSocketEventInterface::ChannelState; | 62 using ChannelState = WebSocketEventInterface::ChannelState; |
| 62 | 63 |
| 63 // Creates a new WebSocketChannel in an idle state. | 64 // Creates a new WebSocketChannel in an idle state. |
| 64 // SendAddChannelRequest() must be called immediately afterwards to start the | 65 // SendAddChannelRequest() must be called immediately afterwards to start the |
| 65 // connection process. | 66 // connection process. |
| 66 WebSocketChannel(std::unique_ptr<WebSocketEventInterface> event_interface, | 67 WebSocketChannel(std::unique_ptr<WebSocketEventInterface> event_interface, |
| 67 URLRequestContext* url_request_context); | 68 URLRequestContext* url_request_context); |
| 68 virtual ~WebSocketChannel(); | 69 virtual ~WebSocketChannel(); |
| 69 | 70 |
| 70 // Starts the connection process. | 71 // Starts the connection process. |
| 71 void SendAddChannelRequest( | 72 void SendAddChannelRequest( |
| 72 const GURL& socket_url, | 73 const GURL& socket_url, |
| 73 const std::vector<std::string>& requested_protocols, | 74 const std::vector<std::string>& requested_protocols, |
| 74 const url::Origin& origin); | 75 const url::Origin& origin, |
| 76 const std::string& additional_headers); |
| 75 | 77 |
| 76 // Sends a data frame to the remote side. It is the responsibility of the | 78 // Sends a data frame to the remote side. It is the responsibility of the |
| 77 // caller to ensure that they have sufficient send quota to send this data, | 79 // caller to ensure that they have sufficient send quota to send this data, |
| 78 // otherwise the connection will be closed without sending. |fin| indicates | 80 // otherwise the connection will be closed without sending. |fin| indicates |
| 79 // the last frame in a message, equivalent to "FIN" as specified in section | 81 // the last frame in a message, equivalent to "FIN" as specified in section |
| 80 // 5.2 of RFC6455. |data| is the "Payload Data". If |op_code| is kOpCodeText, | 82 // 5.2 of RFC6455. |data| is the "Payload Data". If |op_code| is kOpCodeText, |
| 81 // or it is kOpCodeContinuation and the type the message is Text, then |data| | 83 // or it is kOpCodeContinuation and the type the message is Text, then |data| |
| 82 // must be a chunk of a valid UTF-8 message, however there is no requirement | 84 // must be a chunk of a valid UTF-8 message, however there is no requirement |
| 83 // for |data| to be split on character boundaries. Calling SendFrame may | 85 // for |data| to be split on character boundaries. Calling SendFrame may |
| 84 // result in synchronous calls to |event_interface_| which may result in this | 86 // result in synchronous calls to |event_interface_| which may result in this |
| (...skipping 29 matching lines...) Expand all Loading... |
| 114 // valid for the execution of the current Task or until SendFrame() is called, | 116 // valid for the execution of the current Task or until SendFrame() is called, |
| 115 // whichever happens sooner. | 117 // whichever happens sooner. |
| 116 int current_send_quota() const { return current_send_quota_; } | 118 int current_send_quota() const { return current_send_quota_; } |
| 117 | 119 |
| 118 // Starts the connection process, using a specified creator callback rather | 120 // Starts the connection process, using a specified creator callback rather |
| 119 // than the default. This is exposed for testing. | 121 // than the default. This is exposed for testing. |
| 120 void SendAddChannelRequestForTesting( | 122 void SendAddChannelRequestForTesting( |
| 121 const GURL& socket_url, | 123 const GURL& socket_url, |
| 122 const std::vector<std::string>& requested_protocols, | 124 const std::vector<std::string>& requested_protocols, |
| 123 const url::Origin& origin, | 125 const url::Origin& origin, |
| 126 const std::string& additional_headers, |
| 124 const WebSocketStreamCreator& creator); | 127 const WebSocketStreamCreator& creator); |
| 125 | 128 |
| 126 // The default timout for the closing handshake is a sensible value (see | 129 // The default timout for the closing handshake is a sensible value (see |
| 127 // kClosingHandshakeTimeoutSeconds in websocket_channel.cc). However, we can | 130 // kClosingHandshakeTimeoutSeconds in websocket_channel.cc). However, we can |
| 128 // set it to a very small value for testing purposes. | 131 // set it to a very small value for testing purposes. |
| 129 void SetClosingHandshakeTimeoutForTesting(base::TimeDelta delay); | 132 void SetClosingHandshakeTimeoutForTesting(base::TimeDelta delay); |
| 130 | 133 |
| 131 // The default timout for the underlying connection close is a sensible value | 134 // The default timout for the underlying connection close is a sensible value |
| 132 // (see kUnderlyingConnectionCloseTimeoutSeconds in websocket_channel.cc). | 135 // (see kUnderlyingConnectionCloseTimeoutSeconds in websocket_channel.cc). |
| 133 // However, we can set it to a very small value for testing purposes. | 136 // However, we can set it to a very small value for testing purposes. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // interface with the implementation of those methods, and because the | 209 // interface with the implementation of those methods, and because the |
| 207 // lifetime of a WebSocketChannel is longer than the lifetime of the | 210 // lifetime of a WebSocketChannel is longer than the lifetime of the |
| 208 // connection process. | 211 // connection process. |
| 209 class ConnectDelegate; | 212 class ConnectDelegate; |
| 210 | 213 |
| 211 // Starts the connection process, using the supplied creator callback. | 214 // Starts the connection process, using the supplied creator callback. |
| 212 void SendAddChannelRequestWithSuppliedCreator( | 215 void SendAddChannelRequestWithSuppliedCreator( |
| 213 const GURL& socket_url, | 216 const GURL& socket_url, |
| 214 const std::vector<std::string>& requested_protocols, | 217 const std::vector<std::string>& requested_protocols, |
| 215 const url::Origin& origin, | 218 const url::Origin& origin, |
| 219 const std::string& additional_headers, |
| 216 const WebSocketStreamCreator& creator); | 220 const WebSocketStreamCreator& creator); |
| 217 | 221 |
| 218 // Success callback from WebSocketStream::CreateAndConnectStream(). Reports | 222 // Success callback from WebSocketStream::CreateAndConnectStream(). Reports |
| 219 // success to the event interface. May delete |this|. | 223 // success to the event interface. May delete |this|. |
| 220 void OnConnectSuccess(std::unique_ptr<WebSocketStream> stream); | 224 void OnConnectSuccess(std::unique_ptr<WebSocketStream> stream); |
| 221 | 225 |
| 222 // Failure callback from WebSocketStream::CreateAndConnectStream(). Reports | 226 // Failure callback from WebSocketStream::CreateAndConnectStream(). Reports |
| 223 // failure to the event interface. May delete |this|. | 227 // failure to the event interface. May delete |this|. |
| 224 void OnConnectFailure(const std::string& message); | 228 void OnConnectFailure(const std::string& message); |
| 225 | 229 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 // For UMA. The time when OnConnectSuccess() method was called and |stream_| | 441 // For UMA. The time when OnConnectSuccess() method was called and |stream_| |
| 438 // was set. | 442 // was set. |
| 439 base::TimeTicks established_on_; | 443 base::TimeTicks established_on_; |
| 440 | 444 |
| 441 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel); | 445 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel); |
| 442 }; | 446 }; |
| 443 | 447 |
| 444 } // namespace net | 448 } // namespace net |
| 445 | 449 |
| 446 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ | 450 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ |
| OLD | NEW |