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

Side by Side Diff: net/socket/ssl_client_socket_pool.cc

Issue 384873002: This CL changes the lifespan of SSLConnectJobMessengers so that they are created only when needed, (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@useloop
Patch Set: Renamed methods and member vars. Created 6 years, 4 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 (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
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 base::Closure& connection_complete_callback)
109 : connection_complete_callback_(connection_complete_callback),
110 weak_factory_(this) {
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) {
wtc 2014/08/14 23:26:26 1. Remove the unused |ssl_socket| parameter. 2. N
mshelley 2014/08/15 16:53:06 Done.
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() {
149 connecting_sockets_.clear(); 151 connecting_sockets_.clear();
150 SSLPendingSocketsAndCallbacks temp_list; 152 SSLPendingSocketsAndCallbacks temp_list;
151 temp_list.swap(pending_sockets_and_callbacks_); 153 temp_list.swap(pending_sockets_and_callbacks_);
154 base::Closure connection_complete_callback = connection_complete_callback_;
152 RunAllCallbacks(temp_list); 155 RunAllCallbacks(temp_list);
156 connection_complete_callback.Run();
wtc 2014/08/14 23:26:26 IMPORTANT: I think we should run connection_comple
mshelley 2014/08/15 16:53:06 Done.
153 } 157 }
154 158
155 void SSLConnectJobMessenger::RunAllCallbacks( 159 void SSLConnectJobMessenger::RunAllCallbacks(
156 const SSLPendingSocketsAndCallbacks& pending_sockets_and_callbacks) { 160 const SSLPendingSocketsAndCallbacks& pending_sockets_and_callbacks) {
157 for (std::vector<SocketAndCallback>::const_iterator it = 161 for (std::vector<SocketAndCallback>::const_iterator it =
158 pending_sockets_and_callbacks.begin(); 162 pending_sockets_and_callbacks.begin();
159 it != pending_sockets_and_callbacks.end(); 163 it != pending_sockets_and_callbacks.end();
160 ++it) { 164 ++it) {
161 it->callback.Run(); 165 it->callback.Run();
162 } 166 }
163 } 167 }
164 168
165 // Timeout for the SSL handshake portion of the connect. 169 // Timeout for the SSL handshake portion of the connect.
166 static const int kSSLHandshakeTimeoutInSeconds = 30; 170 static const int kSSLHandshakeTimeoutInSeconds = 30;
167 171
168 SSLConnectJob::SSLConnectJob(const std::string& group_name, 172 SSLConnectJob::SSLConnectJob(const std::string& group_name,
169 RequestPriority priority, 173 RequestPriority priority,
170 const scoped_refptr<SSLSocketParams>& params, 174 const scoped_refptr<SSLSocketParams>& params,
171 const base::TimeDelta& timeout_duration, 175 const base::TimeDelta& timeout_duration,
172 TransportClientSocketPool* transport_pool, 176 TransportClientSocketPool* transport_pool,
173 SOCKSClientSocketPool* socks_pool, 177 SOCKSClientSocketPool* socks_pool,
174 HttpProxyClientSocketPool* http_proxy_pool, 178 HttpProxyClientSocketPool* http_proxy_pool,
175 ClientSocketFactory* client_socket_factory, 179 ClientSocketFactory* client_socket_factory,
176 HostResolver* host_resolver, 180 HostResolver* host_resolver,
177 const SSLClientSocketContext& context, 181 const SSLClientSocketContext& context,
178 SSLConnectJobMessenger* messenger, 182 const GetMessengerCallback& get_messenger_callback,
179 Delegate* delegate, 183 Delegate* delegate,
180 NetLog* net_log) 184 NetLog* net_log)
181 : ConnectJob(group_name, 185 : ConnectJob(group_name,
182 timeout_duration, 186 timeout_duration,
183 priority, 187 priority,
184 delegate, 188 delegate,
185 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), 189 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)),
186 params_(params), 190 params_(params),
187 transport_pool_(transport_pool), 191 transport_pool_(transport_pool),
188 socks_pool_(socks_pool), 192 socks_pool_(socks_pool),
189 http_proxy_pool_(http_proxy_pool), 193 http_proxy_pool_(http_proxy_pool),
190 client_socket_factory_(client_socket_factory), 194 client_socket_factory_(client_socket_factory),
191 host_resolver_(host_resolver), 195 host_resolver_(host_resolver),
192 context_(context.cert_verifier, 196 context_(context.cert_verifier,
193 context.channel_id_service, 197 context.channel_id_service,
194 context.transport_security_state, 198 context.transport_security_state,
195 context.cert_transparency_verifier, 199 context.cert_transparency_verifier,
196 (params->privacy_mode() == PRIVACY_MODE_ENABLED 200 (params->privacy_mode() == PRIVACY_MODE_ENABLED
197 ? "pm/" + context.ssl_session_cache_shard 201 ? "pm/" + context.ssl_session_cache_shard
198 : context.ssl_session_cache_shard)), 202 : context.ssl_session_cache_shard)),
199 io_callback_( 203 io_callback_(
200 base::Bind(&SSLConnectJob::OnIOComplete, base::Unretained(this))), 204 base::Bind(&SSLConnectJob::OnIOComplete, base::Unretained(this))),
201 messenger_(messenger), 205 messenger_(NULL),
206 get_messenger_callback_(get_messenger_callback),
202 weak_factory_(this) { 207 weak_factory_(this) {
203 } 208 }
204 209
205 SSLConnectJob::~SSLConnectJob() { 210 SSLConnectJob::~SSLConnectJob() {
206 if (ssl_socket_.get() && messenger_) 211 if (ssl_socket_.get() && messenger_)
207 messenger_->RemovePendingSocket(ssl_socket_.get()); 212 messenger_->RemovePendingSocket(ssl_socket_.get());
208 } 213 }
209 214
210 LoadState SSLConnectJob::GetLoadState() const { 215 LoadState SSLConnectJob::GetLoadState() const {
211 switch (next_state_) { 216 switch (next_state_) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 connect_timing_.connect_start = socket_connect_timing.connect_start; 400 connect_timing_.connect_start = socket_connect_timing.connect_start;
396 connect_timing_.dns_start = socket_connect_timing.dns_start; 401 connect_timing_.dns_start = socket_connect_timing.dns_start;
397 connect_timing_.dns_end = socket_connect_timing.dns_end; 402 connect_timing_.dns_end = socket_connect_timing.dns_end;
398 } 403 }
399 404
400 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket( 405 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket(
401 transport_socket_handle_.Pass(), 406 transport_socket_handle_.Pass(),
402 params_->host_and_port(), 407 params_->host_and_port(),
403 params_->ssl_config(), 408 params_->ssl_config(),
404 context_); 409 context_);
410
411 if (!ssl_socket_->InSessionCache()) {
412 messenger_ = get_messenger_callback_.Run(ssl_socket_->GetSessionCacheKey());
413 }
wtc 2014/08/14 23:26:26 Nit: omit the curly braces.
mshelley 2014/08/15 16:53:06 Done.
414
405 return OK; 415 return OK;
406 } 416 }
407 417
408 int SSLConnectJob::DoCheckForResume() { 418 int SSLConnectJob::DoCheckForResume() {
409 next_state_ = STATE_SSL_CONNECT; 419 next_state_ = STATE_SSL_CONNECT;
410 if (!messenger_) 420
421 if (ssl_socket_->InSessionCache() || !messenger_)
wtc 2014/08/14 23:26:26 Remove the redundant ssl_socket_->InSessionCache()
mshelley 2014/08/15 16:53:06 Done.
411 return OK; 422 return OK;
412 423
413 // TODO(mshelley): Remove duplicate InSessionCache() calls.
414 if (messenger_->CanProceed(ssl_socket_.get())) { 424 if (messenger_->CanProceed(ssl_socket_.get())) {
415 if (!ssl_socket_->InSessionCache()) 425 messenger_->MonitorConnectionResult(ssl_socket_.get());
416 messenger_->MonitorConnectionResult(ssl_socket_.get()); 426 // The SSLConnectJob no longer needs access to the messenger after this
427 // point.
428 messenger_ = NULL;
wtc 2014/08/14 23:26:26 I suspect you set messenger_ to NULL because we wi
mshelley 2014/08/15 16:53:06 Yep -- I check whether the messenger_ is valid bef
417 return OK; 429 return OK;
418 } 430 }
431
419 messenger_->AddPendingSocket(ssl_socket_.get(), 432 messenger_->AddPendingSocket(ssl_socket_.get(),
420 base::Bind(&SSLConnectJob::ResumeSSLConnection, 433 base::Bind(&SSLConnectJob::ResumeSSLConnection,
421 weak_factory_.GetWeakPtr())); 434 weak_factory_.GetWeakPtr()));
wtc 2014/08/14 23:26:26 In this case, the right time to set messenger_ to
mshelley 2014/08/15 16:53:06 Probably, I'll add documentation.
435
422 return ERR_IO_PENDING; 436 return ERR_IO_PENDING;
423 } 437 }
424 438
425 int SSLConnectJob::DoSSLConnect() { 439 int SSLConnectJob::DoSSLConnect() {
426 next_state_ = STATE_SSL_CONNECT_COMPLETE; 440 next_state_ = STATE_SSL_CONNECT_COMPLETE;
427 441
428 connect_timing_.ssl_start = base::TimeTicks::Now(); 442 connect_timing_.ssl_start = base::TimeTicks::Now();
429 443
430 return ssl_socket_->Connect(io_callback_); 444 return ssl_socket_->Connect(io_callback_);
431 } 445 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 error_response_info_.cert_request_info = new SSLCertRequestInfo; 563 error_response_info_.cert_request_info = new SSLCertRequestInfo;
550 ssl_socket_->GetSSLCertRequestInfo( 564 ssl_socket_->GetSSLCertRequestInfo(
551 error_response_info_.cert_request_info.get()); 565 error_response_info_.cert_request_info.get());
552 } 566 }
553 567
554 return result; 568 return result;
555 } 569 }
556 570
557 void SSLConnectJob::ResumeSSLConnection() { 571 void SSLConnectJob::ResumeSSLConnection() {
558 DCHECK_EQ(next_state_, STATE_SSL_CONNECT); 572 DCHECK_EQ(next_state_, STATE_SSL_CONNECT);
573 messenger_ = NULL;
559 OnIOComplete(OK); 574 OnIOComplete(OK);
560 } 575 }
561 576
562 SSLConnectJob::State SSLConnectJob::GetInitialState( 577 SSLConnectJob::State SSLConnectJob::GetInitialState(
563 SSLSocketParams::ConnectionType connection_type) { 578 SSLSocketParams::ConnectionType connection_type) {
564 switch (connection_type) { 579 switch (connection_type) {
565 case SSLSocketParams::DIRECT: 580 case SSLSocketParams::DIRECT:
566 return STATE_TRANSPORT_CONNECT; 581 return STATE_TRANSPORT_CONNECT;
567 case SSLSocketParams::HTTP_PROXY: 582 case SSLSocketParams::HTTP_PROXY:
568 return STATE_TUNNEL_CONNECT; 583 return STATE_TUNNEL_CONNECT;
569 case SSLSocketParams::SOCKS_PROXY: 584 case SSLSocketParams::SOCKS_PROXY:
570 return STATE_SOCKS_CONNECT; 585 return STATE_SOCKS_CONNECT;
571 } 586 }
572 NOTREACHED(); 587 NOTREACHED();
573 return STATE_NONE; 588 return STATE_NONE;
574 } 589 }
575 590
576 int SSLConnectJob::ConnectInternal() { 591 int SSLConnectJob::ConnectInternal() {
577 next_state_ = GetInitialState(params_->GetConnectionType()); 592 next_state_ = GetInitialState(params_->GetConnectionType());
578 return DoLoop(OK); 593 return DoLoop(OK);
579 } 594 }
580 595
581 SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory( 596 SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory(
582 TransportClientSocketPool* transport_pool, 597 TransportClientSocketPool* transport_pool,
583 SOCKSClientSocketPool* socks_pool, 598 SOCKSClientSocketPool* socks_pool,
584 HttpProxyClientSocketPool* http_proxy_pool, 599 HttpProxyClientSocketPool* http_proxy_pool,
585 ClientSocketFactory* client_socket_factory, 600 ClientSocketFactory* client_socket_factory,
586 HostResolver* host_resolver, 601 HostResolver* host_resolver,
587 const SSLClientSocketContext& context, 602 const SSLClientSocketContext& context,
588 bool enable_ssl_connect_job_waiting, 603 SSLConnectJob::GetMessengerCallback get_messenger_callback,
589 NetLog* net_log) 604 NetLog* net_log)
590 : transport_pool_(transport_pool), 605 : transport_pool_(transport_pool),
591 socks_pool_(socks_pool), 606 socks_pool_(socks_pool),
592 http_proxy_pool_(http_proxy_pool), 607 http_proxy_pool_(http_proxy_pool),
593 client_socket_factory_(client_socket_factory), 608 client_socket_factory_(client_socket_factory),
594 host_resolver_(host_resolver), 609 host_resolver_(host_resolver),
595 context_(context), 610 context_(context),
596 enable_ssl_connect_job_waiting_(enable_ssl_connect_job_waiting), 611 get_messenger_callback_(get_messenger_callback),
597 net_log_(net_log), 612 net_log_(net_log) {
598 messenger_map_(new MessengerMap) {
599 base::TimeDelta max_transport_timeout = base::TimeDelta(); 613 base::TimeDelta max_transport_timeout = base::TimeDelta();
600 base::TimeDelta pool_timeout; 614 base::TimeDelta pool_timeout;
601 if (transport_pool_) 615 if (transport_pool_)
602 max_transport_timeout = transport_pool_->ConnectionTimeout(); 616 max_transport_timeout = transport_pool_->ConnectionTimeout();
603 if (socks_pool_) { 617 if (socks_pool_) {
604 pool_timeout = socks_pool_->ConnectionTimeout(); 618 pool_timeout = socks_pool_->ConnectionTimeout();
605 if (pool_timeout > max_transport_timeout) 619 if (pool_timeout > max_transport_timeout)
606 max_transport_timeout = pool_timeout; 620 max_transport_timeout = pool_timeout;
607 } 621 }
608 if (http_proxy_pool_) { 622 if (http_proxy_pool_) {
609 pool_timeout = http_proxy_pool_->ConnectionTimeout(); 623 pool_timeout = http_proxy_pool_->ConnectionTimeout();
610 if (pool_timeout > max_transport_timeout) 624 if (pool_timeout > max_transport_timeout)
611 max_transport_timeout = pool_timeout; 625 max_transport_timeout = pool_timeout;
612 } 626 }
613 timeout_ = max_transport_timeout + 627 timeout_ = max_transport_timeout +
614 base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds); 628 base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds);
615 } 629 }
616 630
617 SSLClientSocketPool::SSLConnectJobFactory::~SSLConnectJobFactory() { 631 SSLClientSocketPool::SSLConnectJobFactory::~SSLConnectJobFactory() {
618 STLDeleteValues(messenger_map_.get());
619 } 632 }
620 633
621 SSLClientSocketPool::SSLClientSocketPool( 634 SSLClientSocketPool::SSLClientSocketPool(
622 int max_sockets, 635 int max_sockets,
623 int max_sockets_per_group, 636 int max_sockets_per_group,
624 ClientSocketPoolHistograms* histograms, 637 ClientSocketPoolHistograms* histograms,
625 HostResolver* host_resolver, 638 HostResolver* host_resolver,
626 CertVerifier* cert_verifier, 639 CertVerifier* cert_verifier,
627 ChannelIDService* channel_id_service, 640 ChannelIDService* channel_id_service,
628 TransportSecurityState* transport_security_state, 641 TransportSecurityState* transport_security_state,
(...skipping 19 matching lines...) Expand all
648 transport_pool, 661 transport_pool,
649 socks_pool, 662 socks_pool,
650 http_proxy_pool, 663 http_proxy_pool,
651 client_socket_factory, 664 client_socket_factory,
652 host_resolver, 665 host_resolver,
653 SSLClientSocketContext(cert_verifier, 666 SSLClientSocketContext(cert_verifier,
654 channel_id_service, 667 channel_id_service,
655 transport_security_state, 668 transport_security_state,
656 cert_transparency_verifier, 669 cert_transparency_verifier,
657 ssl_session_cache_shard), 670 ssl_session_cache_shard),
658 enable_ssl_connect_job_waiting, 671 base::Bind(
672 &SSLClientSocketPool::GetOrCreateSSLConnectJobMessenger,
673 base::Unretained(this)),
wtc 2014/08/14 23:26:26 Please confirm that we don't need to use a weak po
mshelley 2014/08/15 16:53:06 We do not -- the pool owns the SSLConnectJobs, the
659 net_log)), 674 net_log)),
660 ssl_config_service_(ssl_config_service) { 675 ssl_config_service_(ssl_config_service),
676 enable_ssl_connect_job_waiting_(enable_ssl_connect_job_waiting) {
661 if (ssl_config_service_.get()) 677 if (ssl_config_service_.get())
662 ssl_config_service_->AddObserver(this); 678 ssl_config_service_->AddObserver(this);
663 if (transport_pool_) 679 if (transport_pool_)
664 base_.AddLowerLayeredPool(transport_pool_); 680 base_.AddLowerLayeredPool(transport_pool_);
665 if (socks_pool_) 681 if (socks_pool_)
666 base_.AddLowerLayeredPool(socks_pool_); 682 base_.AddLowerLayeredPool(socks_pool_);
667 if (http_proxy_pool_) 683 if (http_proxy_pool_)
668 base_.AddLowerLayeredPool(http_proxy_pool_); 684 base_.AddLowerLayeredPool(http_proxy_pool_);
669 } 685 }
670 686
671 SSLClientSocketPool::~SSLClientSocketPool() { 687 SSLClientSocketPool::~SSLClientSocketPool() {
688 STLDeleteContainerPairSecondPointers(messenger_map_.begin(),
689 messenger_map_.end());
672 if (ssl_config_service_.get()) 690 if (ssl_config_service_.get())
673 ssl_config_service_->RemoveObserver(this); 691 ssl_config_service_->RemoveObserver(this);
674 } 692 }
675 693
676 scoped_ptr<ConnectJob> 694 scoped_ptr<ConnectJob> SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob(
677 SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob(
678 const std::string& group_name, 695 const std::string& group_name,
679 const PoolBase::Request& request, 696 const PoolBase::Request& request,
680 ConnectJob::Delegate* delegate) const { 697 ConnectJob::Delegate* delegate) const {
681 SSLConnectJobMessenger* messenger = NULL;
682 if (enable_ssl_connect_job_waiting_) {
683 std::string cache_key = SSLClientSocket::CreateSessionCacheKey(
684 request.params()->host_and_port(), context_.ssl_session_cache_shard);
685 MessengerMap::const_iterator it = messenger_map_->find(cache_key);
686 if (it == messenger_map_->end()) {
687 std::pair<MessengerMap::iterator, bool> iter = messenger_map_->insert(
688 MessengerMap::value_type(cache_key, new SSLConnectJobMessenger()));
689 it = iter.first;
690 }
691 messenger = it->second;
692 }
693
694 return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name, 698 return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name,
695 request.priority(), 699 request.priority(),
696 request.params(), 700 request.params(),
697 ConnectionTimeout(), 701 ConnectionTimeout(),
698 transport_pool_, 702 transport_pool_,
699 socks_pool_, 703 socks_pool_,
700 http_proxy_pool_, 704 http_proxy_pool_,
701 client_socket_factory_, 705 client_socket_factory_,
702 host_resolver_, 706 host_resolver_,
703 context_, 707 context_,
704 messenger, 708 get_messenger_callback_,
705 delegate, 709 delegate,
706 net_log_)); 710 net_log_));
707 } 711 }
708 712
709 base::TimeDelta 713 base::TimeDelta SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout()
710 SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() const { 714 const {
711 return timeout_; 715 return timeout_;
712 } 716 }
713 717
714 int SSLClientSocketPool::RequestSocket(const std::string& group_name, 718 int SSLClientSocketPool::RequestSocket(const std::string& group_name,
715 const void* socket_params, 719 const void* socket_params,
716 RequestPriority priority, 720 RequestPriority priority,
717 ClientSocketHandle* handle, 721 ClientSocketHandle* handle,
718 const CompletionCallback& callback, 722 const CompletionCallback& callback,
719 const BoundNetLog& net_log) { 723 const BoundNetLog& net_log) {
720 const scoped_refptr<SSLSocketParams>* casted_socket_params = 724 const scoped_refptr<SSLSocketParams>* casted_socket_params =
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 HigherLayeredPool* higher_pool) { 819 HigherLayeredPool* higher_pool) {
816 base_.RemoveHigherLayeredPool(higher_pool); 820 base_.RemoveHigherLayeredPool(higher_pool);
817 } 821 }
818 822
819 bool SSLClientSocketPool::CloseOneIdleConnection() { 823 bool SSLClientSocketPool::CloseOneIdleConnection() {
820 if (base_.CloseOneIdleSocket()) 824 if (base_.CloseOneIdleSocket())
821 return true; 825 return true;
822 return base_.CloseOneIdleConnectionInHigherLayeredPool(); 826 return base_.CloseOneIdleConnectionInHigherLayeredPool();
823 } 827 }
824 828
829 SSLConnectJobMessenger* SSLClientSocketPool::GetOrCreateSSLConnectJobMessenger(
830 const std::string& cache_key) {
831 if (!enable_ssl_connect_job_waiting_)
832 return NULL;
833 MessengerMap::const_iterator it = messenger_map_.find(cache_key);
834 if (it == messenger_map_.end()) {
835 std::pair<MessengerMap::iterator, bool> iter =
836 messenger_map_.insert(MessengerMap::value_type(
837 cache_key,
838 new SSLConnectJobMessenger(
839 base::Bind(&SSLClientSocketPool::DeleteSSLConnectJobMessenger,
840 base::Unretained(this),
wtc 2014/08/14 23:26:26 Please confirm that we don't need a weak pointer h
mshelley 2014/08/15 16:53:06 We do not, the pool also owns the SSLConnectJobMes
841 cache_key))));
842 it = iter.first;
843 }
844 return it->second;
845 }
846
847 void SSLClientSocketPool::DeleteSSLConnectJobMessenger(
848 const std::string& cache_key) {
849 MessengerMap::iterator it = messenger_map_.find(cache_key);
850 CHECK(it != messenger_map_.end());
wtc 2014/08/14 23:26:26 You can also assert CHECK_EQ(this, it->second).
mshelley 2014/08/15 16:53:06 I'm not sure if I understand how that would work -
wtc 2014/08/15 18:48:29 Ah, you're right. I thought |this| was a pointer t
851 delete it->second;
852 messenger_map_.erase(it);
853 }
854
825 void SSLClientSocketPool::OnSSLConfigChanged() { 855 void SSLClientSocketPool::OnSSLConfigChanged() {
826 FlushWithError(ERR_NETWORK_CHANGED); 856 FlushWithError(ERR_NETWORK_CHANGED);
827 } 857 }
828 858
829 } // namespace net 859 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698