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 24 matching lines...) Expand all Loading... | |
35 // interface to the content layer. Some WebSocket concepts are used here without | 35 // interface to the content layer. Some WebSocket concepts are used here without |
36 // definition; please see the RFC at http://tools.ietf.org/html/rfc6455 for | 36 // definition; please see the RFC at http://tools.ietf.org/html/rfc6455 for |
37 // clarification. | 37 // clarification. |
38 class NET_EXPORT WebSocketChannel { | 38 class NET_EXPORT WebSocketChannel { |
39 public: | 39 public: |
40 // The type of a WebSocketStream creator callback. Must match the signature of | 40 // The type of a WebSocketStream creator callback. Must match the signature of |
41 // WebSocketStream::CreateAndConnectStream(). | 41 // WebSocketStream::CreateAndConnectStream(). |
42 typedef base::Callback<scoped_ptr<WebSocketStreamRequest>( | 42 typedef base::Callback<scoped_ptr<WebSocketStreamRequest>( |
43 const GURL&, | 43 const GURL&, |
44 const std::vector<std::string>&, | 44 const std::vector<std::string>&, |
45 const GURL&, | 45 const std::string&, |
abarth-chromium
2014/02/24 06:17:06
It's too bad we've lost the type information at th
yhirano
2014/03/03 15:41:54
Done.
| |
46 URLRequestContext*, | 46 URLRequestContext*, |
47 const BoundNetLog&, | 47 const BoundNetLog&, |
48 scoped_ptr<WebSocketStream::ConnectDelegate>)> WebSocketStreamCreator; | 48 scoped_ptr<WebSocketStream::ConnectDelegate>)> WebSocketStreamCreator; |
49 | 49 |
50 // Creates a new WebSocketChannel in an idle state. | 50 // Creates a new WebSocketChannel in an idle state. |
51 // SendAddChannelRequest() must be called immediately afterwards to start the | 51 // SendAddChannelRequest() must be called immediately afterwards to start the |
52 // connection process. | 52 // connection process. |
53 WebSocketChannel(scoped_ptr<WebSocketEventInterface> event_interface, | 53 WebSocketChannel(scoped_ptr<WebSocketEventInterface> event_interface, |
54 URLRequestContext* url_request_context); | 54 URLRequestContext* url_request_context); |
55 virtual ~WebSocketChannel(); | 55 virtual ~WebSocketChannel(); |
56 | 56 |
57 // Starts the connection process. | 57 // Starts the connection process. |
58 void SendAddChannelRequest( | 58 void SendAddChannelRequest( |
59 const GURL& socket_url, | 59 const GURL& socket_url, |
60 const std::vector<std::string>& requested_protocols, | 60 const std::vector<std::string>& requested_protocols, |
61 const GURL& origin); | 61 const std::string& origin); |
62 | 62 |
63 // Sends a data frame to the remote side. The frame should usually be no | 63 // Sends a data frame to the remote side. The frame should usually be no |
64 // larger than 32KB to prevent the time required to copy the buffers from from | 64 // larger than 32KB to prevent the time required to copy the buffers from from |
65 // unduly delaying other tasks that need to run on the IO thread. This method | 65 // unduly delaying other tasks that need to run on the IO thread. This method |
66 // has a hard limit of 2GB. It is the responsibility of the caller to ensure | 66 // has a hard limit of 2GB. It is the responsibility of the caller to ensure |
67 // that they have sufficient send quota to send this data, otherwise the | 67 // that they have sufficient send quota to send this data, otherwise the |
68 // connection will be closed without sending. |fin| indicates the last frame | 68 // connection will be closed without sending. |fin| indicates the last frame |
69 // in a message, equivalent to "FIN" as specified in section 5.2 of | 69 // in a message, equivalent to "FIN" as specified in section 5.2 of |
70 // RFC6455. |data| is the "Payload Data". If |op_code| is kOpCodeText, or it | 70 // RFC6455. |data| is the "Payload Data". If |op_code| is kOpCodeText, or it |
71 // is kOpCodeContinuation and the type the message is Text, then |data| must | 71 // is kOpCodeContinuation and the type the message is Text, then |data| must |
(...skipping 17 matching lines...) Expand all Loading... | |
89 // This does *not* trigger the event OnClosingHandshake(). The caller should | 89 // This does *not* trigger the event OnClosingHandshake(). The caller should |
90 // assume that the closing handshake has started and perform the equivalent | 90 // assume that the closing handshake has started and perform the equivalent |
91 // processing to OnClosingHandshake() if necessary. | 91 // processing to OnClosingHandshake() if necessary. |
92 void StartClosingHandshake(uint16 code, const std::string& reason); | 92 void StartClosingHandshake(uint16 code, const std::string& reason); |
93 | 93 |
94 // Starts the connection process, using a specified creator callback rather | 94 // Starts the connection process, using a specified creator callback rather |
95 // than the default. This is exposed for testing. | 95 // than the default. This is exposed for testing. |
96 void SendAddChannelRequestForTesting( | 96 void SendAddChannelRequestForTesting( |
97 const GURL& socket_url, | 97 const GURL& socket_url, |
98 const std::vector<std::string>& requested_protocols, | 98 const std::vector<std::string>& requested_protocols, |
99 const GURL& origin, | 99 const std::string& origin, |
100 const WebSocketStreamCreator& creator); | 100 const WebSocketStreamCreator& creator); |
101 | 101 |
102 // The default timout for the closing handshake is a sensible value (see | 102 // The default timout for the closing handshake is a sensible value (see |
103 // kClosingHandshakeTimeoutSeconds in websocket_channel.cc). However, we can | 103 // kClosingHandshakeTimeoutSeconds in websocket_channel.cc). However, we can |
104 // set it to a very small value for testing purposes. | 104 // set it to a very small value for testing purposes. |
105 void SetClosingHandshakeTimeoutForTesting(base::TimeDelta delay); | 105 void SetClosingHandshakeTimeoutForTesting(base::TimeDelta delay); |
106 | 106 |
107 // Called when the stream starts the WebSocket Opening Handshake. | 107 // Called when the stream starts the WebSocket Opening Handshake. |
108 // This method is public for testing. | 108 // This method is public for testing. |
109 void OnStartOpeningHandshake( | 109 void OnStartOpeningHandshake( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 // WebSocketStream::ConnectDelegate directly to avoid cluttering the public | 144 // WebSocketStream::ConnectDelegate directly to avoid cluttering the public |
145 // interface with the implementation of those methods, and because the | 145 // interface with the implementation of those methods, and because the |
146 // lifetime of a WebSocketChannel is longer than the lifetime of the | 146 // lifetime of a WebSocketChannel is longer than the lifetime of the |
147 // connection process. | 147 // connection process. |
148 class ConnectDelegate; | 148 class ConnectDelegate; |
149 | 149 |
150 // Starts the connection process, using the supplied creator callback. | 150 // Starts the connection process, using the supplied creator callback. |
151 void SendAddChannelRequestWithSuppliedCreator( | 151 void SendAddChannelRequestWithSuppliedCreator( |
152 const GURL& socket_url, | 152 const GURL& socket_url, |
153 const std::vector<std::string>& requested_protocols, | 153 const std::vector<std::string>& requested_protocols, |
154 const GURL& origin, | 154 const std::string& origin, |
155 const WebSocketStreamCreator& creator); | 155 const WebSocketStreamCreator& creator); |
156 | 156 |
157 // Success callback from WebSocketStream::CreateAndConnectStream(). Reports | 157 // Success callback from WebSocketStream::CreateAndConnectStream(). Reports |
158 // success to the event interface. May delete |this|. | 158 // success to the event interface. May delete |this|. |
159 void OnConnectSuccess(scoped_ptr<WebSocketStream> stream); | 159 void OnConnectSuccess(scoped_ptr<WebSocketStream> stream); |
160 | 160 |
161 // Failure callback from WebSocketStream::CreateAndConnectStream(). Reports | 161 // Failure callback from WebSocketStream::CreateAndConnectStream(). Reports |
162 // failure to the event interface. May delete |this|. | 162 // failure to the event interface. May delete |this|. |
163 void OnConnectFailure(const std::string& message); | 163 void OnConnectFailure(const std::string& message); |
164 | 164 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 | 335 |
336 // True if we are in the middle of receiving a message. | 336 // True if we are in the middle of receiving a message. |
337 bool expecting_to_handle_continuation_; | 337 bool expecting_to_handle_continuation_; |
338 | 338 |
339 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel); | 339 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel); |
340 }; | 340 }; |
341 | 341 |
342 } // namespace net | 342 } // namespace net |
343 | 343 |
344 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ | 344 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ |
OLD | NEW |