| 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 <queue> | 10 #include <queue> |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // result in synchronous calls to |event_interface_| which may result in this | 83 // result in synchronous calls to |event_interface_| which may result in this |
| 84 // object being deleted. In that case, the return value will be | 84 // object being deleted. In that case, the return value will be |
| 85 // CHANNEL_DELETED. | 85 // CHANNEL_DELETED. |
| 86 ChannelState SendFrame(bool fin, | 86 ChannelState SendFrame(bool fin, |
| 87 WebSocketFrameHeader::OpCode op_code, | 87 WebSocketFrameHeader::OpCode op_code, |
| 88 const std::vector<char>& data); | 88 const std::vector<char>& data); |
| 89 | 89 |
| 90 // Sends |quota| units of flow control to the remote side. If the underlying | 90 // Sends |quota| units of flow control to the remote side. If the underlying |
| 91 // transport has a concept of |quota|, then it permits the remote server to | 91 // transport has a concept of |quota|, then it permits the remote server to |
| 92 // send up to |quota| units of data. | 92 // send up to |quota| units of data. |
| 93 void SendFlowControl(int64_t quota); | 93 // |
| 94 // Calling this function may result in synchronous calls to |event_interface_| |
| 95 // which may result in this object being deleted. In that case, the return |
| 96 // value will be CHANNEL_DELETED. |
| 97 ChannelState SendFlowControl(int64_t quota) WARN_UNUSED_RESULT; |
| 94 | 98 |
| 95 // Starts the closing handshake for a client-initiated shutdown of the | 99 // Starts the closing handshake for a client-initiated shutdown of the |
| 96 // connection. There is no API to close the connection without a closing | 100 // connection. There is no API to close the connection without a closing |
| 97 // handshake, but destroying the WebSocketChannel object while connected will | 101 // handshake, but destroying the WebSocketChannel object while connected will |
| 98 // effectively do that. |code| must be in the range 1000-4999. |reason| should | 102 // effectively do that. |code| must be in the range 1000-4999. |reason| should |
| 99 // be a valid UTF-8 string or empty. | 103 // be a valid UTF-8 string or empty. |
| 100 // | 104 // |
| 101 // This does *not* trigger the event OnClosingHandshake(). The caller should | 105 // Calling this function may result in synchronous calls to |event_interface_| |
| 102 // assume that the closing handshake has started and perform the equivalent | 106 // which may result in this object being deleted. In that case, the return |
| 103 // processing to OnClosingHandshake() if necessary. | 107 // value will be CHANNEL_DELETED. |
| 104 void StartClosingHandshake(uint16_t code, const std::string& reason); | 108 ChannelState StartClosingHandshake(uint16_t code, const std::string& reason) |
| 109 WARN_UNUSED_RESULT; |
| 105 | 110 |
| 106 // Returns the current send quota. This value is unsafe to use outside of the | 111 // Returns the current send quota. This value is unsafe to use outside of the |
| 107 // browser IO thread because it changes asynchronously. The value is only | 112 // browser IO thread because it changes asynchronously. The value is only |
| 108 // valid for the execution of the current Task or until SendFrame() is called, | 113 // valid for the execution of the current Task or until SendFrame() is called, |
| 109 // whichever happens sooner. | 114 // whichever happens sooner. |
| 110 int current_send_quota() const { return current_send_quota_; } | 115 int current_send_quota() const { return current_send_quota_; } |
| 111 | 116 |
| 112 // Starts the connection process, using a specified creator callback rather | 117 // Starts the connection process, using a specified creator callback rather |
| 113 // than the default. This is exposed for testing. | 118 // than the default. This is exposed for testing. |
| 114 void SendAddChannelRequestForTesting( | 119 void SendAddChannelRequestForTesting( |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 ChannelState HandleFrame( | 271 ChannelState HandleFrame( |
| 267 scoped_ptr<WebSocketFrame> frame) WARN_UNUSED_RESULT; | 272 scoped_ptr<WebSocketFrame> frame) WARN_UNUSED_RESULT; |
| 268 | 273 |
| 269 // Handles a single frame depending on the current state. It's used by the | 274 // Handles a single frame depending on the current state. It's used by the |
| 270 // HandleFrame() method. | 275 // HandleFrame() method. |
| 271 ChannelState HandleFrameByState(const WebSocketFrameHeader::OpCode opcode, | 276 ChannelState HandleFrameByState(const WebSocketFrameHeader::OpCode opcode, |
| 272 bool final, | 277 bool final, |
| 273 const scoped_refptr<IOBuffer>& data_buffer, | 278 const scoped_refptr<IOBuffer>& data_buffer, |
| 274 uint64_t size) WARN_UNUSED_RESULT; | 279 uint64_t size) WARN_UNUSED_RESULT; |
| 275 | 280 |
| 276 // Forward a received data frame to the renderer, if connected. If | 281 // Forwards a received data frame to the renderer, if connected. If |
| 277 // |expecting_continuation| is not equal to |expecting_to_read_continuation_|, | 282 // |expecting_continuation| is not equal to |expecting_to_read_continuation_|, |
| 278 // will fail the channel. Also checks the UTF-8 validity of text frames. | 283 // will fail the channel. Also checks the UTF-8 validity of text frames. |
| 279 ChannelState HandleDataFrame(WebSocketFrameHeader::OpCode opcode, | 284 ChannelState HandleDataFrame(WebSocketFrameHeader::OpCode opcode, |
| 280 bool final, | 285 bool final, |
| 281 const scoped_refptr<IOBuffer>& data_buffer, | 286 const scoped_refptr<IOBuffer>& data_buffer, |
| 282 uint64_t size) WARN_UNUSED_RESULT; | 287 uint64_t size) WARN_UNUSED_RESULT; |
| 283 | 288 |
| 289 // Handles an incoming close frame with |code| and |reason|. |
| 290 ChannelState HandleCloseFrame(uint16_t code, |
| 291 const std::string& reason) WARN_UNUSED_RESULT; |
| 292 |
| 293 // Responds to a closing handshake initiated by the server. |
| 294 ChannelState RespondToClosingHandshake() WARN_UNUSED_RESULT; |
| 295 |
| 284 // Low-level method to send a single frame. Used for both data and control | 296 // Low-level method to send a single frame. Used for both data and control |
| 285 // frames. Either sends the frame immediately or buffers it to be scheduled | 297 // frames. Either sends the frame immediately or buffers it to be scheduled |
| 286 // when the current write finishes. |fin| and |op_code| are defined as for | 298 // when the current write finishes. |fin| and |op_code| are defined as for |
| 287 // SendFrame() above, except that |op_code| may also be a control frame | 299 // SendFrame() above, except that |op_code| may also be a control frame |
| 288 // opcode. | 300 // opcode. |
| 289 ChannelState SendFrameFromIOBuffer(bool fin, | 301 ChannelState SendFrameFromIOBuffer(bool fin, |
| 290 WebSocketFrameHeader::OpCode op_code, | 302 WebSocketFrameHeader::OpCode op_code, |
| 291 const scoped_refptr<IOBuffer>& buffer, | 303 const scoped_refptr<IOBuffer>& buffer, |
| 292 uint64_t size) WARN_UNUSED_RESULT; | 304 uint64_t size) WARN_UNUSED_RESULT; |
| 293 | 305 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 // For UMA. The time when OnConnectSuccess() method was called and |stream_| | 436 // For UMA. The time when OnConnectSuccess() method was called and |stream_| |
| 425 // was set. | 437 // was set. |
| 426 base::TimeTicks established_on_; | 438 base::TimeTicks established_on_; |
| 427 | 439 |
| 428 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel); | 440 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel); |
| 429 }; | 441 }; |
| 430 | 442 |
| 431 } // namespace net | 443 } // namespace net |
| 432 | 444 |
| 433 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ | 445 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ |
| OLD | NEW |