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
3 // found in the LICENSE file.
5 #include "net/socket/ssl_client_socket_pool.h"
8 #include "base/bind_helpers.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h"
11 #include "base/metrics/sparse_histogram.h"
12 #include "base/stl_util.h"
13 #include "base/values.h"
14 #include "net/base/host_port_pair.h"
15 #include "net/base/net_errors.h"
16 #include "net/http/http_proxy_client_socket.h"
17 #include "net/http/http_proxy_client_socket_pool.h"
18 #include "net/socket/client_socket_factory.h"
19 #include "net/socket/client_socket_handle.h"
20 #include "net/socket/socks_client_socket_pool.h"
21 #include "net/socket/ssl_client_socket.h"
22 #include "net/socket/transport_client_socket_pool.h"
23 #include "net/ssl/ssl_cert_request_info.h"
24 #include "net/ssl/ssl_connection_status_flags.h"
25 #include "net/ssl/ssl_info.h"
29 SSLSocketParams::SSLSocketParams(
30 const scoped_refptr
<TransportSocketParams
>& direct_params
,
31 const scoped_refptr
<SOCKSSocketParams
>& socks_proxy_params
,
32 const scoped_refptr
<HttpProxySocketParams
>& http_proxy_params
,
33 const HostPortPair
& host_and_port
,
34 const SSLConfig
& ssl_config
,
35 PrivacyMode privacy_mode
,
37 bool force_spdy_over_ssl
,
38 bool want_spdy_over_npn
)
39 : direct_params_(direct_params
),
40 socks_proxy_params_(socks_proxy_params
),
41 http_proxy_params_(http_proxy_params
),
42 host_and_port_(host_and_port
),
43 ssl_config_(ssl_config
),
44 privacy_mode_(privacy_mode
),
45 load_flags_(load_flags
),
46 force_spdy_over_ssl_(force_spdy_over_ssl
),
47 want_spdy_over_npn_(want_spdy_over_npn
),
48 ignore_limits_(false) {
49 if (direct_params_
.get()) {
50 DCHECK(!socks_proxy_params_
.get());
51 DCHECK(!http_proxy_params_
.get());
52 ignore_limits_
= direct_params_
->ignore_limits();
53 } else if (socks_proxy_params_
.get()) {
54 DCHECK(!http_proxy_params_
.get());
55 ignore_limits_
= socks_proxy_params_
->ignore_limits();
57 DCHECK(http_proxy_params_
.get());
58 ignore_limits_
= http_proxy_params_
->ignore_limits();
62 SSLSocketParams::~SSLSocketParams() {}
64 SSLSocketParams::ConnectionType
SSLSocketParams::GetConnectionType() const {
65 if (direct_params_
.get()) {
66 DCHECK(!socks_proxy_params_
.get());
67 DCHECK(!http_proxy_params_
.get());
71 if (socks_proxy_params_
.get()) {
72 DCHECK(!http_proxy_params_
.get());
76 DCHECK(http_proxy_params_
.get());
80 const scoped_refptr
<TransportSocketParams
>&
81 SSLSocketParams::GetDirectConnectionParams() const {
82 DCHECK_EQ(GetConnectionType(), DIRECT
);
83 return direct_params_
;
86 const scoped_refptr
<SOCKSSocketParams
>&
87 SSLSocketParams::GetSocksProxyConnectionParams() const {
88 DCHECK_EQ(GetConnectionType(), SOCKS_PROXY
);
89 return socks_proxy_params_
;
92 const scoped_refptr
<HttpProxySocketParams
>&
93 SSLSocketParams::GetHttpProxyConnectionParams() const {
94 DCHECK_EQ(GetConnectionType(), HTTP_PROXY
);
95 return http_proxy_params_
;
98 SSLConnectJobMessenger::SocketAndCallback::SocketAndCallback(
99 SSLClientSocket
* ssl_socket
,
100 const base::Closure
& job_resumption_callback
)
101 : socket(ssl_socket
), callback(job_resumption_callback
) {
104 SSLConnectJobMessenger::SocketAndCallback::~SocketAndCallback() {
107 SSLConnectJobMessenger::SSLConnectJobMessenger(
108 const base::Closure
& messenger_finished_callback
)
109 : messenger_finished_callback_(messenger_finished_callback
),
110 weak_factory_(this) {
113 SSLConnectJobMessenger::~SSLConnectJobMessenger() {
116 void SSLConnectJobMessenger::RemovePendingSocket(SSLClientSocket
* ssl_socket
) {
117 // Sockets do not need to be removed from connecting_sockets_ because
118 // OnSSLHandshakeCompleted will do this.
119 for (SSLPendingSocketsAndCallbacks::iterator it
=
120 pending_sockets_and_callbacks_
.begin();
121 it
!= pending_sockets_and_callbacks_
.end();
123 if (it
->socket
== ssl_socket
) {
124 pending_sockets_and_callbacks_
.erase(it
);
130 bool SSLConnectJobMessenger::CanProceed(SSLClientSocket
* ssl_socket
) {
131 // If there are no connecting sockets, allow the connection to proceed.
132 return connecting_sockets_
.empty();
135 void SSLConnectJobMessenger::MonitorConnectionResult(
136 SSLClientSocket
* ssl_socket
) {
137 connecting_sockets_
.push_back(ssl_socket
);
138 ssl_socket
->SetHandshakeCompletionCallback(
139 base::Bind(&SSLConnectJobMessenger::OnSSLHandshakeCompleted
,
140 weak_factory_
.GetWeakPtr()));
143 void SSLConnectJobMessenger::AddPendingSocket(SSLClientSocket
* ssl_socket
,
144 const base::Closure
& callback
) {
145 DCHECK(!connecting_sockets_
.empty());
146 pending_sockets_and_callbacks_
.push_back(
147 SocketAndCallback(ssl_socket
, callback
));
150 void SSLConnectJobMessenger::OnSSLHandshakeCompleted() {
151 connecting_sockets_
.clear();
152 SSLPendingSocketsAndCallbacks temp_list
;
153 temp_list
.swap(pending_sockets_and_callbacks_
);
154 base::Closure messenger_finished_callback
= messenger_finished_callback_
;
155 messenger_finished_callback
.Run();
156 RunAllCallbacks(temp_list
);
159 void SSLConnectJobMessenger::RunAllCallbacks(
160 const SSLPendingSocketsAndCallbacks
& pending_sockets_and_callbacks
) {
161 for (std::vector
<SocketAndCallback
>::const_iterator it
=
162 pending_sockets_and_callbacks
.begin();
163 it
!= pending_sockets_and_callbacks
.end();
169 // Timeout for the SSL handshake portion of the connect.
170 static const int kSSLHandshakeTimeoutInSeconds
= 30;
172 SSLConnectJob::SSLConnectJob(const std::string
& group_name
,
173 RequestPriority priority
,
174 const scoped_refptr
<SSLSocketParams
>& params
,
175 const base::TimeDelta
& timeout_duration
,
176 TransportClientSocketPool
* transport_pool
,
177 SOCKSClientSocketPool
* socks_pool
,
178 HttpProxyClientSocketPool
* http_proxy_pool
,
179 ClientSocketFactory
* client_socket_factory
,
180 HostResolver
* host_resolver
,
181 const SSLClientSocketContext
& context
,
182 const GetMessengerCallback
& get_messenger_callback
,
185 : ConnectJob(group_name
,
189 BoundNetLog::Make(net_log
, NetLog::SOURCE_CONNECT_JOB
)),
191 transport_pool_(transport_pool
),
192 socks_pool_(socks_pool
),
193 http_proxy_pool_(http_proxy_pool
),
194 client_socket_factory_(client_socket_factory
),
195 host_resolver_(host_resolver
),
196 context_(context
.cert_verifier
,
197 context
.channel_id_service
,
198 context
.transport_security_state
,
199 context
.cert_transparency_verifier
,
200 (params
->privacy_mode() == PRIVACY_MODE_ENABLED
201 ? "pm/" + context
.ssl_session_cache_shard
202 : context
.ssl_session_cache_shard
)),
204 base::Bind(&SSLConnectJob::OnIOComplete
, base::Unretained(this))),
206 get_messenger_callback_(get_messenger_callback
),
207 weak_factory_(this) {
210 SSLConnectJob::~SSLConnectJob() {
211 if (ssl_socket_
.get() && messenger_
)
212 messenger_
->RemovePendingSocket(ssl_socket_
.get());
215 LoadState
SSLConnectJob::GetLoadState() const {
216 switch (next_state_
) {
217 case STATE_TUNNEL_CONNECT_COMPLETE
:
218 if (transport_socket_handle_
->socket())
219 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL
;
220 // else, fall through.
221 case STATE_TRANSPORT_CONNECT
:
222 case STATE_TRANSPORT_CONNECT_COMPLETE
:
223 case STATE_SOCKS_CONNECT
:
224 case STATE_SOCKS_CONNECT_COMPLETE
:
225 case STATE_TUNNEL_CONNECT
:
226 return transport_socket_handle_
->GetLoadState();
227 case STATE_CREATE_SSL_SOCKET
:
228 case STATE_CHECK_FOR_RESUME
:
229 case STATE_SSL_CONNECT
:
230 case STATE_SSL_CONNECT_COMPLETE
:
231 return LOAD_STATE_SSL_HANDSHAKE
;
234 return LOAD_STATE_IDLE
;
238 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle
* handle
) {
239 // Headers in |error_response_info_| indicate a proxy tunnel setup
240 // problem. See DoTunnelConnectComplete.
241 if (error_response_info_
.headers
.get()) {
242 handle
->set_pending_http_proxy_connection(
243 transport_socket_handle_
.release());
245 handle
->set_ssl_error_response_info(error_response_info_
);
246 if (!connect_timing_
.ssl_start
.is_null())
247 handle
->set_is_ssl_error(true);
250 void SSLConnectJob::OnIOComplete(int result
) {
251 int rv
= DoLoop(result
);
252 if (rv
!= ERR_IO_PENDING
)
253 NotifyDelegateOfCompletion(rv
); // Deletes |this|.
256 int SSLConnectJob::DoLoop(int result
) {
257 DCHECK_NE(next_state_
, STATE_NONE
);
261 State state
= next_state_
;
262 next_state_
= STATE_NONE
;
264 case STATE_TRANSPORT_CONNECT
:
266 rv
= DoTransportConnect();
268 case STATE_TRANSPORT_CONNECT_COMPLETE
:
269 rv
= DoTransportConnectComplete(rv
);
271 case STATE_SOCKS_CONNECT
:
273 rv
= DoSOCKSConnect();
275 case STATE_SOCKS_CONNECT_COMPLETE
:
276 rv
= DoSOCKSConnectComplete(rv
);
278 case STATE_TUNNEL_CONNECT
:
280 rv
= DoTunnelConnect();
282 case STATE_TUNNEL_CONNECT_COMPLETE
:
283 rv
= DoTunnelConnectComplete(rv
);
285 case STATE_CREATE_SSL_SOCKET
:
286 rv
= DoCreateSSLSocket();
288 case STATE_CHECK_FOR_RESUME
:
289 rv
= DoCheckForResume();
291 case STATE_SSL_CONNECT
:
295 case STATE_SSL_CONNECT_COMPLETE
:
296 rv
= DoSSLConnectComplete(rv
);
299 NOTREACHED() << "bad state";
303 } while (rv
!= ERR_IO_PENDING
&& next_state_
!= STATE_NONE
);
308 int SSLConnectJob::DoTransportConnect() {
309 DCHECK(transport_pool_
);
311 next_state_
= STATE_TRANSPORT_CONNECT_COMPLETE
;
312 transport_socket_handle_
.reset(new ClientSocketHandle());
313 scoped_refptr
<TransportSocketParams
> direct_params
=
314 params_
->GetDirectConnectionParams();
315 return transport_socket_handle_
->Init(group_name(),
323 int SSLConnectJob::DoTransportConnectComplete(int result
) {
325 next_state_
= STATE_CREATE_SSL_SOCKET
;
330 int SSLConnectJob::DoSOCKSConnect() {
332 next_state_
= STATE_SOCKS_CONNECT_COMPLETE
;
333 transport_socket_handle_
.reset(new ClientSocketHandle());
334 scoped_refptr
<SOCKSSocketParams
> socks_proxy_params
=
335 params_
->GetSocksProxyConnectionParams();
336 return transport_socket_handle_
->Init(group_name(),
344 int SSLConnectJob::DoSOCKSConnectComplete(int result
) {
346 next_state_
= STATE_CREATE_SSL_SOCKET
;
351 int SSLConnectJob::DoTunnelConnect() {
352 DCHECK(http_proxy_pool_
);
353 next_state_
= STATE_TUNNEL_CONNECT_COMPLETE
;
355 transport_socket_handle_
.reset(new ClientSocketHandle());
356 scoped_refptr
<HttpProxySocketParams
> http_proxy_params
=
357 params_
->GetHttpProxyConnectionParams();
358 return transport_socket_handle_
->Init(group_name(),
366 int SSLConnectJob::DoTunnelConnectComplete(int result
) {
367 // Extract the information needed to prompt for appropriate proxy
368 // authentication so that when ClientSocketPoolBaseHelper calls
369 // |GetAdditionalErrorState|, we can easily set the state.
370 if (result
== ERR_SSL_CLIENT_AUTH_CERT_NEEDED
) {
371 error_response_info_
= transport_socket_handle_
->ssl_error_response_info();
372 } else if (result
== ERR_PROXY_AUTH_REQUESTED
||
373 result
== ERR_HTTPS_PROXY_TUNNEL_RESPONSE
) {
374 StreamSocket
* socket
= transport_socket_handle_
->socket();
375 HttpProxyClientSocket
* tunnel_socket
=
376 static_cast<HttpProxyClientSocket
*>(socket
);
377 error_response_info_
= *tunnel_socket
->GetConnectResponseInfo();
381 next_state_
= STATE_CREATE_SSL_SOCKET
;
385 int SSLConnectJob::DoCreateSSLSocket() {
386 next_state_
= STATE_CHECK_FOR_RESUME
;
388 // Reset the timeout to just the time allowed for the SSL handshake.
389 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds
));
391 // If the handle has a fresh socket, get its connect start and DNS times.
392 // This should always be the case.
393 const LoadTimingInfo::ConnectTiming
& socket_connect_timing
=
394 transport_socket_handle_
->connect_timing();
395 if (!transport_socket_handle_
->is_reused() &&
396 !socket_connect_timing
.connect_start
.is_null()) {
397 // Overwriting |connect_start| serves two purposes - it adjusts timing so
398 // |connect_start| doesn't include dns times, and it adjusts the time so
399 // as not to include time spent waiting for an idle socket.
400 connect_timing_
.connect_start
= socket_connect_timing
.connect_start
;
401 connect_timing_
.dns_start
= socket_connect_timing
.dns_start
;
402 connect_timing_
.dns_end
= socket_connect_timing
.dns_end
;
405 ssl_socket_
= client_socket_factory_
->CreateSSLClientSocket(
406 transport_socket_handle_
.Pass(),
407 params_
->host_and_port(),
408 params_
->ssl_config(),
411 if (!ssl_socket_
->InSessionCache())
412 messenger_
= get_messenger_callback_
.Run(ssl_socket_
->GetSessionCacheKey());
417 int SSLConnectJob::DoCheckForResume() {
418 next_state_
= STATE_SSL_CONNECT
;
423 if (messenger_
->CanProceed(ssl_socket_
.get())) {
424 messenger_
->MonitorConnectionResult(ssl_socket_
.get());
425 // The SSLConnectJob no longer needs access to the messenger after this
431 messenger_
->AddPendingSocket(ssl_socket_
.get(),
432 base::Bind(&SSLConnectJob::ResumeSSLConnection
,
433 weak_factory_
.GetWeakPtr()));
435 return ERR_IO_PENDING
;
438 int SSLConnectJob::DoSSLConnect() {
439 next_state_
= STATE_SSL_CONNECT_COMPLETE
;
441 connect_timing_
.ssl_start
= base::TimeTicks::Now();
443 return ssl_socket_
->Connect(io_callback_
);
446 int SSLConnectJob::DoSSLConnectComplete(int result
) {
447 connect_timing_
.ssl_end
= base::TimeTicks::Now();
449 SSLClientSocket::NextProtoStatus status
=
450 SSLClientSocket::kNextProtoUnsupported
;
452 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket
453 // that hasn't had SSL_ImportFD called on it. If we get a certificate error
454 // here, then we know that we called SSL_ImportFD.
455 if (result
== OK
|| IsCertificateError(result
)) {
456 status
= ssl_socket_
->GetNextProto(&proto
);
457 ssl_socket_
->RecordNegotiationExtension();
460 // If we want spdy over npn, make sure it succeeded.
461 if (status
== SSLClientSocket::kNextProtoNegotiated
) {
462 ssl_socket_
->set_was_npn_negotiated(true);
463 NextProto protocol_negotiated
=
464 SSLClientSocket::NextProtoFromString(proto
);
465 ssl_socket_
->set_protocol_negotiated(protocol_negotiated
);
466 // If we negotiated a SPDY version, it must have been present in
467 // SSLConfig::next_protos.
468 // TODO(mbelshe): Verify this.
469 if (protocol_negotiated
>= kProtoSPDYMinimumVersion
&&
470 protocol_negotiated
<= kProtoSPDYMaximumVersion
) {
471 ssl_socket_
->set_was_spdy_negotiated(true);
474 if (params_
->want_spdy_over_npn() && !ssl_socket_
->was_spdy_negotiated())
475 return ERR_NPN_NEGOTIATION_FAILED
;
477 // Spdy might be turned on by default, or it might be over npn.
478 bool using_spdy
= params_
->force_spdy_over_ssl() ||
479 params_
->want_spdy_over_npn();
482 ssl_socket_
->IgnoreCertError(result
, params_
->load_flags())) {
483 DCHECK(!connect_timing_
.ssl_start
.is_null());
484 base::TimeDelta connect_duration
=
485 connect_timing_
.ssl_end
- connect_timing_
.ssl_start
;
487 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SpdyConnectionLatency_2",
489 base::TimeDelta::FromMilliseconds(1),
490 base::TimeDelta::FromMinutes(1),
494 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_2",
496 base::TimeDelta::FromMilliseconds(1),
497 base::TimeDelta::FromMinutes(1),
501 ssl_socket_
->GetSSLInfo(&ssl_info
);
503 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSL_CipherSuite",
504 SSLConnectionStatusToCipherSuite(
505 ssl_info
.connection_status
));
507 UMA_HISTOGRAM_BOOLEAN(
508 "Net.RenegotiationExtensionSupported",
509 (ssl_info
.connection_status
&
510 SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION
) == 0);
512 if (ssl_info
.handshake_type
== SSLInfo::HANDSHAKE_RESUME
) {
513 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Resume_Handshake",
515 base::TimeDelta::FromMilliseconds(1),
516 base::TimeDelta::FromMinutes(1),
518 } else if (ssl_info
.handshake_type
== SSLInfo::HANDSHAKE_FULL
) {
519 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Full_Handshake",
521 base::TimeDelta::FromMilliseconds(1),
522 base::TimeDelta::FromMinutes(1),
526 const std::string
& host
= params_
->host_and_port().host();
528 host
== "google.com" ||
529 (host
.size() > 11 && host
.rfind(".google.com") == host
.size() - 11);
531 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2",
533 base::TimeDelta::FromMilliseconds(1),
534 base::TimeDelta::FromMinutes(1),
536 if (ssl_info
.handshake_type
== SSLInfo::HANDSHAKE_RESUME
) {
537 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_"
540 base::TimeDelta::FromMilliseconds(1),
541 base::TimeDelta::FromMinutes(1),
543 } else if (ssl_info
.handshake_type
== SSLInfo::HANDSHAKE_FULL
) {
544 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_"
547 base::TimeDelta::FromMilliseconds(1),
548 base::TimeDelta::FromMinutes(1),
554 if (result
== OK
|| IsCertificateError(result
)) {
555 SetSocket(ssl_socket_
.Pass());
556 } else if (result
== ERR_SSL_CLIENT_AUTH_CERT_NEEDED
) {
557 error_response_info_
.cert_request_info
= new SSLCertRequestInfo
;
558 ssl_socket_
->GetSSLCertRequestInfo(
559 error_response_info_
.cert_request_info
.get());
565 void SSLConnectJob::ResumeSSLConnection() {
566 DCHECK_EQ(next_state_
, STATE_SSL_CONNECT
);
571 SSLConnectJob::State
SSLConnectJob::GetInitialState(
572 SSLSocketParams::ConnectionType connection_type
) {
573 switch (connection_type
) {
574 case SSLSocketParams::DIRECT
:
575 return STATE_TRANSPORT_CONNECT
;
576 case SSLSocketParams::HTTP_PROXY
:
577 return STATE_TUNNEL_CONNECT
;
578 case SSLSocketParams::SOCKS_PROXY
:
579 return STATE_SOCKS_CONNECT
;
585 int SSLConnectJob::ConnectInternal() {
586 next_state_
= GetInitialState(params_
->GetConnectionType());
590 SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory(
591 TransportClientSocketPool
* transport_pool
,
592 SOCKSClientSocketPool
* socks_pool
,
593 HttpProxyClientSocketPool
* http_proxy_pool
,
594 ClientSocketFactory
* client_socket_factory
,
595 HostResolver
* host_resolver
,
596 const SSLClientSocketContext
& context
,
597 const SSLConnectJob::GetMessengerCallback
& get_messenger_callback
,
599 : transport_pool_(transport_pool
),
600 socks_pool_(socks_pool
),
601 http_proxy_pool_(http_proxy_pool
),
602 client_socket_factory_(client_socket_factory
),
603 host_resolver_(host_resolver
),
605 get_messenger_callback_(get_messenger_callback
),
607 base::TimeDelta max_transport_timeout
= base::TimeDelta();
608 base::TimeDelta pool_timeout
;
610 max_transport_timeout
= transport_pool_
->ConnectionTimeout();
612 pool_timeout
= socks_pool_
->ConnectionTimeout();
613 if (pool_timeout
> max_transport_timeout
)
614 max_transport_timeout
= pool_timeout
;
616 if (http_proxy_pool_
) {
617 pool_timeout
= http_proxy_pool_
->ConnectionTimeout();
618 if (pool_timeout
> max_transport_timeout
)
619 max_transport_timeout
= pool_timeout
;
621 timeout_
= max_transport_timeout
+
622 base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds
);
625 SSLClientSocketPool::SSLConnectJobFactory::~SSLConnectJobFactory() {
628 SSLClientSocketPool::SSLClientSocketPool(
630 int max_sockets_per_group
,
631 ClientSocketPoolHistograms
* histograms
,
632 HostResolver
* host_resolver
,
633 CertVerifier
* cert_verifier
,
634 ChannelIDService
* channel_id_service
,
635 TransportSecurityState
* transport_security_state
,
636 CTVerifier
* cert_transparency_verifier
,
637 const std::string
& ssl_session_cache_shard
,
638 ClientSocketFactory
* client_socket_factory
,
639 TransportClientSocketPool
* transport_pool
,
640 SOCKSClientSocketPool
* socks_pool
,
641 HttpProxyClientSocketPool
* http_proxy_pool
,
642 SSLConfigService
* ssl_config_service
,
643 bool enable_ssl_connect_job_waiting
,
645 : transport_pool_(transport_pool
),
646 socks_pool_(socks_pool
),
647 http_proxy_pool_(http_proxy_pool
),
650 max_sockets_per_group
,
652 ClientSocketPool::unused_idle_socket_timeout(),
653 ClientSocketPool::used_idle_socket_timeout(),
654 new SSLConnectJobFactory(
658 client_socket_factory
,
660 SSLClientSocketContext(cert_verifier
,
662 transport_security_state
,
663 cert_transparency_verifier
,
664 ssl_session_cache_shard
),
666 &SSLClientSocketPool::GetOrCreateSSLConnectJobMessenger
,
667 base::Unretained(this)),
669 ssl_config_service_(ssl_config_service
),
670 enable_ssl_connect_job_waiting_(enable_ssl_connect_job_waiting
) {
671 if (ssl_config_service_
.get())
672 ssl_config_service_
->AddObserver(this);
674 base_
.AddLowerLayeredPool(transport_pool_
);
676 base_
.AddLowerLayeredPool(socks_pool_
);
677 if (http_proxy_pool_
)
678 base_
.AddLowerLayeredPool(http_proxy_pool_
);
681 SSLClientSocketPool::~SSLClientSocketPool() {
682 STLDeleteContainerPairSecondPointers(messenger_map_
.begin(),
683 messenger_map_
.end());
684 if (ssl_config_service_
.get())
685 ssl_config_service_
->RemoveObserver(this);
688 scoped_ptr
<ConnectJob
> SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob(
689 const std::string
& group_name
,
690 const PoolBase::Request
& request
,
691 ConnectJob::Delegate
* delegate
) const {
692 return scoped_ptr
<ConnectJob
>(new SSLConnectJob(group_name
,
699 client_socket_factory_
,
702 get_messenger_callback_
,
707 base::TimeDelta
SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout()
712 int SSLClientSocketPool::RequestSocket(const std::string
& group_name
,
713 const void* socket_params
,
714 RequestPriority priority
,
715 ClientSocketHandle
* handle
,
716 const CompletionCallback
& callback
,
717 const BoundNetLog
& net_log
) {
718 const scoped_refptr
<SSLSocketParams
>* casted_socket_params
=
719 static_cast<const scoped_refptr
<SSLSocketParams
>*>(socket_params
);
721 return base_
.RequestSocket(group_name
, *casted_socket_params
, priority
,
722 handle
, callback
, net_log
);
725 void SSLClientSocketPool::RequestSockets(
726 const std::string
& group_name
,
729 const BoundNetLog
& net_log
) {
730 const scoped_refptr
<SSLSocketParams
>* casted_params
=
731 static_cast<const scoped_refptr
<SSLSocketParams
>*>(params
);
733 base_
.RequestSockets(group_name
, *casted_params
, num_sockets
, net_log
);
736 void SSLClientSocketPool::CancelRequest(const std::string
& group_name
,
737 ClientSocketHandle
* handle
) {
738 base_
.CancelRequest(group_name
, handle
);
741 void SSLClientSocketPool::ReleaseSocket(const std::string
& group_name
,
742 scoped_ptr
<StreamSocket
> socket
,
744 base_
.ReleaseSocket(group_name
, socket
.Pass(), id
);
747 void SSLClientSocketPool::FlushWithError(int error
) {
748 base_
.FlushWithError(error
);
751 void SSLClientSocketPool::CloseIdleSockets() {
752 base_
.CloseIdleSockets();
755 int SSLClientSocketPool::IdleSocketCount() const {
756 return base_
.idle_socket_count();
759 int SSLClientSocketPool::IdleSocketCountInGroup(
760 const std::string
& group_name
) const {
761 return base_
.IdleSocketCountInGroup(group_name
);
764 LoadState
SSLClientSocketPool::GetLoadState(
765 const std::string
& group_name
, const ClientSocketHandle
* handle
) const {
766 return base_
.GetLoadState(group_name
, handle
);
769 base::DictionaryValue
* SSLClientSocketPool::GetInfoAsValue(
770 const std::string
& name
,
771 const std::string
& type
,
772 bool include_nested_pools
) const {
773 base::DictionaryValue
* dict
= base_
.GetInfoAsValue(name
, type
);
774 if (include_nested_pools
) {
775 base::ListValue
* list
= new base::ListValue();
776 if (transport_pool_
) {
777 list
->Append(transport_pool_
->GetInfoAsValue("transport_socket_pool",
778 "transport_socket_pool",
782 list
->Append(socks_pool_
->GetInfoAsValue("socks_pool",
786 if (http_proxy_pool_
) {
787 list
->Append(http_proxy_pool_
->GetInfoAsValue("http_proxy_pool",
791 dict
->Set("nested_pools", list
);
796 base::TimeDelta
SSLClientSocketPool::ConnectionTimeout() const {
797 return base_
.ConnectionTimeout();
800 ClientSocketPoolHistograms
* SSLClientSocketPool::histograms() const {
801 return base_
.histograms();
804 bool SSLClientSocketPool::IsStalled() const {
805 return base_
.IsStalled();
808 void SSLClientSocketPool::AddHigherLayeredPool(HigherLayeredPool
* higher_pool
) {
809 base_
.AddHigherLayeredPool(higher_pool
);
812 void SSLClientSocketPool::RemoveHigherLayeredPool(
813 HigherLayeredPool
* higher_pool
) {
814 base_
.RemoveHigherLayeredPool(higher_pool
);
817 bool SSLClientSocketPool::CloseOneIdleConnection() {
818 if (base_
.CloseOneIdleSocket())
820 return base_
.CloseOneIdleConnectionInHigherLayeredPool();
823 SSLConnectJobMessenger
* SSLClientSocketPool::GetOrCreateSSLConnectJobMessenger(
824 const std::string
& cache_key
) {
825 if (!enable_ssl_connect_job_waiting_
)
827 MessengerMap::const_iterator it
= messenger_map_
.find(cache_key
);
828 if (it
== messenger_map_
.end()) {
829 std::pair
<MessengerMap::iterator
, bool> iter
=
830 messenger_map_
.insert(MessengerMap::value_type(
832 new SSLConnectJobMessenger(
833 base::Bind(&SSLClientSocketPool::DeleteSSLConnectJobMessenger
,
834 base::Unretained(this),
841 void SSLClientSocketPool::DeleteSSLConnectJobMessenger(
842 const std::string
& cache_key
) {
843 MessengerMap::iterator it
= messenger_map_
.find(cache_key
);
844 CHECK(it
!= messenger_map_
.end());
846 messenger_map_
.erase(it
);
849 void SSLClientSocketPool::OnSSLConfigChanged() {
850 FlushWithError(ERR_NETWORK_CHANGED
);