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

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

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 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 <utility> 7 #include <utility>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 18 matching lines...) Expand all
29 if (version_str == "tls1") { 29 if (version_str == "tls1") {
30 version = net::SSL_PROTOCOL_VERSION_TLS1; 30 version = net::SSL_PROTOCOL_VERSION_TLS1;
31 } else if (version_str == "tls1.1") { 31 } else if (version_str == "tls1.1") {
32 version = net::SSL_PROTOCOL_VERSION_TLS1_1; 32 version = net::SSL_PROTOCOL_VERSION_TLS1_1;
33 } else if (version_str == "tls1.2") { 33 } else if (version_str == "tls1.2") {
34 version = net::SSL_PROTOCOL_VERSION_TLS1_2; 34 version = net::SSL_PROTOCOL_VERSION_TLS1_2;
35 } 35 }
36 return version; 36 return version;
37 } 37 }
38 38
39 void TlsConnectDone(scoped_ptr<net::SSLClientSocket> ssl_socket, 39 void TlsConnectDone(std::unique_ptr<net::SSLClientSocket> ssl_socket,
40 const std::string& extension_id, 40 const std::string& extension_id,
41 const extensions::TLSSocket::SecureCallback& callback, 41 const extensions::TLSSocket::SecureCallback& callback,
42 int result) { 42 int result) {
43 DVLOG(1) << "Got back result " << result << " " << net::ErrorToString(result); 43 DVLOG(1) << "Got back result " << result << " " << net::ErrorToString(result);
44 44
45 // No matter how the TLS connection attempt went, the underlying socket's 45 // No matter how the TLS connection attempt went, the underlying socket's
46 // no longer bound to the original TCPSocket. It belongs to |ssl_socket|, 46 // no longer bound to the original TCPSocket. It belongs to |ssl_socket|,
47 // which is promoted here to a new API-accessible socket (via a TLSSocket 47 // which is promoted here to a new API-accessible socket (via a TLSSocket
48 // wrapper), or deleted. 48 // wrapper), or deleted.
49 if (result != net::OK) { 49 if (result != net::OK) {
50 callback.Run(scoped_ptr<extensions::TLSSocket>(), result); 50 callback.Run(std::unique_ptr<extensions::TLSSocket>(), result);
51 return; 51 return;
52 }; 52 };
53 53
54 // Wrap the StreamSocket in a TLSSocket, which matches the extension socket 54 // Wrap the StreamSocket in a TLSSocket, which matches the extension socket
55 // API. Set the handle of the socket to the new value, so that it can be 55 // API. Set the handle of the socket to the new value, so that it can be
56 // used for read/write/close/etc. 56 // used for read/write/close/etc.
57 scoped_ptr<extensions::TLSSocket> wrapper( 57 std::unique_ptr<extensions::TLSSocket> wrapper(
58 new extensions::TLSSocket(std::move(ssl_socket), extension_id)); 58 new extensions::TLSSocket(std::move(ssl_socket), extension_id));
59 59
60 // Caller will end up deleting the prior TCPSocket, once it calls 60 // Caller will end up deleting the prior TCPSocket, once it calls
61 // SetSocket(..,wrapper). 61 // SetSocket(..,wrapper).
62 callback.Run(std::move(wrapper), result); 62 callback.Run(std::move(wrapper), result);
63 } 63 }
64 64
65 } // namespace 65 } // namespace
66 66
67 namespace extensions { 67 namespace extensions {
68 68
69 const char kTLSSocketTypeInvalidError[] = 69 const char kTLSSocketTypeInvalidError[] =
70 "Cannot listen on a socket that is already connected."; 70 "Cannot listen on a socket that is already connected.";
71 71
72 TLSSocket::TLSSocket(scoped_ptr<net::StreamSocket> tls_socket, 72 TLSSocket::TLSSocket(std::unique_ptr<net::StreamSocket> tls_socket,
73 const std::string& owner_extension_id) 73 const std::string& owner_extension_id)
74 : ResumableTCPSocket(owner_extension_id), 74 : ResumableTCPSocket(owner_extension_id),
75 tls_socket_(std::move(tls_socket)) {} 75 tls_socket_(std::move(tls_socket)) {}
76 76
77 TLSSocket::~TLSSocket() { 77 TLSSocket::~TLSSocket() {
78 Disconnect(); 78 Disconnect();
79 } 79 }
80 80
81 void TLSSocket::Connect(const net::AddressList& address, 81 void TLSSocket::Connect(const net::AddressList& address,
82 const CompletionCallback& callback) { 82 const CompletionCallback& callback) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 void TLSSocket::UpgradeSocketToTLS( 179 void TLSSocket::UpgradeSocketToTLS(
180 Socket* socket, 180 Socket* socket,
181 scoped_refptr<net::SSLConfigService> ssl_config_service, 181 scoped_refptr<net::SSLConfigService> ssl_config_service,
182 net::CertVerifier* cert_verifier, 182 net::CertVerifier* cert_verifier,
183 net::TransportSecurityState* transport_security_state, 183 net::TransportSecurityState* transport_security_state,
184 const std::string& extension_id, 184 const std::string& extension_id,
185 api::socket::SecureOptions* options, 185 api::socket::SecureOptions* options,
186 const TLSSocket::SecureCallback& callback) { 186 const TLSSocket::SecureCallback& callback) {
187 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 187 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
188 TCPSocket* tcp_socket = static_cast<TCPSocket*>(socket); 188 TCPSocket* tcp_socket = static_cast<TCPSocket*>(socket);
189 scoped_ptr<net::SSLClientSocket> null_sock; 189 std::unique_ptr<net::SSLClientSocket> null_sock;
190 190
191 if (!tcp_socket || tcp_socket->GetSocketType() != Socket::TYPE_TCP || 191 if (!tcp_socket || tcp_socket->GetSocketType() != Socket::TYPE_TCP ||
192 !tcp_socket->ClientStream() || !tcp_socket->IsConnected() || 192 !tcp_socket->ClientStream() || !tcp_socket->IsConnected() ||
193 tcp_socket->HasPendingRead()) { 193 tcp_socket->HasPendingRead()) {
194 DVLOG(1) << "Failing before trying. socket is " << tcp_socket; 194 DVLOG(1) << "Failing before trying. socket is " << tcp_socket;
195 if (tcp_socket) { 195 if (tcp_socket) {
196 DVLOG(1) << "type: " << tcp_socket->GetSocketType() 196 DVLOG(1) << "type: " << tcp_socket->GetSocketType()
197 << ", ClientStream is " << tcp_socket->ClientStream() 197 << ", ClientStream is " << tcp_socket->ClientStream()
198 << ", IsConnected: " << tcp_socket->IsConnected() 198 << ", IsConnected: " << tcp_socket->IsConnected()
199 << ", HasPendingRead: " << tcp_socket->HasPendingRead(); 199 << ", HasPendingRead: " << tcp_socket->HasPendingRead();
(...skipping 20 matching lines...) Expand all
220 // host, using this hostname. 220 // host, using this hostname.
221 if (host_info.family == url::CanonHostInfo::BROKEN) { 221 if (host_info.family == url::CanonHostInfo::BROKEN) {
222 DVLOG(1) << "Could not canonicalize hostname"; 222 DVLOG(1) << "Could not canonicalize hostname";
223 TlsConnectDone(std::move(null_sock), extension_id, callback, 223 TlsConnectDone(std::move(null_sock), extension_id, callback,
224 net::ERR_INVALID_ARGUMENT); 224 net::ERR_INVALID_ARGUMENT);
225 return; 225 return;
226 } 226 }
227 227
228 net::HostPortPair host_and_port(canon_host, dest_host_port_pair.port()); 228 net::HostPortPair host_and_port(canon_host, dest_host_port_pair.port());
229 229
230 scoped_ptr<net::ClientSocketHandle> socket_handle( 230 std::unique_ptr<net::ClientSocketHandle> socket_handle(
231 new net::ClientSocketHandle()); 231 new net::ClientSocketHandle());
232 232
233 // Set the socket handle to the socket's client stream (that should be the 233 // Set the socket handle to the socket's client stream (that should be the
234 // only one active here). Then have the old socket release ownership on 234 // only one active here). Then have the old socket release ownership on
235 // that client stream. 235 // that client stream.
236 socket_handle->SetSocket( 236 socket_handle->SetSocket(
237 scoped_ptr<net::StreamSocket>(tcp_socket->ClientStream())); 237 std::unique_ptr<net::StreamSocket>(tcp_socket->ClientStream()));
238 tcp_socket->Release(); 238 tcp_socket->Release();
239 239
240 DCHECK(transport_security_state); 240 DCHECK(transport_security_state);
241 net::SSLClientSocketContext context; 241 net::SSLClientSocketContext context;
242 context.cert_verifier = cert_verifier; 242 context.cert_verifier = cert_verifier;
243 context.transport_security_state = transport_security_state; 243 context.transport_security_state = transport_security_state;
244 244
245 // Fill in the SSL socket params. 245 // Fill in the SSL socket params.
246 net::SSLConfig ssl_config; 246 net::SSLConfig ssl_config;
247 ssl_config_service->GetSSLConfig(&ssl_config); 247 ssl_config_service->GetSSLConfig(&ssl_config);
(...skipping 11 matching lines...) Expand all
259 } 259 }
260 if (version_max) { 260 if (version_max) {
261 ssl_config.version_max = version_max; 261 ssl_config.version_max = version_max;
262 } 262 }
263 } 263 }
264 264
265 net::ClientSocketFactory* socket_factory = 265 net::ClientSocketFactory* socket_factory =
266 net::ClientSocketFactory::GetDefaultFactory(); 266 net::ClientSocketFactory::GetDefaultFactory();
267 267
268 // Create the socket. 268 // Create the socket.
269 scoped_ptr<net::SSLClientSocket> ssl_socket( 269 std::unique_ptr<net::SSLClientSocket> ssl_socket(
270 socket_factory->CreateSSLClientSocket( 270 socket_factory->CreateSSLClientSocket(
271 std::move(socket_handle), host_and_port, ssl_config, context)); 271 std::move(socket_handle), host_and_port, ssl_config, context));
272 272
273 DVLOG(1) << "Attempting to secure a connection to " << tcp_socket->hostname() 273 DVLOG(1) << "Attempting to secure a connection to " << tcp_socket->hostname()
274 << ":" << dest_host_port_pair.port(); 274 << ":" << dest_host_port_pair.port();
275 275
276 // We need the contents of |ssl_socket| in order to invoke its Connect() 276 // We need the contents of |ssl_socket| in order to invoke its Connect()
277 // method. It belongs to |ssl_socket|, and we own that until our internal 277 // method. It belongs to |ssl_socket|, and we own that until our internal
278 // callback (|connect_cb|, below) is invoked. 278 // callback (|connect_cb|, below) is invoked.
279 net::SSLClientSocket* saved_ssl_socket = ssl_socket.get(); 279 net::SSLClientSocket* saved_ssl_socket = ssl_socket.get();
(...skipping 19 matching lines...) Expand all
299 if (status != net::OK) { 299 if (status != net::OK) {
300 DVLOG(1) << "Status is not OK or IO-pending: " 300 DVLOG(1) << "Status is not OK or IO-pending: "
301 << net::ErrorToString(status); 301 << net::ErrorToString(status);
302 } 302 }
303 connect_cb.Run(status); 303 connect_cb.Run(status);
304 } 304 }
305 } 305 }
306 306
307 } // namespace extensions 307 } // namespace extensions
308 308
OLDNEW
« no previous file with comments | « extensions/browser/api/socket/tls_socket.h ('k') | extensions/browser/api/sockets_tcp/sockets_tcp_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698