| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/socket/ssl_client_socket_pool.h" | 5 #include "net/socket/ssl_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/base/ssl_cert_request_info.h" | 10 #include "net/base/ssl_cert_request_info.h" |
| 11 #include "net/base/ssl_host_info.h" |
| 11 #include "net/http/http_proxy_client_socket.h" | 12 #include "net/http/http_proxy_client_socket.h" |
| 12 #include "net/http/http_proxy_client_socket_pool.h" | 13 #include "net/http/http_proxy_client_socket_pool.h" |
| 13 #include "net/socket/client_socket_factory.h" | 14 #include "net/socket/client_socket_factory.h" |
| 14 #include "net/socket/client_socket_handle.h" | 15 #include "net/socket/client_socket_handle.h" |
| 15 #include "net/socket/socks_client_socket_pool.h" | 16 #include "net/socket/socks_client_socket_pool.h" |
| 16 #include "net/socket/ssl_client_socket.h" | 17 #include "net/socket/ssl_client_socket.h" |
| 17 #include "net/socket/tcp_client_socket_pool.h" | 18 #include "net/socket/tcp_client_socket_pool.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 SSLConnectJob::SSLConnectJob( | 70 SSLConnectJob::SSLConnectJob( |
| 70 const std::string& group_name, | 71 const std::string& group_name, |
| 71 const scoped_refptr<SSLSocketParams>& params, | 72 const scoped_refptr<SSLSocketParams>& params, |
| 72 const base::TimeDelta& timeout_duration, | 73 const base::TimeDelta& timeout_duration, |
| 73 TCPClientSocketPool* tcp_pool, | 74 TCPClientSocketPool* tcp_pool, |
| 74 SOCKSClientSocketPool* socks_pool, | 75 SOCKSClientSocketPool* socks_pool, |
| 75 HttpProxyClientSocketPool* http_proxy_pool, | 76 HttpProxyClientSocketPool* http_proxy_pool, |
| 76 ClientSocketFactory* client_socket_factory, | 77 ClientSocketFactory* client_socket_factory, |
| 77 HostResolver* host_resolver, | 78 HostResolver* host_resolver, |
| 78 DnsRRResolver* dnsrr_resolver, | 79 DnsRRResolver* dnsrr_resolver, |
| 80 SSLHostInfoFactory* ssl_host_info_factory, |
| 79 Delegate* delegate, | 81 Delegate* delegate, |
| 80 NetLog* net_log) | 82 NetLog* net_log) |
| 81 : ConnectJob(group_name, timeout_duration, delegate, | 83 : ConnectJob(group_name, timeout_duration, delegate, |
| 82 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 84 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 83 params_(params), | 85 params_(params), |
| 84 tcp_pool_(tcp_pool), | 86 tcp_pool_(tcp_pool), |
| 85 socks_pool_(socks_pool), | 87 socks_pool_(socks_pool), |
| 86 http_proxy_pool_(http_proxy_pool), | 88 http_proxy_pool_(http_proxy_pool), |
| 87 client_socket_factory_(client_socket_factory), | 89 client_socket_factory_(client_socket_factory), |
| 88 resolver_(host_resolver), | 90 resolver_(host_resolver), |
| 89 dnsrr_resolver_(dnsrr_resolver), | 91 dnsrr_resolver_(dnsrr_resolver), |
| 92 ssl_host_info_factory_(ssl_host_info_factory), |
| 90 ALLOW_THIS_IN_INITIALIZER_LIST( | 93 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 91 callback_(this, &SSLConnectJob::OnIOComplete)) {} | 94 callback_(this, &SSLConnectJob::OnIOComplete)) {} |
| 92 | 95 |
| 93 SSLConnectJob::~SSLConnectJob() {} | 96 SSLConnectJob::~SSLConnectJob() {} |
| 94 | 97 |
| 95 LoadState SSLConnectJob::GetLoadState() const { | 98 LoadState SSLConnectJob::GetLoadState() const { |
| 96 switch (next_state_) { | 99 switch (next_state_) { |
| 97 case STATE_TUNNEL_CONNECT_COMPLETE: | 100 case STATE_TUNNEL_CONNECT_COMPLETE: |
| 98 if (transport_socket_handle_->socket()) | 101 if (transport_socket_handle_->socket()) |
| 99 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; | 102 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 break; | 184 break; |
| 182 } | 185 } |
| 183 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 186 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 184 | 187 |
| 185 return rv; | 188 return rv; |
| 186 } | 189 } |
| 187 | 190 |
| 188 int SSLConnectJob::DoTCPConnect() { | 191 int SSLConnectJob::DoTCPConnect() { |
| 189 DCHECK(tcp_pool_); | 192 DCHECK(tcp_pool_); |
| 190 | 193 |
| 191 if (params_->ssl_config().ssl_host_info.get()) { | 194 if (ssl_host_info_factory_ && SSLConfigService::snap_start_enabled()) { |
| 195 ssl_host_info_.reset( |
| 196 ssl_host_info_factory_->GetForHost(params_->hostname())); |
| 197 } |
| 198 if (ssl_host_info_.get()) { |
| 192 // This starts fetching the SSL host info from the disk cache for Snap | 199 // This starts fetching the SSL host info from the disk cache for Snap |
| 193 // Start. | 200 // Start. |
| 194 params_->ssl_config().ssl_host_info->Start(); | 201 ssl_host_info_->Start(); |
| 195 } | 202 } |
| 196 | 203 |
| 197 next_state_ = STATE_TCP_CONNECT_COMPLETE; | 204 next_state_ = STATE_TCP_CONNECT_COMPLETE; |
| 198 transport_socket_handle_.reset(new ClientSocketHandle()); | 205 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 199 scoped_refptr<TCPSocketParams> tcp_params = params_->tcp_params(); | 206 scoped_refptr<TCPSocketParams> tcp_params = params_->tcp_params(); |
| 200 return transport_socket_handle_->Init(group_name(), tcp_params, | 207 return transport_socket_handle_->Init(group_name(), tcp_params, |
| 201 tcp_params->destination().priority(), | 208 tcp_params->destination().priority(), |
| 202 &callback_, tcp_pool_, net_log()); | 209 &callback_, tcp_pool_, net_log()); |
| 203 } | 210 } |
| 204 | 211 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 277 } |
| 271 | 278 |
| 272 int SSLConnectJob::DoSSLConnect() { | 279 int SSLConnectJob::DoSSLConnect() { |
| 273 next_state_ = STATE_SSL_CONNECT_COMPLETE; | 280 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
| 274 // Reset the timeout to just the time allowed for the SSL handshake. | 281 // Reset the timeout to just the time allowed for the SSL handshake. |
| 275 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); | 282 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); |
| 276 ssl_connect_start_time_ = base::TimeTicks::Now(); | 283 ssl_connect_start_time_ = base::TimeTicks::Now(); |
| 277 | 284 |
| 278 ssl_socket_.reset(client_socket_factory_->CreateSSLClientSocket( | 285 ssl_socket_.reset(client_socket_factory_->CreateSSLClientSocket( |
| 279 transport_socket_handle_.release(), params_->hostname(), | 286 transport_socket_handle_.release(), params_->hostname(), |
| 280 params_->ssl_config())); | 287 params_->ssl_config(), ssl_host_info_.release())); |
| 281 return ssl_socket_->Connect(&callback_); | 288 return ssl_socket_->Connect(&callback_); |
| 282 } | 289 } |
| 283 | 290 |
| 284 int SSLConnectJob::DoSSLConnectComplete(int result) { | 291 int SSLConnectJob::DoSSLConnectComplete(int result) { |
| 285 SSLClientSocket::NextProtoStatus status = | 292 SSLClientSocket::NextProtoStatus status = |
| 286 SSLClientSocket::kNextProtoUnsupported; | 293 SSLClientSocket::kNextProtoUnsupported; |
| 287 std::string proto; | 294 std::string proto; |
| 288 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket | 295 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket |
| 289 // that hasn't had SSL_ImportFD called on it. If we get a certificate error | 296 // that hasn't had SSL_ImportFD called on it. If we get a certificate error |
| 290 // here, then we know that we called SSL_ImportFD. | 297 // here, then we know that we called SSL_ImportFD. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 return result; | 348 return result; |
| 342 } | 349 } |
| 343 | 350 |
| 344 ConnectJob* SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( | 351 ConnectJob* SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( |
| 345 const std::string& group_name, | 352 const std::string& group_name, |
| 346 const PoolBase::Request& request, | 353 const PoolBase::Request& request, |
| 347 ConnectJob::Delegate* delegate) const { | 354 ConnectJob::Delegate* delegate) const { |
| 348 return new SSLConnectJob(group_name, request.params(), ConnectionTimeout(), | 355 return new SSLConnectJob(group_name, request.params(), ConnectionTimeout(), |
| 349 tcp_pool_, socks_pool_, http_proxy_pool_, | 356 tcp_pool_, socks_pool_, http_proxy_pool_, |
| 350 client_socket_factory_, host_resolver_, | 357 client_socket_factory_, host_resolver_, |
| 351 dnsrr_resolver_, delegate, net_log_); | 358 dnsrr_resolver_, ssl_host_info_factory_, delegate, |
| 359 net_log_); |
| 352 } | 360 } |
| 353 | 361 |
| 354 SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory( | 362 SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory( |
| 355 TCPClientSocketPool* tcp_pool, | 363 TCPClientSocketPool* tcp_pool, |
| 356 SOCKSClientSocketPool* socks_pool, | 364 SOCKSClientSocketPool* socks_pool, |
| 357 HttpProxyClientSocketPool* http_proxy_pool, | 365 HttpProxyClientSocketPool* http_proxy_pool, |
| 358 ClientSocketFactory* client_socket_factory, | 366 ClientSocketFactory* client_socket_factory, |
| 359 HostResolver* host_resolver, | 367 HostResolver* host_resolver, |
| 360 DnsRRResolver* dnsrr_resolver, | 368 DnsRRResolver* dnsrr_resolver, |
| 369 SSLHostInfoFactory* ssl_host_info_factory, |
| 361 NetLog* net_log) | 370 NetLog* net_log) |
| 362 : tcp_pool_(tcp_pool), | 371 : tcp_pool_(tcp_pool), |
| 363 socks_pool_(socks_pool), | 372 socks_pool_(socks_pool), |
| 364 http_proxy_pool_(http_proxy_pool), | 373 http_proxy_pool_(http_proxy_pool), |
| 365 client_socket_factory_(client_socket_factory), | 374 client_socket_factory_(client_socket_factory), |
| 366 host_resolver_(host_resolver), | 375 host_resolver_(host_resolver), |
| 367 dnsrr_resolver_(dnsrr_resolver), | 376 dnsrr_resolver_(dnsrr_resolver), |
| 377 ssl_host_info_factory_(ssl_host_info_factory), |
| 368 net_log_(net_log) { | 378 net_log_(net_log) { |
| 369 base::TimeDelta max_transport_timeout = base::TimeDelta(); | 379 base::TimeDelta max_transport_timeout = base::TimeDelta(); |
| 370 base::TimeDelta pool_timeout; | 380 base::TimeDelta pool_timeout; |
| 371 if (tcp_pool_) | 381 if (tcp_pool_) |
| 372 max_transport_timeout = tcp_pool_->ConnectionTimeout(); | 382 max_transport_timeout = tcp_pool_->ConnectionTimeout(); |
| 373 if (socks_pool_) { | 383 if (socks_pool_) { |
| 374 pool_timeout = socks_pool_->ConnectionTimeout(); | 384 pool_timeout = socks_pool_->ConnectionTimeout(); |
| 375 if (pool_timeout > max_transport_timeout) | 385 if (pool_timeout > max_transport_timeout) |
| 376 max_transport_timeout = pool_timeout; | 386 max_transport_timeout = pool_timeout; |
| 377 } | 387 } |
| 378 if (http_proxy_pool_) { | 388 if (http_proxy_pool_) { |
| 379 pool_timeout = http_proxy_pool_->ConnectionTimeout(); | 389 pool_timeout = http_proxy_pool_->ConnectionTimeout(); |
| 380 if (pool_timeout > max_transport_timeout) | 390 if (pool_timeout > max_transport_timeout) |
| 381 max_transport_timeout = pool_timeout; | 391 max_transport_timeout = pool_timeout; |
| 382 } | 392 } |
| 383 timeout_ = max_transport_timeout + | 393 timeout_ = max_transport_timeout + |
| 384 base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds); | 394 base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds); |
| 385 } | 395 } |
| 386 | 396 |
| 387 SSLClientSocketPool::SSLClientSocketPool( | 397 SSLClientSocketPool::SSLClientSocketPool( |
| 388 int max_sockets, | 398 int max_sockets, |
| 389 int max_sockets_per_group, | 399 int max_sockets_per_group, |
| 390 ClientSocketPoolHistograms* histograms, | 400 ClientSocketPoolHistograms* histograms, |
| 391 HostResolver* host_resolver, | 401 HostResolver* host_resolver, |
| 392 DnsRRResolver* dnsrr_resolver, | 402 DnsRRResolver* dnsrr_resolver, |
| 403 SSLHostInfoFactory* ssl_host_info_factory, |
| 393 ClientSocketFactory* client_socket_factory, | 404 ClientSocketFactory* client_socket_factory, |
| 394 TCPClientSocketPool* tcp_pool, | 405 TCPClientSocketPool* tcp_pool, |
| 395 SOCKSClientSocketPool* socks_pool, | 406 SOCKSClientSocketPool* socks_pool, |
| 396 HttpProxyClientSocketPool* http_proxy_pool, | 407 HttpProxyClientSocketPool* http_proxy_pool, |
| 397 SSLConfigService* ssl_config_service, | 408 SSLConfigService* ssl_config_service, |
| 398 NetLog* net_log) | 409 NetLog* net_log) |
| 399 : tcp_pool_(tcp_pool), | 410 : tcp_pool_(tcp_pool), |
| 400 socks_pool_(socks_pool), | 411 socks_pool_(socks_pool), |
| 401 http_proxy_pool_(http_proxy_pool), | 412 http_proxy_pool_(http_proxy_pool), |
| 402 base_(max_sockets, max_sockets_per_group, histograms, | 413 base_(max_sockets, max_sockets_per_group, histograms, |
| 403 base::TimeDelta::FromSeconds( | 414 base::TimeDelta::FromSeconds( |
| 404 ClientSocketPool::unused_idle_socket_timeout()), | 415 ClientSocketPool::unused_idle_socket_timeout()), |
| 405 base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), | 416 base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), |
| 406 new SSLConnectJobFactory(tcp_pool, socks_pool, http_proxy_pool, | 417 new SSLConnectJobFactory(tcp_pool, socks_pool, http_proxy_pool, |
| 407 client_socket_factory, host_resolver, | 418 client_socket_factory, host_resolver, |
| 408 dnsrr_resolver, net_log)), | 419 dnsrr_resolver, ssl_host_info_factory, |
| 420 net_log)), |
| 409 ssl_config_service_(ssl_config_service) { | 421 ssl_config_service_(ssl_config_service) { |
| 410 if (ssl_config_service_) | 422 if (ssl_config_service_) |
| 411 ssl_config_service_->AddObserver(this); | 423 ssl_config_service_->AddObserver(this); |
| 412 } | 424 } |
| 413 | 425 |
| 414 SSLClientSocketPool::~SSLClientSocketPool() { | 426 SSLClientSocketPool::~SSLClientSocketPool() { |
| 415 if (ssl_config_service_) | 427 if (ssl_config_service_) |
| 416 ssl_config_service_->RemoveObserver(this); | 428 ssl_config_service_->RemoveObserver(this); |
| 417 } | 429 } |
| 418 | 430 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 list->Append(http_proxy_pool_->GetInfoAsValue("http_proxy_pool", | 505 list->Append(http_proxy_pool_->GetInfoAsValue("http_proxy_pool", |
| 494 "http_proxy_pool", | 506 "http_proxy_pool", |
| 495 true)); | 507 true)); |
| 496 } | 508 } |
| 497 dict->Set("nested_pools", list); | 509 dict->Set("nested_pools", list); |
| 498 } | 510 } |
| 499 return dict; | 511 return dict; |
| 500 } | 512 } |
| 501 | 513 |
| 502 } // namespace net | 514 } // namespace net |
| OLD | NEW |