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

Side by Side Diff: extensions/browser/api/socket/tls_socket.cc

Issue 494573002: A change for the setPause() api in chrome.sockets.tcp: Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cosmetics and commentary. Created 5 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "extensions/browser/api/socket/tls_socket.h" 5 #include "extensions/browser/api/socket/tls_socket.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "extensions/browser/api/api_resource.h" 9 #include "extensions/browser/api/api_resource.h"
10 #include "net/base/address_list.h" 10 #include "net/base/address_list.h"
11 #include "net/base/ip_endpoint.h" 11 #include "net/base/ip_endpoint.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/base/rand_callback.h" 13 #include "net/base/rand_callback.h"
14 #include "net/socket/client_socket_factory.h" 14 #include "net/socket/client_socket_factory.h"
15 #include "net/socket/client_socket_handle.h" 15 #include "net/socket/client_socket_handle.h"
16 #include "net/socket/ssl_client_socket.h" 16 #include "net/socket/ssl_client_socket.h"
17 #include "net/socket/tcp_client_socket.h" 17 #include "net/socket/tcp_client_socket.h"
18 #include "url/url_canon.h" 18 #include "url/url_canon.h"
19 19
20 using extensions::BufferingStreamSocket;
21
20 namespace { 22 namespace {
21 23
22 // Returns the SSL protocol version (as a uint16) represented by a string. 24 // Returns the SSL protocol version (as a uint16) represented by a string.
23 // Returns 0 if the string is invalid. 25 // Returns 0 if the string is invalid.
24 uint16 SSLProtocolVersionFromString(const std::string& version_str) { 26 uint16 SSLProtocolVersionFromString(const std::string& version_str) {
25 uint16 version = 0; // Invalid. 27 uint16 version = 0; // Invalid.
26 if (version_str == "tls1") { 28 if (version_str == "tls1") {
27 version = net::SSL_PROTOCOL_VERSION_TLS1; 29 version = net::SSL_PROTOCOL_VERSION_TLS1;
28 } else if (version_str == "tls1.1") { 30 } else if (version_str == "tls1.1") {
29 version = net::SSL_PROTOCOL_VERSION_TLS1_1; 31 version = net::SSL_PROTOCOL_VERSION_TLS1_1;
30 } else if (version_str == "tls1.2") { 32 } else if (version_str == "tls1.2") {
31 version = net::SSL_PROTOCOL_VERSION_TLS1_2; 33 version = net::SSL_PROTOCOL_VERSION_TLS1_2;
32 } 34 }
33 return version; 35 return version;
34 } 36 }
35 37
36 void TlsConnectDone(scoped_ptr<net::SSLClientSocket> ssl_socket, 38 void TlsConnectDone(scoped_ptr<net::SSLClientSocket> ssl_socket,
37 const std::string& extension_id, 39 const std::string& extension_id,
38 const extensions::TLSSocket::SecureCallback& callback, 40 const extensions::TLSSocket::SecureCallback& callback,
39 int result) { 41 int result) {
40 DVLOG(1) << "Got back result " << result << " " << net::ErrorToString(result); 42 DVLOG(1) << "Got back result " << result << " " << net::ErrorToString(result);
41 43
42 // No matter how the TLS connection attempt went, the underlying socket's 44 // No matter how the TLS connection attempt went, the underlying socket's
43 // no longer bound to the original TCPSocket. It belongs to |ssl_socket|, 45 // no longer bound to the original TCPSocket. It belongs to |ssl_socket|,
44 // which is promoted here to a new API-accessible socket (via a TLSSocket 46 // which is promoted here to a new API-accessible socket (via a TLSSocket
45 // wrapper), or deleted. 47 // wrapper), or deleted.
46 if (result != net::OK) { 48 if (result != net::OK) {
47 callback.Run(scoped_ptr<extensions::TLSSocket>(), result); 49 callback.Run(scoped_ptr<extensions::TLSSocket>(), result);
48 return; 50 return;
49 }; 51 }
50 52
53 // Wrap the StreamSocket in a BufferingTCPSocket, to support SetPaused().
Ken Rockot(use gerrit already) 2015/12/15 17:17:49 nit: s/BufferingTCPSocket/BufferingStreamSocket/
54 scoped_ptr<BufferingStreamSocket> buffer_sock(
Ken Rockot(use gerrit already) 2015/12/15 17:17:49 nit: buffer_socket? No real value in abbreviating
55 new BufferingStreamSocket(ssl_socket.Pass()));
51 // Wrap the StreamSocket in a TLSSocket, which matches the extension socket 56 // Wrap the StreamSocket in a TLSSocket, which matches the extension socket
52 // API. Set the handle of the socket to the new value, so that it can be 57 // API. Set the handle of the socket to the new value, so that it can be
53 // used for read/write/close/etc. 58 // used for read/write/close/etc.
54 scoped_ptr<extensions::TLSSocket> wrapper( 59 scoped_ptr<extensions::TLSSocket> wrapper(
55 new extensions::TLSSocket(ssl_socket.Pass(), extension_id)); 60 new extensions::TLSSocket(buffer_sock.Pass(), extension_id));
56 61
57 // Caller will end up deleting the prior TCPSocket, once it calls 62 // Caller will end up deleting the prior TCPSocket, once it calls
58 // SetSocket(..,wrapper). 63 // SetSocket(..,wrapper).
59 callback.Run(wrapper.Pass(), result); 64 callback.Run(wrapper.Pass(), result);
60 } 65 }
61 66
62 } // namespace 67 } // namespace
63 68
64 namespace extensions { 69 namespace extensions {
65 70
66 const char kTLSSocketTypeInvalidError[] = 71 const char kTLSSocketTypeInvalidError[] =
67 "Cannot listen on a socket that is already connected."; 72 "Cannot listen on a socket that is already connected.";
68 73
69 TLSSocket::TLSSocket(scoped_ptr<net::StreamSocket> tls_socket, 74 TLSSocket::TLSSocket(scoped_ptr<BufferingStreamSocket> tls_socket,
70 const std::string& owner_extension_id) 75 const std::string& owner_extension_id)
71 : ResumableTCPSocket(owner_extension_id), tls_socket_(tls_socket.Pass()) { 76 : ResumableTCPSocket(owner_extension_id), tls_socket_(tls_socket.Pass()) {}
72 }
73 77
74 TLSSocket::~TLSSocket() { 78 TLSSocket::~TLSSocket() {
75 Disconnect(); 79 Disconnect();
76 } 80 }
77 81
78 void TLSSocket::Connect(const net::AddressList& address, 82 void TLSSocket::Connect(const net::AddressList& address,
79 const CompletionCallback& callback) { 83 const CompletionCallback& callback) {
80 callback.Run(net::ERR_CONNECTION_FAILED); 84 callback.Run(net::ERR_CONNECTION_FAILED);
81 } 85 }
82 86
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 227 }
224 228
225 net::HostPortPair host_and_port(canon_host, dest_host_port_pair.port()); 229 net::HostPortPair host_and_port(canon_host, dest_host_port_pair.port());
226 230
227 scoped_ptr<net::ClientSocketHandle> socket_handle( 231 scoped_ptr<net::ClientSocketHandle> socket_handle(
228 new net::ClientSocketHandle()); 232 new net::ClientSocketHandle());
229 233
230 // Set the socket handle to the socket's client stream (that should be the 234 // Set the socket handle to the socket's client stream (that should be the
231 // only one active here). Then have the old socket release ownership on 235 // only one active here). Then have the old socket release ownership on
232 // that client stream. 236 // that client stream.
237 tcp_socket->ClientStream()->DisableBuffering();
233 socket_handle->SetSocket( 238 socket_handle->SetSocket(
234 scoped_ptr<net::StreamSocket>(tcp_socket->ClientStream())); 239 scoped_ptr<net::StreamSocket>(tcp_socket->ClientStream()));
235 tcp_socket->Release(); 240 tcp_socket->Release();
236 241
237 DCHECK(transport_security_state); 242 DCHECK(transport_security_state);
238 net::SSLClientSocketContext context; 243 net::SSLClientSocketContext context;
239 context.cert_verifier = cert_verifier; 244 context.cert_verifier = cert_verifier;
240 context.transport_security_state = transport_security_state; 245 context.transport_security_state = transport_security_state;
241 246
242 // Fill in the SSL socket params. 247 // Fill in the SSL socket params.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // fail with an error above. 300 // fail with an error above.
296 if (status != net::OK) { 301 if (status != net::OK) {
297 DVLOG(1) << "Status is not OK or IO-pending: " 302 DVLOG(1) << "Status is not OK or IO-pending: "
298 << net::ErrorToString(status); 303 << net::ErrorToString(status);
299 } 304 }
300 connect_cb.Run(status); 305 connect_cb.Run(status);
301 } 306 }
302 } 307 }
303 308
304 } // namespace extensions 309 } // namespace extensions
305
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698