Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: net/websockets/websocket_channel.h

Issue 1820233002: [WebSocket] Incoming close frame should not overtake data frames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // for |data| to be split on character boundaries. Calling SendFrame may 82 // for |data| to be split on character boundaries. Calling SendFrame may
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. Calling this function may
tyoshino (SeeGerritForStatus) 2016/03/29 11:18:56 break the line at the end of the sentence and have
yhirano 2016/03/29 12:26:41 Done.
93 void SendFlowControl(int64_t quota); 93 // result in synchronous calls to |event_interface_| which may result in this
94 // object being deleted. In that case, the return value will be
95 // CHANNEL_DELETED.
96 ChannelState SendFlowControl(int64_t quota) WARN_UNUSED_RESULT;
94 97
95 // Starts the closing handshake for a client-initiated shutdown of the 98 // Starts the closing handshake for a client-initiated shutdown of the
96 // connection. There is no API to close the connection without a closing 99 // connection. There is no API to close the connection without a closing
97 // handshake, but destroying the WebSocketChannel object while connected will 100 // handshake, but destroying the WebSocketChannel object while connected will
98 // effectively do that. |code| must be in the range 1000-4999. |reason| should 101 // effectively do that. |code| must be in the range 1000-4999. |reason| should
99 // be a valid UTF-8 string or empty. 102 // be a valid UTF-8 string or empty.
100 // 103 //
101 // This does *not* trigger the event OnClosingHandshake(). The caller should 104 // Calling this function may result in synchronous calls to |event_interface_|
102 // assume that the closing handshake has started and perform the equivalent 105 // which may result in this object being deleted. In that case, the return
103 // processing to OnClosingHandshake() if necessary. 106 // value will be CHANNEL_DELETED.
104 void StartClosingHandshake(uint16_t code, const std::string& reason); 107 ChannelState StartClosingHandshake(uint16_t code, const std::string& reason)
108 WARN_UNUSED_RESULT;
105 109
106 // Returns the current send quota. This value is unsafe to use outside of the 110 // 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 111 // 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, 112 // valid for the execution of the current Task or until SendFrame() is called,
109 // whichever happens sooner. 113 // whichever happens sooner.
110 int current_send_quota() const { return current_send_quota_; } 114 int current_send_quota() const { return current_send_quota_; }
111 115
112 // Starts the connection process, using a specified creator callback rather 116 // Starts the connection process, using a specified creator callback rather
113 // than the default. This is exposed for testing. 117 // than the default. This is exposed for testing.
114 void SendAddChannelRequestForTesting( 118 void SendAddChannelRequestForTesting(
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 ChannelState HandleFrame( 270 ChannelState HandleFrame(
267 scoped_ptr<WebSocketFrame> frame) WARN_UNUSED_RESULT; 271 scoped_ptr<WebSocketFrame> frame) WARN_UNUSED_RESULT;
268 272
269 // Handles a single frame depending on the current state. It's used by the 273 // Handles a single frame depending on the current state. It's used by the
270 // HandleFrame() method. 274 // HandleFrame() method.
271 ChannelState HandleFrameByState(const WebSocketFrameHeader::OpCode opcode, 275 ChannelState HandleFrameByState(const WebSocketFrameHeader::OpCode opcode,
272 bool final, 276 bool final,
273 const scoped_refptr<IOBuffer>& data_buffer, 277 const scoped_refptr<IOBuffer>& data_buffer,
274 uint64_t size) WARN_UNUSED_RESULT; 278 uint64_t size) WARN_UNUSED_RESULT;
275 279
276 // Forward a received data frame to the renderer, if connected. If 280 // Forwards a received data frame to the renderer, if connected. If
277 // |expecting_continuation| is not equal to |expecting_to_read_continuation_|, 281 // |expecting_continuation| is not equal to |expecting_to_read_continuation_|,
278 // will fail the channel. Also checks the UTF-8 validity of text frames. 282 // will fail the channel. Also checks the UTF-8 validity of text frames.
279 ChannelState HandleDataFrame(WebSocketFrameHeader::OpCode opcode, 283 ChannelState HandleDataFrame(WebSocketFrameHeader::OpCode opcode,
280 bool final, 284 bool final,
281 const scoped_refptr<IOBuffer>& data_buffer, 285 const scoped_refptr<IOBuffer>& data_buffer,
282 uint64_t size) WARN_UNUSED_RESULT; 286 uint64_t size) WARN_UNUSED_RESULT;
283 287
288 // Handles an incoming close frame with |code| and |reason|.
289 ChannelState HandleCloseFrame(uint16_t code,
290 const std::string& reason) WARN_UNUSED_RESULT;
291
292 // Responds to a closing handshake initiated by the server.
293 ChannelState RespondToClosingHandshake() WARN_UNUSED_RESULT;
294
284 // Low-level method to send a single frame. Used for both data and control 295 // 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 296 // 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 297 // 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 298 // SendFrame() above, except that |op_code| may also be a control frame
288 // opcode. 299 // opcode.
289 ChannelState SendFrameFromIOBuffer(bool fin, 300 ChannelState SendFrameFromIOBuffer(bool fin,
290 WebSocketFrameHeader::OpCode op_code, 301 WebSocketFrameHeader::OpCode op_code,
291 const scoped_refptr<IOBuffer>& buffer, 302 const scoped_refptr<IOBuffer>& buffer,
292 uint64_t size) WARN_UNUSED_RESULT; 303 uint64_t size) WARN_UNUSED_RESULT;
293 304
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // For UMA. The time when OnConnectSuccess() method was called and |stream_| 435 // For UMA. The time when OnConnectSuccess() method was called and |stream_|
425 // was set. 436 // was set.
426 base::TimeTicks established_on_; 437 base::TimeTicks established_on_;
427 438
428 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel); 439 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel);
429 }; 440 };
430 441
431 } // namespace net 442 } // namespace net
432 443
433 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ 444 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698