Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 | 97 |
| 98 SSLConnectJobMessenger::SocketAndCallback::SocketAndCallback( | 98 SSLConnectJobMessenger::SocketAndCallback::SocketAndCallback( |
| 99 SSLClientSocket* ssl_socket, | 99 SSLClientSocket* ssl_socket, |
| 100 const base::Closure& job_resumption_callback) | 100 const base::Closure& job_resumption_callback) |
| 101 : socket(ssl_socket), callback(job_resumption_callback) { | 101 : socket(ssl_socket), callback(job_resumption_callback) { |
| 102 } | 102 } |
| 103 | 103 |
| 104 SSLConnectJobMessenger::SocketAndCallback::~SocketAndCallback() { | 104 SSLConnectJobMessenger::SocketAndCallback::~SocketAndCallback() { |
| 105 } | 105 } |
| 106 | 106 |
| 107 SSLConnectJobMessenger::SSLConnectJobMessenger() : weak_factory_(this) { | 107 SSLConnectJobMessenger::SSLConnectJobMessenger( |
| 108 const ConnectionCompleteCallback& connection_complete_callback) | |
| 109 : weak_factory_(this), | |
| 110 connection_complete_callback_(connection_complete_callback) { | |
| 108 } | 111 } |
| 109 | 112 |
| 110 SSLConnectJobMessenger::~SSLConnectJobMessenger() { | 113 SSLConnectJobMessenger::~SSLConnectJobMessenger() { |
| 111 } | 114 } |
| 112 | 115 |
| 113 void SSLConnectJobMessenger::RemovePendingSocket(SSLClientSocket* ssl_socket) { | 116 void SSLConnectJobMessenger::RemovePendingSocket(SSLClientSocket* ssl_socket) { |
| 114 // Sockets do not need to be removed from connecting_sockets_ because | 117 // Sockets do not need to be removed from connecting_sockets_ because |
| 115 // OnSSLHandshakeCompleted will do this. | 118 // OnSSLHandshakeCompleted will do this. |
| 116 for (SSLPendingSocketsAndCallbacks::iterator it = | 119 for (SSLPendingSocketsAndCallbacks::iterator it = |
| 117 pending_sockets_and_callbacks_.begin(); | 120 pending_sockets_and_callbacks_.begin(); |
| 118 it != pending_sockets_and_callbacks_.end(); | 121 it != pending_sockets_and_callbacks_.end(); |
| 119 ++it) { | 122 ++it) { |
| 120 if (it->socket == ssl_socket) { | 123 if (it->socket == ssl_socket) { |
| 121 pending_sockets_and_callbacks_.erase(it); | 124 pending_sockets_and_callbacks_.erase(it); |
| 122 return; | 125 return; |
| 123 } | 126 } |
| 124 } | 127 } |
| 125 } | 128 } |
| 126 | 129 |
| 127 bool SSLConnectJobMessenger::CanProceed(SSLClientSocket* ssl_socket) { | 130 bool SSLConnectJobMessenger::CanProceed(SSLClientSocket* ssl_socket) { |
| 128 // If the session is in the session cache, or there are no connecting | 131 // If there are no connecting sockets allow the connection to proceed. |
| 129 // sockets, allow the connection to proceed. | 132 return connecting_sockets_.empty(); |
| 130 return ssl_socket->InSessionCache() || connecting_sockets_.empty(); | |
| 131 } | 133 } |
| 132 | 134 |
| 133 void SSLConnectJobMessenger::MonitorConnectionResult( | 135 void SSLConnectJobMessenger::MonitorConnectionResult( |
| 134 SSLClientSocket* ssl_socket) { | 136 SSLClientSocket* ssl_socket) { |
| 135 connecting_sockets_.push_back(ssl_socket); | 137 connecting_sockets_.push_back(ssl_socket); |
| 136 ssl_socket->SetHandshakeCompletionCallback( | 138 ssl_socket->SetHandshakeCompletionCallback( |
| 137 base::Bind(&SSLConnectJobMessenger::OnSSLHandshakeCompleted, | 139 base::Bind(&SSLConnectJobMessenger::OnSSLHandshakeCompleted, |
| 138 weak_factory_.GetWeakPtr())); | 140 weak_factory_.GetWeakPtr())); |
| 139 } | 141 } |
| 140 | 142 |
| 141 void SSLConnectJobMessenger::AddPendingSocket(SSLClientSocket* ssl_socket, | 143 void SSLConnectJobMessenger::AddPendingSocket(SSLClientSocket* ssl_socket, |
| 142 const base::Closure& callback) { | 144 const base::Closure& callback) { |
| 143 DCHECK(!connecting_sockets_.empty()); | 145 DCHECK(!connecting_sockets_.empty()); |
| 144 pending_sockets_and_callbacks_.push_back( | 146 pending_sockets_and_callbacks_.push_back( |
| 145 SocketAndCallback(ssl_socket, callback)); | 147 SocketAndCallback(ssl_socket, callback)); |
| 146 } | 148 } |
| 147 | 149 |
| 148 void SSLConnectJobMessenger::OnSSLHandshakeCompleted() { | 150 void SSLConnectJobMessenger::OnSSLHandshakeCompleted() { |
| 151 SSLClientSocket* ssl_socket = NULL; | |
| 152 if (!connecting_sockets_.empty()) | |
| 153 ssl_socket = connecting_sockets_.front(); | |
|
Ryan Sleevi
2014/08/13 01:02:15
Are these changes unrelated? Under what scenario c
mshelley
2014/08/13 08:09:59
Done.
| |
| 149 connecting_sockets_.clear(); | 154 connecting_sockets_.clear(); |
| 150 SSLPendingSocketsAndCallbacks temp_list; | 155 SSLPendingSocketsAndCallbacks temp_list; |
| 151 temp_list.swap(pending_sockets_and_callbacks_); | 156 temp_list.swap(pending_sockets_and_callbacks_); |
| 152 RunAllCallbacks(temp_list); | 157 RunAllCallbacks(temp_list); |
| 158 if (ssl_socket) | |
| 159 connection_complete_callback_.Run(ssl_socket->GetSessionCacheKey()); | |
| 153 } | 160 } |
| 154 | 161 |
| 155 void SSLConnectJobMessenger::RunAllCallbacks( | 162 void SSLConnectJobMessenger::RunAllCallbacks( |
| 156 const SSLPendingSocketsAndCallbacks& pending_sockets_and_callbacks) { | 163 const SSLPendingSocketsAndCallbacks& pending_sockets_and_callbacks) { |
| 157 for (std::vector<SocketAndCallback>::const_iterator it = | 164 for (std::vector<SocketAndCallback>::const_iterator it = |
| 158 pending_sockets_and_callbacks.begin(); | 165 pending_sockets_and_callbacks.begin(); |
| 159 it != pending_sockets_and_callbacks.end(); | 166 it != pending_sockets_and_callbacks.end(); |
| 160 ++it) { | 167 ++it) { |
| 161 it->callback.Run(); | 168 it->callback.Run(); |
| 162 } | 169 } |
| 163 } | 170 } |
| 164 | 171 |
| 165 // Timeout for the SSL handshake portion of the connect. | 172 // Timeout for the SSL handshake portion of the connect. |
| 166 static const int kSSLHandshakeTimeoutInSeconds = 30; | 173 static const int kSSLHandshakeTimeoutInSeconds = 30; |
| 167 | 174 |
| 168 SSLConnectJob::SSLConnectJob(const std::string& group_name, | 175 SSLConnectJob::SSLConnectJob( |
| 169 RequestPriority priority, | 176 const std::string& group_name, |
| 170 const scoped_refptr<SSLSocketParams>& params, | 177 RequestPriority priority, |
| 171 const base::TimeDelta& timeout_duration, | 178 const scoped_refptr<SSLSocketParams>& params, |
| 172 TransportClientSocketPool* transport_pool, | 179 const base::TimeDelta& timeout_duration, |
| 173 SOCKSClientSocketPool* socks_pool, | 180 TransportClientSocketPool* transport_pool, |
| 174 HttpProxyClientSocketPool* http_proxy_pool, | 181 SOCKSClientSocketPool* socks_pool, |
| 175 ClientSocketFactory* client_socket_factory, | 182 HttpProxyClientSocketPool* http_proxy_pool, |
| 176 HostResolver* host_resolver, | 183 ClientSocketFactory* client_socket_factory, |
| 177 const SSLClientSocketContext& context, | 184 HostResolver* host_resolver, |
| 178 SSLConnectJobMessenger* messenger, | 185 const SSLClientSocketContext& context, |
| 179 Delegate* delegate, | 186 GetMessengerForUncachedSessionCallback uncached_session_callback, |
| 180 NetLog* net_log) | 187 bool enable_ssl_connect_job_waiting, |
| 188 Delegate* delegate, | |
| 189 NetLog* net_log) | |
| 181 : ConnectJob(group_name, | 190 : ConnectJob(group_name, |
| 182 timeout_duration, | 191 timeout_duration, |
| 183 priority, | 192 priority, |
| 184 delegate, | 193 delegate, |
| 185 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 194 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 186 params_(params), | 195 params_(params), |
| 187 transport_pool_(transport_pool), | 196 transport_pool_(transport_pool), |
| 188 socks_pool_(socks_pool), | 197 socks_pool_(socks_pool), |
| 189 http_proxy_pool_(http_proxy_pool), | 198 http_proxy_pool_(http_proxy_pool), |
| 190 client_socket_factory_(client_socket_factory), | 199 client_socket_factory_(client_socket_factory), |
| 191 host_resolver_(host_resolver), | 200 host_resolver_(host_resolver), |
| 192 context_(context.cert_verifier, | 201 context_(context.cert_verifier, |
| 193 context.channel_id_service, | 202 context.channel_id_service, |
| 194 context.transport_security_state, | 203 context.transport_security_state, |
| 195 context.cert_transparency_verifier, | 204 context.cert_transparency_verifier, |
| 196 (params->privacy_mode() == PRIVACY_MODE_ENABLED | 205 (params->privacy_mode() == PRIVACY_MODE_ENABLED |
| 197 ? "pm/" + context.ssl_session_cache_shard | 206 ? "pm/" + context.ssl_session_cache_shard |
| 198 : context.ssl_session_cache_shard)), | 207 : context.ssl_session_cache_shard)), |
| 199 io_callback_( | 208 io_callback_( |
| 200 base::Bind(&SSLConnectJob::OnIOComplete, base::Unretained(this))), | 209 base::Bind(&SSLConnectJob::OnIOComplete, base::Unretained(this))), |
| 201 messenger_(messenger), | 210 messenger_(NULL), |
| 202 weak_factory_(this) { | 211 weak_factory_(this), |
|
Ryan Sleevi
2014/08/13 01:02:12
see comment about Weak Factory's always needing to
mshelley
2014/08/13 08:09:59
Done.
| |
| 212 uncached_session_callback_(uncached_session_callback), | |
| 213 enable_ssl_connect_job_waiting_(enable_ssl_connect_job_waiting) { | |
| 203 } | 214 } |
| 204 | 215 |
| 205 SSLConnectJob::~SSLConnectJob() { | 216 SSLConnectJob::~SSLConnectJob() { |
| 206 if (ssl_socket_.get() && messenger_) | 217 if (ssl_socket_.get() && messenger_) |
| 207 messenger_->RemovePendingSocket(ssl_socket_.get()); | 218 messenger_->RemovePendingSocket(ssl_socket_.get()); |
| 208 } | 219 } |
| 209 | 220 |
| 210 LoadState SSLConnectJob::GetLoadState() const { | 221 LoadState SSLConnectJob::GetLoadState() const { |
| 211 switch (next_state_) { | 222 switch (next_state_) { |
| 212 case STATE_TUNNEL_CONNECT_COMPLETE: | 223 case STATE_TUNNEL_CONNECT_COMPLETE: |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 connect_timing_.connect_start = socket_connect_timing.connect_start; | 406 connect_timing_.connect_start = socket_connect_timing.connect_start; |
| 396 connect_timing_.dns_start = socket_connect_timing.dns_start; | 407 connect_timing_.dns_start = socket_connect_timing.dns_start; |
| 397 connect_timing_.dns_end = socket_connect_timing.dns_end; | 408 connect_timing_.dns_end = socket_connect_timing.dns_end; |
| 398 } | 409 } |
| 399 | 410 |
| 400 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket( | 411 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket( |
| 401 transport_socket_handle_.Pass(), | 412 transport_socket_handle_.Pass(), |
| 402 params_->host_and_port(), | 413 params_->host_and_port(), |
| 403 params_->ssl_config(), | 414 params_->ssl_config(), |
| 404 context_); | 415 context_); |
| 416 | |
| 417 if (!ssl_socket_->InSessionCache() && enable_ssl_connect_job_waiting_) | |
| 418 RunGetMessengerForUncachedSessionCallback( | |
|
Ryan Sleevi
2014/08/13 01:02:11
This is only called in one place (here). I'd just
mshelley
2014/08/13 08:09:59
Done.
| |
| 419 ssl_socket_->GetSessionCacheKey()); | |
| 420 | |
| 405 return OK; | 421 return OK; |
| 406 } | 422 } |
| 407 | 423 |
| 408 int SSLConnectJob::DoCheckForResume() { | 424 int SSLConnectJob::DoCheckForResume() { |
| 409 next_state_ = STATE_SSL_CONNECT; | 425 next_state_ = STATE_SSL_CONNECT; |
| 410 if (!messenger_) | 426 |
| 427 if (ssl_socket_->InSessionCache() || !messenger_) | |
| 411 return OK; | 428 return OK; |
| 412 | 429 |
| 413 // TODO(mshelley): Remove duplicate InSessionCache() calls. | |
| 414 if (messenger_->CanProceed(ssl_socket_.get())) { | 430 if (messenger_->CanProceed(ssl_socket_.get())) { |
| 415 if (!ssl_socket_->InSessionCache()) | 431 messenger_->MonitorConnectionResult(ssl_socket_.get()); |
| 416 messenger_->MonitorConnectionResult(ssl_socket_.get()); | 432 // The SSLConnectJob no longer needs access to the messenger after this |
| 433 // point. | |
| 434 messenger_ = NULL; | |
| 417 return OK; | 435 return OK; |
| 418 } | 436 } |
| 437 | |
| 419 messenger_->AddPendingSocket(ssl_socket_.get(), | 438 messenger_->AddPendingSocket(ssl_socket_.get(), |
| 420 base::Bind(&SSLConnectJob::ResumeSSLConnection, | 439 base::Bind(&SSLConnectJob::ResumeSSLConnection, |
| 421 weak_factory_.GetWeakPtr())); | 440 weak_factory_.GetWeakPtr())); |
| 441 | |
| 422 return ERR_IO_PENDING; | 442 return ERR_IO_PENDING; |
| 423 } | 443 } |
| 424 | 444 |
| 425 int SSLConnectJob::DoSSLConnect() { | 445 int SSLConnectJob::DoSSLConnect() { |
| 426 next_state_ = STATE_SSL_CONNECT_COMPLETE; | 446 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
| 427 | 447 |
| 428 connect_timing_.ssl_start = base::TimeTicks::Now(); | 448 connect_timing_.ssl_start = base::TimeTicks::Now(); |
| 429 | 449 |
| 430 return ssl_socket_->Connect(io_callback_); | 450 return ssl_socket_->Connect(io_callback_); |
| 431 } | 451 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 error_response_info_.cert_request_info = new SSLCertRequestInfo; | 569 error_response_info_.cert_request_info = new SSLCertRequestInfo; |
| 550 ssl_socket_->GetSSLCertRequestInfo( | 570 ssl_socket_->GetSSLCertRequestInfo( |
| 551 error_response_info_.cert_request_info.get()); | 571 error_response_info_.cert_request_info.get()); |
| 552 } | 572 } |
| 553 | 573 |
| 554 return result; | 574 return result; |
| 555 } | 575 } |
| 556 | 576 |
| 557 void SSLConnectJob::ResumeSSLConnection() { | 577 void SSLConnectJob::ResumeSSLConnection() { |
| 558 DCHECK_EQ(next_state_, STATE_SSL_CONNECT); | 578 DCHECK_EQ(next_state_, STATE_SSL_CONNECT); |
| 579 messenger_ = NULL; | |
| 559 OnIOComplete(OK); | 580 OnIOComplete(OK); |
| 560 } | 581 } |
| 561 | 582 |
| 583 void SSLConnectJob::RunGetMessengerForUncachedSessionCallback( | |
| 584 const std::string& cache_key) { | |
| 585 messenger_ = uncached_session_callback_.Run(cache_key); | |
| 586 } | |
| 587 | |
| 562 SSLConnectJob::State SSLConnectJob::GetInitialState( | 588 SSLConnectJob::State SSLConnectJob::GetInitialState( |
| 563 SSLSocketParams::ConnectionType connection_type) { | 589 SSLSocketParams::ConnectionType connection_type) { |
| 564 switch (connection_type) { | 590 switch (connection_type) { |
| 565 case SSLSocketParams::DIRECT: | 591 case SSLSocketParams::DIRECT: |
| 566 return STATE_TRANSPORT_CONNECT; | 592 return STATE_TRANSPORT_CONNECT; |
| 567 case SSLSocketParams::HTTP_PROXY: | 593 case SSLSocketParams::HTTP_PROXY: |
| 568 return STATE_TUNNEL_CONNECT; | 594 return STATE_TUNNEL_CONNECT; |
| 569 case SSLSocketParams::SOCKS_PROXY: | 595 case SSLSocketParams::SOCKS_PROXY: |
| 570 return STATE_SOCKS_CONNECT; | 596 return STATE_SOCKS_CONNECT; |
| 571 } | 597 } |
| 572 NOTREACHED(); | 598 NOTREACHED(); |
| 573 return STATE_NONE; | 599 return STATE_NONE; |
| 574 } | 600 } |
| 575 | 601 |
| 576 int SSLConnectJob::ConnectInternal() { | 602 int SSLConnectJob::ConnectInternal() { |
| 577 next_state_ = GetInitialState(params_->GetConnectionType()); | 603 next_state_ = GetInitialState(params_->GetConnectionType()); |
| 578 return DoLoop(OK); | 604 return DoLoop(OK); |
| 579 } | 605 } |
| 580 | 606 |
| 581 SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory( | 607 SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory( |
| 582 TransportClientSocketPool* transport_pool, | 608 TransportClientSocketPool* transport_pool, |
| 583 SOCKSClientSocketPool* socks_pool, | 609 SOCKSClientSocketPool* socks_pool, |
| 584 HttpProxyClientSocketPool* http_proxy_pool, | 610 HttpProxyClientSocketPool* http_proxy_pool, |
| 585 ClientSocketFactory* client_socket_factory, | 611 ClientSocketFactory* client_socket_factory, |
| 586 HostResolver* host_resolver, | 612 HostResolver* host_resolver, |
| 587 const SSLClientSocketContext& context, | 613 const SSLClientSocketContext& context, |
| 588 bool enable_ssl_connect_job_waiting, | 614 bool enable_ssl_connect_job_waiting, |
| 615 SSLConnectJob::GetMessengerForUncachedSessionCallback | |
| 616 uncached_session_callback, | |
| 589 NetLog* net_log) | 617 NetLog* net_log) |
| 590 : transport_pool_(transport_pool), | 618 : transport_pool_(transport_pool), |
| 591 socks_pool_(socks_pool), | 619 socks_pool_(socks_pool), |
| 592 http_proxy_pool_(http_proxy_pool), | 620 http_proxy_pool_(http_proxy_pool), |
| 593 client_socket_factory_(client_socket_factory), | 621 client_socket_factory_(client_socket_factory), |
| 594 host_resolver_(host_resolver), | 622 host_resolver_(host_resolver), |
| 595 context_(context), | 623 context_(context), |
| 596 enable_ssl_connect_job_waiting_(enable_ssl_connect_job_waiting), | 624 enable_ssl_connect_job_waiting_(enable_ssl_connect_job_waiting), |
| 597 net_log_(net_log), | 625 uncached_session_callback_(uncached_session_callback), |
| 598 messenger_map_(new MessengerMap) { | 626 net_log_(net_log) { |
| 599 base::TimeDelta max_transport_timeout = base::TimeDelta(); | 627 base::TimeDelta max_transport_timeout = base::TimeDelta(); |
| 600 base::TimeDelta pool_timeout; | 628 base::TimeDelta pool_timeout; |
| 601 if (transport_pool_) | 629 if (transport_pool_) |
| 602 max_transport_timeout = transport_pool_->ConnectionTimeout(); | 630 max_transport_timeout = transport_pool_->ConnectionTimeout(); |
| 603 if (socks_pool_) { | 631 if (socks_pool_) { |
| 604 pool_timeout = socks_pool_->ConnectionTimeout(); | 632 pool_timeout = socks_pool_->ConnectionTimeout(); |
| 605 if (pool_timeout > max_transport_timeout) | 633 if (pool_timeout > max_transport_timeout) |
| 606 max_transport_timeout = pool_timeout; | 634 max_transport_timeout = pool_timeout; |
| 607 } | 635 } |
| 608 if (http_proxy_pool_) { | 636 if (http_proxy_pool_) { |
| 609 pool_timeout = http_proxy_pool_->ConnectionTimeout(); | 637 pool_timeout = http_proxy_pool_->ConnectionTimeout(); |
| 610 if (pool_timeout > max_transport_timeout) | 638 if (pool_timeout > max_transport_timeout) |
| 611 max_transport_timeout = pool_timeout; | 639 max_transport_timeout = pool_timeout; |
| 612 } | 640 } |
| 613 timeout_ = max_transport_timeout + | 641 timeout_ = max_transport_timeout + |
| 614 base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds); | 642 base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds); |
| 615 } | 643 } |
| 616 | 644 |
| 617 SSLClientSocketPool::SSLConnectJobFactory::~SSLConnectJobFactory() { | 645 SSLClientSocketPool::SSLConnectJobFactory::~SSLConnectJobFactory() { |
| 618 STLDeleteValues(messenger_map_.get()); | |
| 619 } | 646 } |
| 620 | 647 |
| 621 SSLClientSocketPool::SSLClientSocketPool( | 648 SSLClientSocketPool::SSLClientSocketPool( |
| 622 int max_sockets, | 649 int max_sockets, |
| 623 int max_sockets_per_group, | 650 int max_sockets_per_group, |
| 624 ClientSocketPoolHistograms* histograms, | 651 ClientSocketPoolHistograms* histograms, |
| 625 HostResolver* host_resolver, | 652 HostResolver* host_resolver, |
| 626 CertVerifier* cert_verifier, | 653 CertVerifier* cert_verifier, |
| 627 ChannelIDService* channel_id_service, | 654 ChannelIDService* channel_id_service, |
| 628 TransportSecurityState* transport_security_state, | 655 TransportSecurityState* transport_security_state, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 649 socks_pool, | 676 socks_pool, |
| 650 http_proxy_pool, | 677 http_proxy_pool, |
| 651 client_socket_factory, | 678 client_socket_factory, |
| 652 host_resolver, | 679 host_resolver, |
| 653 SSLClientSocketContext(cert_verifier, | 680 SSLClientSocketContext(cert_verifier, |
| 654 channel_id_service, | 681 channel_id_service, |
| 655 transport_security_state, | 682 transport_security_state, |
| 656 cert_transparency_verifier, | 683 cert_transparency_verifier, |
| 657 ssl_session_cache_shard), | 684 ssl_session_cache_shard), |
| 658 enable_ssl_connect_job_waiting, | 685 enable_ssl_connect_job_waiting, |
| 686 base::Bind(&SSLClientSocketPool::AddSSLConnectJobMessenger, | |
| 687 base::Unretained(this)), | |
| 659 net_log)), | 688 net_log)), |
| 660 ssl_config_service_(ssl_config_service) { | 689 ssl_config_service_(ssl_config_service) { |
| 661 if (ssl_config_service_.get()) | 690 if (ssl_config_service_.get()) |
| 662 ssl_config_service_->AddObserver(this); | 691 ssl_config_service_->AddObserver(this); |
| 663 if (transport_pool_) | 692 if (transport_pool_) |
| 664 base_.AddLowerLayeredPool(transport_pool_); | 693 base_.AddLowerLayeredPool(transport_pool_); |
| 665 if (socks_pool_) | 694 if (socks_pool_) |
| 666 base_.AddLowerLayeredPool(socks_pool_); | 695 base_.AddLowerLayeredPool(socks_pool_); |
| 667 if (http_proxy_pool_) | 696 if (http_proxy_pool_) |
| 668 base_.AddLowerLayeredPool(http_proxy_pool_); | 697 base_.AddLowerLayeredPool(http_proxy_pool_); |
| 669 } | 698 } |
| 670 | 699 |
| 671 SSLClientSocketPool::~SSLClientSocketPool() { | 700 SSLClientSocketPool::~SSLClientSocketPool() { |
| 701 for (MessengerMap::iterator it = messenger_map_.begin(); | |
| 702 it != messenger_map_.end(); | |
| 703 ++it) { | |
| 704 delete it->second; | |
| 705 } | |
| 672 if (ssl_config_service_.get()) | 706 if (ssl_config_service_.get()) |
| 673 ssl_config_service_->RemoveObserver(this); | 707 ssl_config_service_->RemoveObserver(this); |
| 674 } | 708 } |
| 675 | 709 |
| 676 scoped_ptr<ConnectJob> | 710 scoped_ptr<ConnectJob> SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( |
| 677 SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( | |
| 678 const std::string& group_name, | 711 const std::string& group_name, |
| 679 const PoolBase::Request& request, | 712 const PoolBase::Request& request, |
| 680 ConnectJob::Delegate* delegate) const { | 713 ConnectJob::Delegate* delegate) const { |
| 681 SSLConnectJobMessenger* messenger = NULL; | 714 return scoped_ptr<ConnectJob>( |
| 682 if (enable_ssl_connect_job_waiting_) { | 715 new SSLConnectJob(group_name, |
| 683 std::string cache_key = SSLClientSocket::CreateSessionCacheKey( | 716 request.priority(), |
| 684 request.params()->host_and_port(), context_.ssl_session_cache_shard); | 717 request.params(), |
| 685 MessengerMap::const_iterator it = messenger_map_->find(cache_key); | 718 ConnectionTimeout(), |
| 686 if (it == messenger_map_->end()) { | 719 transport_pool_, |
| 687 std::pair<MessengerMap::iterator, bool> iter = messenger_map_->insert( | 720 socks_pool_, |
| 688 MessengerMap::value_type(cache_key, new SSLConnectJobMessenger())); | 721 http_proxy_pool_, |
| 689 it = iter.first; | 722 client_socket_factory_, |
| 690 } | 723 host_resolver_, |
| 691 messenger = it->second; | 724 context_, |
| 692 } | 725 uncached_session_callback_, |
| 693 | 726 enable_ssl_connect_job_waiting_, |
| 694 return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name, | 727 delegate, |
| 695 request.priority(), | 728 net_log_)); |
| 696 request.params(), | |
| 697 ConnectionTimeout(), | |
| 698 transport_pool_, | |
| 699 socks_pool_, | |
| 700 http_proxy_pool_, | |
| 701 client_socket_factory_, | |
| 702 host_resolver_, | |
| 703 context_, | |
| 704 messenger, | |
| 705 delegate, | |
| 706 net_log_)); | |
| 707 } | 729 } |
| 708 | 730 |
| 709 base::TimeDelta | 731 base::TimeDelta SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() |
| 710 SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() const { | 732 const { |
| 711 return timeout_; | 733 return timeout_; |
| 712 } | 734 } |
| 713 | 735 |
| 714 int SSLClientSocketPool::RequestSocket(const std::string& group_name, | 736 int SSLClientSocketPool::RequestSocket(const std::string& group_name, |
| 715 const void* socket_params, | 737 const void* socket_params, |
| 716 RequestPriority priority, | 738 RequestPriority priority, |
| 717 ClientSocketHandle* handle, | 739 ClientSocketHandle* handle, |
| 718 const CompletionCallback& callback, | 740 const CompletionCallback& callback, |
| 719 const BoundNetLog& net_log) { | 741 const BoundNetLog& net_log) { |
| 720 const scoped_refptr<SSLSocketParams>* casted_socket_params = | 742 const scoped_refptr<SSLSocketParams>* casted_socket_params = |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 HigherLayeredPool* higher_pool) { | 837 HigherLayeredPool* higher_pool) { |
| 816 base_.RemoveHigherLayeredPool(higher_pool); | 838 base_.RemoveHigherLayeredPool(higher_pool); |
| 817 } | 839 } |
| 818 | 840 |
| 819 bool SSLClientSocketPool::CloseOneIdleConnection() { | 841 bool SSLClientSocketPool::CloseOneIdleConnection() { |
| 820 if (base_.CloseOneIdleSocket()) | 842 if (base_.CloseOneIdleSocket()) |
| 821 return true; | 843 return true; |
| 822 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 844 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
| 823 } | 845 } |
| 824 | 846 |
| 847 SSLConnectJobMessenger* SSLClientSocketPool::AddSSLConnectJobMessenger( | |
| 848 const std::string& cache_key) { | |
| 849 MessengerMap::const_iterator it = messenger_map_.find(cache_key); | |
| 850 if (it == messenger_map_.end()) { | |
| 851 std::pair<MessengerMap::iterator, bool> iter = | |
| 852 messenger_map_.insert(MessengerMap::value_type( | |
| 853 cache_key, | |
| 854 new SSLConnectJobMessenger( | |
| 855 base::Bind(&SSLClientSocketPool::DeleteSSLConnectJobMessenger, | |
| 856 base::Unretained(this))))); | |
|
Ryan Sleevi
2014/08/13 01:02:11
To hide the need to *pass* the cache key to the SS
mshelley
2014/08/13 08:09:59
Done.
| |
| 857 it = iter.first; | |
| 858 } | |
| 859 return it->second; | |
| 860 } | |
| 861 | |
| 862 void SSLClientSocketPool::DeleteSSLConnectJobMessenger( | |
| 863 const std::string& cache_key) { | |
| 864 MessengerMap::iterator it = messenger_map_.find(cache_key); | |
| 865 delete it->second; | |
|
Ryan Sleevi
2014/08/13 01:02:15
CHECK_NE(it, messenger_map_.end()) ?
Otherwise, a
mshelley
2014/08/13 08:09:59
Done.
| |
| 866 messenger_map_.erase(it); | |
| 867 } | |
| 868 | |
| 825 void SSLClientSocketPool::OnSSLConfigChanged() { | 869 void SSLClientSocketPool::OnSSLConfigChanged() { |
| 826 FlushWithError(ERR_NETWORK_CHANGED); | 870 FlushWithError(ERR_NETWORK_CHANGED); |
| 827 } | 871 } |
| 828 | 872 |
| 829 } // namespace net | 873 } // namespace net |
| OLD | NEW |