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