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 CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/cancelable_callback.h" | |
13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
17 #include "chrome/common/extensions/api/cast_channel.h" | 18 #include "chrome/common/extensions/api/cast_channel.h" |
18 #include "extensions/browser/api/api_resource.h" | 19 #include "extensions/browser/api/api_resource.h" |
19 #include "extensions/browser/api/api_resource_manager.h" | 20 #include "extensions/browser/api/api_resource_manager.h" |
20 #include "net/base/completion_callback.h" | 21 #include "net/base/completion_callback.h" |
21 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
22 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 virtual ~Delegate() {} | 62 virtual ~Delegate() {} |
62 }; | 63 }; |
63 | 64 |
64 // Creates a new CastSocket that connects to |ip_endpoint| with | 65 // Creates a new CastSocket that connects to |ip_endpoint| with |
65 // |channel_auth|. |owner_extension_id| is the id of the extension that opened | 66 // |channel_auth|. |owner_extension_id| is the id of the extension that opened |
66 // the socket. |channel_auth| must not be CHANNEL_AUTH_NONE. | 67 // the socket. |channel_auth| must not be CHANNEL_AUTH_NONE. |
67 CastSocket(const std::string& owner_extension_id, | 68 CastSocket(const std::string& owner_extension_id, |
68 const net::IPEndPoint& ip_endpoint, | 69 const net::IPEndPoint& ip_endpoint, |
69 ChannelAuthType channel_auth, | 70 ChannelAuthType channel_auth, |
70 CastSocket::Delegate* delegate, | 71 CastSocket::Delegate* delegate, |
71 net::NetLog* net_log); | 72 net::NetLog* net_log, |
73 int64 timeout_ms); | |
mark a. foltz
2014/07/15 22:18:15
connect_timeout_ms
Kevin M
2014/07/16 22:59:42
Done.
| |
72 virtual ~CastSocket(); | 74 virtual ~CastSocket(); |
73 | 75 |
74 // The IP endpoint for the destination of the channel. | 76 // The IP endpoint for the destination of the channel. |
75 const net::IPEndPoint& ip_endpoint() const { return ip_endpoint_; } | 77 const net::IPEndPoint& ip_endpoint() const { return ip_endpoint_; } |
76 | 78 |
77 // The authentication level requested for the channel. | 79 // The authentication level requested for the channel. |
78 ChannelAuthType channel_auth() const { return channel_auth_; } | 80 ChannelAuthType channel_auth() const { return channel_auth_; } |
79 | 81 |
80 // Returns a cast:// or casts:// URL for the channel endpoint. | 82 // Returns a cast:// or casts:// URL for the channel endpoint. |
81 // For backwards compatibility. | 83 // For backwards compatibility. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 scoped_ptr<net::StreamSocket> socket); | 186 scoped_ptr<net::StreamSocket> socket); |
185 // Extracts peer certificate from SSLClientSocket instance when the socket | 187 // Extracts peer certificate from SSLClientSocket instance when the socket |
186 // is in cert error state. | 188 // is in cert error state. |
187 // Returns whether certificate is successfully extracted. | 189 // Returns whether certificate is successfully extracted. |
188 virtual bool ExtractPeerCert(std::string* cert); | 190 virtual bool ExtractPeerCert(std::string* cert); |
189 // Verifies whether the challenge reply received from the peer is valid: | 191 // Verifies whether the challenge reply received from the peer is valid: |
190 // 1. Signature in the reply is valid. | 192 // 1. Signature in the reply is valid. |
191 // 2. Certificate is rooted to a trusted CA. | 193 // 2. Certificate is rooted to a trusted CA. |
192 virtual bool VerifyChallengeReply(); | 194 virtual bool VerifyChallengeReply(); |
193 | 195 |
196 // Invoked by a cancelable closure when connection setup time | |
197 // exceeds the interval specified at |timeout_interval_ms_|. | |
198 void Timeout(); | |
mark a. foltz
2014/07/15 22:18:15
CancelConnect()?
Kevin M
2014/07/16 22:59:42
Done.
| |
199 | |
194 ///////////////////////////////////////////////////////////////////////////// | 200 ///////////////////////////////////////////////////////////////////////////// |
195 // Following methods work together to implement the following flow: | 201 // Following methods work together to implement the following flow: |
196 // 1. Create a new TCP socket and connect to it | 202 // 1. Create a new TCP socket and connect to it |
197 // 2. Create a new SSL socket and try connecting to it | 203 // 2. Create a new SSL socket and try connecting to it |
198 // 3. If connection fails due to invalid cert authority, then extract the | 204 // 3. If connection fails due to invalid cert authority, then extract the |
199 // peer certificate from the error. | 205 // peer certificate from the error. |
200 // 4. Whitelist the peer certificate and try #1 and #2 again. | 206 // 4. Whitelist the peer certificate and try #1 and #2 again. |
201 // 5. If SSL socket is connected successfully, and if protocol is casts:// | 207 // 5. If SSL socket is connected successfully, and if protocol is casts:// |
202 // then issue an auth challenge request. | 208 // then issue an auth challenge request. |
203 // 6. Validate the auth challenge response. | 209 // 6. Validate the auth challenge response. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 // Owned ptr to the underlying TCP socket. | 310 // Owned ptr to the underlying TCP socket. |
305 scoped_ptr<net::TCPClientSocket> tcp_socket_; | 311 scoped_ptr<net::TCPClientSocket> tcp_socket_; |
306 // Owned ptr to the underlying SSL socket. | 312 // Owned ptr to the underlying SSL socket. |
307 scoped_ptr<net::SSLClientSocket> socket_; | 313 scoped_ptr<net::SSLClientSocket> socket_; |
308 // Certificate of the peer. This field may be empty if the peer | 314 // Certificate of the peer. This field may be empty if the peer |
309 // certificate is not yet fetched. | 315 // certificate is not yet fetched. |
310 std::string peer_cert_; | 316 std::string peer_cert_; |
311 // Reply received from the receiver to a challenge request. | 317 // Reply received from the receiver to a challenge request. |
312 scoped_ptr<CastMessage> challenge_reply_; | 318 scoped_ptr<CastMessage> challenge_reply_; |
313 | 319 |
314 // Callback invoked when the socket is connected. | 320 // Callback invoked when the socket is connected or fails to connect. |
315 net::CompletionCallback connect_callback_; | 321 net::CompletionCallback connect_callback_; |
316 | 322 |
323 // Number of milliseconds to wait before timing out. | |
324 int64 timeout_interval_ms_; | |
mark a. foltz
2014/07/15 22:18:15
connect_timeout_ms_
Kevin M
2014/07/16 22:59:42
Done.
| |
325 // Closure invoked when the connection has timed out. | |
326 base::CancelableClosure timeout_callback_; | |
mark a. foltz
2014/07/15 22:18:15
connect_timeout_callback_
Kevin M
2014/07/16 22:59:41
Done.
| |
327 bool timed_out_; | |
mark a. foltz
2014/07/15 22:18:15
connect_timed_out_
Kevin M
2014/07/16 22:59:42
Done. Removed this variable - code checks the erro
| |
328 | |
317 // Connection flow state machine state. | 329 // Connection flow state machine state. |
318 ConnectionState connect_state_; | 330 ConnectionState connect_state_; |
319 // Write flow state machine state. | 331 // Write flow state machine state. |
320 WriteState write_state_; | 332 WriteState write_state_; |
321 // Read flow state machine state. | 333 // Read flow state machine state. |
322 ReadState read_state_; | 334 ReadState read_state_; |
323 // The last error encountered by the channel. | 335 // The last error encountered by the channel. |
324 ChannelError error_state_; | 336 ChannelError error_state_; |
325 // The current status of the channel. | 337 // The current status of the channel. |
326 ReadyState ready_state_; | 338 ReadyState ready_state_; |
(...skipping 20 matching lines...) Expand all Loading... | |
347 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadMany); | 359 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadMany); |
348 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestWriteErrorLargeMessage); | 360 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestWriteErrorLargeMessage); |
349 DISALLOW_COPY_AND_ASSIGN(CastSocket); | 361 DISALLOW_COPY_AND_ASSIGN(CastSocket); |
350 }; | 362 }; |
351 | 363 |
352 } // namespace cast_channel | 364 } // namespace cast_channel |
353 } // namespace api | 365 } // namespace api |
354 } // namespace extensions | 366 } // namespace extensions |
355 | 367 |
356 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ | 368 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ |
OLD | NEW |