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" |
11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "net/base/host_port_pair.h" | 13 #include "net/base/host_port_pair.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "net/http/http_proxy_client_socket.h" | 15 #include "net/http/http_proxy_client_socket.h" |
16 #include "net/http/http_proxy_client_socket_pool.h" | 16 #include "net/http/http_proxy_client_socket_pool.h" |
17 #include "net/socket/client_socket_factory.h" | 17 #include "net/socket/client_socket_factory.h" |
18 #include "net/socket/client_socket_handle.h" | 18 #include "net/socket/client_socket_handle.h" |
19 #include "net/socket/socks_client_socket_pool.h" | 19 #include "net/socket/socks_client_socket_pool.h" |
20 #include "net/socket/ssl_client_socket.h" | 20 #include "net/socket/ssl_client_socket.h" |
21 #include "net/socket/ssl_client_socket_openssl.h" | |
wtc
2014/06/13 22:47:24
This needs to be put inside #if defined(USE_OPENSS
mshelley1
2014/06/16 19:02:50
Done.
| |
21 #include "net/socket/transport_client_socket_pool.h" | 22 #include "net/socket/transport_client_socket_pool.h" |
22 #include "net/ssl/ssl_cert_request_info.h" | 23 #include "net/ssl/ssl_cert_request_info.h" |
23 #include "net/ssl/ssl_connection_status_flags.h" | 24 #include "net/ssl/ssl_connection_status_flags.h" |
24 #include "net/ssl/ssl_info.h" | 25 #include "net/ssl/ssl_info.h" |
25 | 26 |
26 namespace net { | 27 namespace net { |
27 | 28 |
28 SSLSocketParams::SSLSocketParams( | 29 SSLSocketParams::SSLSocketParams( |
29 const scoped_refptr<TransportSocketParams>& direct_params, | 30 const scoped_refptr<TransportSocketParams>& direct_params, |
30 const scoped_refptr<SOCKSSocketParams>& socks_proxy_params, | 31 const scoped_refptr<SOCKSSocketParams>& socks_proxy_params, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 RequestPriority priority, | 102 RequestPriority priority, |
102 const scoped_refptr<SSLSocketParams>& params, | 103 const scoped_refptr<SSLSocketParams>& params, |
103 const base::TimeDelta& timeout_duration, | 104 const base::TimeDelta& timeout_duration, |
104 TransportClientSocketPool* transport_pool, | 105 TransportClientSocketPool* transport_pool, |
105 SOCKSClientSocketPool* socks_pool, | 106 SOCKSClientSocketPool* socks_pool, |
106 HttpProxyClientSocketPool* http_proxy_pool, | 107 HttpProxyClientSocketPool* http_proxy_pool, |
107 ClientSocketFactory* client_socket_factory, | 108 ClientSocketFactory* client_socket_factory, |
108 HostResolver* host_resolver, | 109 HostResolver* host_resolver, |
109 const SSLClientSocketContext& context, | 110 const SSLClientSocketContext& context, |
110 Delegate* delegate, | 111 Delegate* delegate, |
111 NetLog* net_log) | 112 NetLog* net_log, |
113 PendingJobList* pending) | |
112 : ConnectJob(group_name, | 114 : ConnectJob(group_name, |
113 timeout_duration, | 115 timeout_duration, |
114 priority, | 116 priority, |
115 delegate, | 117 delegate, |
116 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 118 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
117 params_(params), | 119 params_(params), |
118 transport_pool_(transport_pool), | 120 transport_pool_(transport_pool), |
119 socks_pool_(socks_pool), | 121 socks_pool_(socks_pool), |
120 http_proxy_pool_(http_proxy_pool), | 122 http_proxy_pool_(http_proxy_pool), |
121 client_socket_factory_(client_socket_factory), | 123 client_socket_factory_(client_socket_factory), |
122 host_resolver_(host_resolver), | 124 host_resolver_(host_resolver), |
123 context_(context.cert_verifier, | 125 context_(context.cert_verifier, |
124 context.server_bound_cert_service, | 126 context.server_bound_cert_service, |
125 context.transport_security_state, | 127 context.transport_security_state, |
126 context.cert_transparency_verifier, | 128 context.cert_transparency_verifier, |
127 (params->privacy_mode() == PRIVACY_MODE_ENABLED | 129 (params->privacy_mode() == PRIVACY_MODE_ENABLED |
128 ? "pm/" + context.ssl_session_cache_shard | 130 ? "pm/" + context.ssl_session_cache_shard |
129 : context.ssl_session_cache_shard)), | 131 : context.ssl_session_cache_shard)), |
130 callback_(base::Bind(&SSLConnectJob::OnIOComplete, | 132 callback_( |
Ryan Sleevi
2014/06/13 23:24:22
nit: We typically call this io_callback_
mshelley1
2014/06/16 19:02:50
Done.
| |
131 base::Unretained(this))) {} | 133 base::Bind(&SSLConnectJob::OnIOComplete, base::Unretained(this))), |
134 pending_(pending) { | |
135 } | |
132 | 136 |
133 SSLConnectJob::~SSLConnectJob() {} | 137 SSLConnectJob::~SSLConnectJob() {} |
134 | 138 |
139 bool SSLConnectJob::enable_job_waiting_ = false; | |
140 | |
135 LoadState SSLConnectJob::GetLoadState() const { | 141 LoadState SSLConnectJob::GetLoadState() const { |
136 switch (next_state_) { | 142 switch (next_state_) { |
137 case STATE_TUNNEL_CONNECT_COMPLETE: | 143 case STATE_TUNNEL_CONNECT_COMPLETE: |
138 if (transport_socket_handle_->socket()) | 144 if (transport_socket_handle_->socket()) |
139 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; | 145 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; |
140 // else, fall through. | 146 // else, fall through. |
141 case STATE_TRANSPORT_CONNECT: | 147 case STATE_TRANSPORT_CONNECT: |
142 case STATE_TRANSPORT_CONNECT_COMPLETE: | 148 case STATE_TRANSPORT_CONNECT_COMPLETE: |
143 case STATE_SOCKS_CONNECT: | 149 case STATE_SOCKS_CONNECT: |
144 case STATE_SOCKS_CONNECT_COMPLETE: | 150 case STATE_SOCKS_CONNECT_COMPLETE: |
145 case STATE_TUNNEL_CONNECT: | 151 case STATE_TUNNEL_CONNECT: |
146 return transport_socket_handle_->GetLoadState(); | 152 return transport_socket_handle_->GetLoadState(); |
153 case STATE_CHECK_FOR_RESUME: | |
154 case STATE_WAIT: | |
147 case STATE_SSL_CONNECT: | 155 case STATE_SSL_CONNECT: |
148 case STATE_SSL_CONNECT_COMPLETE: | 156 case STATE_SSL_CONNECT_COMPLETE: |
149 return LOAD_STATE_SSL_HANDSHAKE; | 157 return LOAD_STATE_SSL_HANDSHAKE; |
150 default: | 158 default: |
151 NOTREACHED(); | 159 NOTREACHED(); |
152 return LOAD_STATE_IDLE; | 160 return LOAD_STATE_IDLE; |
153 } | 161 } |
154 } | 162 } |
155 | 163 |
156 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { | 164 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { |
157 // Headers in |error_response_info_| indicate a proxy tunnel setup | 165 // Headers in |error_response_info_| indicate a proxy tunnel setup |
158 // problem. See DoTunnelConnectComplete. | 166 // problem. See DoTunnelConnectComplete. |
159 if (error_response_info_.headers.get()) { | 167 if (error_response_info_.headers.get()) { |
160 handle->set_pending_http_proxy_connection( | 168 handle->set_pending_http_proxy_connection( |
161 transport_socket_handle_.release()); | 169 transport_socket_handle_.release()); |
162 } | 170 } |
163 handle->set_ssl_error_response_info(error_response_info_); | 171 handle->set_ssl_error_response_info(error_response_info_); |
164 if (!connect_timing_.ssl_start.is_null()) | 172 if (!connect_timing_.ssl_start.is_null()) |
165 handle->set_is_ssl_error(true); | 173 handle->set_is_ssl_error(true); |
166 } | 174 } |
167 | 175 |
176 void SSLConnectJob::EnableJobWaiting(bool enable) { | |
177 enable_job_waiting_ = enable; | |
178 } | |
179 | |
168 void SSLConnectJob::OnIOComplete(int result) { | 180 void SSLConnectJob::OnIOComplete(int result) { |
169 int rv = DoLoop(result); | 181 int rv = DoLoop(result); |
170 if (rv != ERR_IO_PENDING) | 182 if (rv != ERR_IO_PENDING) |
171 NotifyDelegateOfCompletion(rv); // Deletes |this|. | 183 NotifyDelegateOfCompletion(rv); // Deletes |this|. |
172 } | 184 } |
173 | 185 |
174 int SSLConnectJob::DoLoop(int result) { | 186 int SSLConnectJob::DoLoop(int result) { |
175 DCHECK_NE(next_state_, STATE_NONE); | 187 DCHECK_NE(next_state_, STATE_NONE); |
176 | 188 |
177 int rv = result; | 189 int rv = result; |
(...skipping 15 matching lines...) Expand all Loading... | |
193 case STATE_SOCKS_CONNECT_COMPLETE: | 205 case STATE_SOCKS_CONNECT_COMPLETE: |
194 rv = DoSOCKSConnectComplete(rv); | 206 rv = DoSOCKSConnectComplete(rv); |
195 break; | 207 break; |
196 case STATE_TUNNEL_CONNECT: | 208 case STATE_TUNNEL_CONNECT: |
197 DCHECK_EQ(OK, rv); | 209 DCHECK_EQ(OK, rv); |
198 rv = DoTunnelConnect(); | 210 rv = DoTunnelConnect(); |
199 break; | 211 break; |
200 case STATE_TUNNEL_CONNECT_COMPLETE: | 212 case STATE_TUNNEL_CONNECT_COMPLETE: |
201 rv = DoTunnelConnectComplete(rv); | 213 rv = DoTunnelConnectComplete(rv); |
202 break; | 214 break; |
215 case STATE_CHECK_FOR_RESUME: | |
216 rv = DoCheckForResume(); | |
217 break; | |
218 case STATE_WAIT: | |
219 next_state_ = STATE_CHECK_FOR_RESUME; | |
220 rv = ERR_IO_PENDING; | |
Ryan Sleevi
2014/06/13 23:24:22
First Reaction: This is weird to have it as an sta
mshelley1
2014/06/16 19:02:50
Done.
| |
221 break; | |
203 case STATE_SSL_CONNECT: | 222 case STATE_SSL_CONNECT: |
204 DCHECK_EQ(OK, rv); | 223 DCHECK_EQ(OK, rv); |
205 rv = DoSSLConnect(); | 224 rv = DoSSLConnect(); |
206 break; | 225 break; |
207 case STATE_SSL_CONNECT_COMPLETE: | 226 case STATE_SSL_CONNECT_COMPLETE: |
208 rv = DoSSLConnectComplete(rv); | 227 rv = DoSSLConnectComplete(rv); |
209 break; | 228 break; |
210 default: | 229 default: |
211 NOTREACHED() << "bad state"; | 230 NOTREACHED() << "bad state"; |
212 rv = ERR_FAILED; | 231 rv = ERR_FAILED; |
(...skipping 13 matching lines...) Expand all Loading... | |
226 params_->GetDirectConnectionParams(); | 245 params_->GetDirectConnectionParams(); |
227 return transport_socket_handle_->Init(group_name(), | 246 return transport_socket_handle_->Init(group_name(), |
228 direct_params, | 247 direct_params, |
229 priority(), | 248 priority(), |
230 callback_, | 249 callback_, |
231 transport_pool_, | 250 transport_pool_, |
232 net_log()); | 251 net_log()); |
233 } | 252 } |
234 | 253 |
235 int SSLConnectJob::DoTransportConnectComplete(int result) { | 254 int SSLConnectJob::DoTransportConnectComplete(int result) { |
236 if (result == OK) | 255 if (result == OK) { |
Ryan Sleevi
2014/06/13 23:24:22
We try to handle errors before success cases;
if
mshelley1
2014/06/16 19:02:49
Done.
| |
237 next_state_ = STATE_SSL_CONNECT; | 256 if (enable_job_waiting_) |
257 next_state_ = STATE_CHECK_FOR_RESUME; | |
258 else | |
259 next_state_ = STATE_SSL_CONNECT; | |
260 } | |
238 | 261 |
239 return result; | 262 return result; |
240 } | 263 } |
241 | 264 |
242 int SSLConnectJob::DoSOCKSConnect() { | 265 int SSLConnectJob::DoSOCKSConnect() { |
243 DCHECK(socks_pool_); | 266 DCHECK(socks_pool_); |
244 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; | 267 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; |
245 transport_socket_handle_.reset(new ClientSocketHandle()); | 268 transport_socket_handle_.reset(new ClientSocketHandle()); |
246 scoped_refptr<SOCKSSocketParams> socks_proxy_params = | 269 scoped_refptr<SOCKSSocketParams> socks_proxy_params = |
247 params_->GetSocksProxyConnectionParams(); | 270 params_->GetSocksProxyConnectionParams(); |
248 return transport_socket_handle_->Init(group_name(), | 271 return transport_socket_handle_->Init(group_name(), |
249 socks_proxy_params, | 272 socks_proxy_params, |
250 priority(), | 273 priority(), |
251 callback_, | 274 callback_, |
252 socks_pool_, | 275 socks_pool_, |
253 net_log()); | 276 net_log()); |
254 } | 277 } |
255 | 278 |
256 int SSLConnectJob::DoSOCKSConnectComplete(int result) { | 279 int SSLConnectJob::DoSOCKSConnectComplete(int result) { |
257 if (result == OK) | 280 if (result == OK) { |
258 next_state_ = STATE_SSL_CONNECT; | 281 if (enable_job_waiting_) |
282 next_state_ = STATE_CHECK_FOR_RESUME; | |
283 else | |
284 next_state_ = STATE_SSL_CONNECT; | |
285 } | |
Ryan Sleevi
2014/06/13 23:24:22
Ditto ordering
mshelley1
2014/06/16 19:02:50
Done.
| |
259 | 286 |
260 return result; | 287 return result; |
261 } | 288 } |
262 | 289 |
263 int SSLConnectJob::DoTunnelConnect() { | 290 int SSLConnectJob::DoTunnelConnect() { |
264 DCHECK(http_proxy_pool_); | 291 DCHECK(http_proxy_pool_); |
265 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; | 292 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; |
266 | 293 |
267 transport_socket_handle_.reset(new ClientSocketHandle()); | 294 transport_socket_handle_.reset(new ClientSocketHandle()); |
268 scoped_refptr<HttpProxySocketParams> http_proxy_params = | 295 scoped_refptr<HttpProxySocketParams> http_proxy_params = |
(...skipping 14 matching lines...) Expand all Loading... | |
283 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); | 310 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); |
284 } else if (result == ERR_PROXY_AUTH_REQUESTED || | 311 } else if (result == ERR_PROXY_AUTH_REQUESTED || |
285 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { | 312 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { |
286 StreamSocket* socket = transport_socket_handle_->socket(); | 313 StreamSocket* socket = transport_socket_handle_->socket(); |
287 HttpProxyClientSocket* tunnel_socket = | 314 HttpProxyClientSocket* tunnel_socket = |
288 static_cast<HttpProxyClientSocket*>(socket); | 315 static_cast<HttpProxyClientSocket*>(socket); |
289 error_response_info_ = *tunnel_socket->GetConnectResponseInfo(); | 316 error_response_info_ = *tunnel_socket->GetConnectResponseInfo(); |
290 } | 317 } |
291 if (result < 0) | 318 if (result < 0) |
292 return result; | 319 return result; |
293 | 320 if (enable_job_waiting_) |
294 next_state_ = STATE_SSL_CONNECT; | 321 next_state_ = STATE_CHECK_FOR_RESUME; |
322 else | |
323 next_state_ = STATE_SSL_CONNECT; | |
Ryan Sleevi
2014/06/13 23:24:22
STYLE: This is now the third time this conditional
mshelley1
2014/06/16 19:02:50
Done.
| |
295 return result; | 324 return result; |
296 } | 325 } |
297 | 326 |
327 int SSLConnectJob::DoCheckForResume() { | |
328 // If the group is in the cache, continue. | |
329 if (SSLClientSocketOpenSSL::InSessionCache(GetSessionCacheKey())) { | |
330 next_state_ = STATE_SSL_CONNECT; | |
331 return OK; | |
332 } | |
333 | |
334 // If there are pending jobs, wait. | |
335 if (!pending_->empty()) { | |
336 pending_->push_back(this); | |
337 next_state_ = STATE_WAIT; | |
338 return OK; | |
Ryan Sleevi
2014/06/13 23:24:22
This should be ERR_IO_PENDING
mshelley1
2014/06/16 19:02:50
Done.
| |
339 } | |
340 | |
341 // If there are no pending jobs, continue | |
342 pending_->push_back(this); | |
343 next_state_ = STATE_SSL_CONNECT; | |
344 return OK; | |
345 } | |
346 | |
298 int SSLConnectJob::DoSSLConnect() { | 347 int SSLConnectJob::DoSSLConnect() { |
299 next_state_ = STATE_SSL_CONNECT_COMPLETE; | 348 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
300 // Reset the timeout to just the time allowed for the SSL handshake. | 349 // Reset the timeout to just the time allowed for the SSL handshake. |
301 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); | 350 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); |
302 | 351 |
303 // If the handle has a fresh socket, get its connect start and DNS times. | 352 // If the handle has a fresh socket, get its connect start and DNS times. |
304 // This should always be the case. | 353 // This should always be the case. |
305 const LoadTimingInfo::ConnectTiming& socket_connect_timing = | 354 const LoadTimingInfo::ConnectTiming& socket_connect_timing = |
306 transport_socket_handle_->connect_timing(); | 355 transport_socket_handle_->connect_timing(); |
307 if (!transport_socket_handle_->is_reused() && | 356 if (!transport_socket_handle_->is_reused() && |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 100); | 453 100); |
405 } else if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_FULL) { | 454 } else if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_FULL) { |
406 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Full_Handshake", | 455 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Full_Handshake", |
407 connect_duration, | 456 connect_duration, |
408 base::TimeDelta::FromMilliseconds(1), | 457 base::TimeDelta::FromMilliseconds(1), |
409 base::TimeDelta::FromMinutes(1), | 458 base::TimeDelta::FromMinutes(1), |
410 100); | 459 100); |
411 } | 460 } |
412 | 461 |
413 const std::string& host = params_->host_and_port().host(); | 462 const std::string& host = params_->host_and_port().host(); |
414 bool is_google = host == "google.com" || | 463 bool is_google = |
415 (host.size() > 11 && | 464 host == "google.com" || |
416 host.rfind(".google.com") == host.size() - 11); | 465 (host.size() > 11 && host.rfind(".google.com") == host.size() - 11); |
417 if (is_google) { | 466 if (is_google) { |
418 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2", | 467 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2", |
419 connect_duration, | 468 connect_duration, |
420 base::TimeDelta::FromMilliseconds(1), | 469 base::TimeDelta::FromMilliseconds(1), |
421 base::TimeDelta::FromMinutes(1), | 470 base::TimeDelta::FromMinutes(1), |
422 100); | 471 100); |
423 if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME) { | 472 if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME) { |
424 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_" | 473 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_" |
425 "Resume_Handshake", | 474 "Resume_Handshake", |
426 connect_duration, | 475 connect_duration, |
(...skipping 12 matching lines...) Expand all Loading... | |
439 } | 488 } |
440 | 489 |
441 if (result == OK || IsCertificateError(result)) { | 490 if (result == OK || IsCertificateError(result)) { |
442 SetSocket(ssl_socket_.PassAs<StreamSocket>()); | 491 SetSocket(ssl_socket_.PassAs<StreamSocket>()); |
443 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 492 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
444 error_response_info_.cert_request_info = new SSLCertRequestInfo; | 493 error_response_info_.cert_request_info = new SSLCertRequestInfo; |
445 ssl_socket_->GetSSLCertRequestInfo( | 494 ssl_socket_->GetSSLCertRequestInfo( |
446 error_response_info_.cert_request_info.get()); | 495 error_response_info_.cert_request_info.get()); |
447 } | 496 } |
448 | 497 |
498 if (enable_job_waiting_) { | |
Ryan Sleevi
2014/06/13 23:24:22
This should probably all be moved into a helper fu
mshelley1
2014/06/16 19:02:50
Done.
| |
499 // If there is a pending list | |
500 if (!pending_->empty()) { | |
501 // The first element of the vector will always be the leading job. | |
502 PendingJobList::iterator i = pending_->begin(); | |
503 // If the connection was successful, tell all pending jobs to proceed. | |
504 if (result == OK) { | |
505 for (PendingJobList::iterator job = i + 1; job != pending_->end(); | |
506 ++job) { | |
507 (*job)->DoSSL(); | |
508 } | |
509 // pending_->erase(i); | |
510 pending_->clear(); | |
511 } | |
512 // If the connection failed, tell only one job to proceed as the new | |
513 // leader. | |
514 else if (i + 1 != pending_->end()) { | |
515 (*(i + 1))->DoSSL(); | |
516 pending_->erase(i); | |
517 } | |
518 // If there are no more jobs and the leader failed, delete the entry. | |
519 else | |
520 pending_->erase(i); | |
521 } | |
522 } | |
523 | |
449 return result; | 524 return result; |
450 } | 525 } |
451 | 526 |
527 void SSLConnectJob::DoSSL() { | |
528 next_state_ = STATE_SSL_CONNECT; | |
529 OnIOComplete(OK); | |
530 } | |
531 | |
532 std::string SSLConnectJob::GetSessionCacheKey() { | |
533 return params_->host_and_port().ToString() + "/" + | |
534 context_.ssl_session_cache_shard; | |
535 } | |
536 | |
452 SSLConnectJob::State SSLConnectJob::GetInitialState( | 537 SSLConnectJob::State SSLConnectJob::GetInitialState( |
453 SSLSocketParams::ConnectionType connection_type) { | 538 SSLSocketParams::ConnectionType connection_type) { |
454 switch (connection_type) { | 539 switch (connection_type) { |
455 case SSLSocketParams::DIRECT: | 540 case SSLSocketParams::DIRECT: |
456 return STATE_TRANSPORT_CONNECT; | 541 return STATE_TRANSPORT_CONNECT; |
457 case SSLSocketParams::HTTP_PROXY: | 542 case SSLSocketParams::HTTP_PROXY: |
458 return STATE_TUNNEL_CONNECT; | 543 return STATE_TUNNEL_CONNECT; |
459 case SSLSocketParams::SOCKS_PROXY: | 544 case SSLSocketParams::SOCKS_PROXY: |
460 return STATE_SOCKS_CONNECT; | 545 return STATE_SOCKS_CONNECT; |
461 } | 546 } |
(...skipping 13 matching lines...) Expand all Loading... | |
475 ClientSocketFactory* client_socket_factory, | 560 ClientSocketFactory* client_socket_factory, |
476 HostResolver* host_resolver, | 561 HostResolver* host_resolver, |
477 const SSLClientSocketContext& context, | 562 const SSLClientSocketContext& context, |
478 NetLog* net_log) | 563 NetLog* net_log) |
479 : transport_pool_(transport_pool), | 564 : transport_pool_(transport_pool), |
480 socks_pool_(socks_pool), | 565 socks_pool_(socks_pool), |
481 http_proxy_pool_(http_proxy_pool), | 566 http_proxy_pool_(http_proxy_pool), |
482 client_socket_factory_(client_socket_factory), | 567 client_socket_factory_(client_socket_factory), |
483 host_resolver_(host_resolver), | 568 host_resolver_(host_resolver), |
484 context_(context), | 569 context_(context), |
485 net_log_(net_log) { | 570 net_log_(net_log), |
571 pending_(new PendingJobMap()) { | |
486 base::TimeDelta max_transport_timeout = base::TimeDelta(); | 572 base::TimeDelta max_transport_timeout = base::TimeDelta(); |
487 base::TimeDelta pool_timeout; | 573 base::TimeDelta pool_timeout; |
488 if (transport_pool_) | 574 if (transport_pool_) |
489 max_transport_timeout = transport_pool_->ConnectionTimeout(); | 575 max_transport_timeout = transport_pool_->ConnectionTimeout(); |
490 if (socks_pool_) { | 576 if (socks_pool_) { |
491 pool_timeout = socks_pool_->ConnectionTimeout(); | 577 pool_timeout = socks_pool_->ConnectionTimeout(); |
492 if (pool_timeout > max_transport_timeout) | 578 if (pool_timeout > max_transport_timeout) |
493 max_transport_timeout = pool_timeout; | 579 max_transport_timeout = pool_timeout; |
494 } | 580 } |
495 if (http_proxy_pool_) { | 581 if (http_proxy_pool_) { |
(...skipping 17 matching lines...) Expand all Loading... | |
513 const std::string& ssl_session_cache_shard, | 599 const std::string& ssl_session_cache_shard, |
514 ClientSocketFactory* client_socket_factory, | 600 ClientSocketFactory* client_socket_factory, |
515 TransportClientSocketPool* transport_pool, | 601 TransportClientSocketPool* transport_pool, |
516 SOCKSClientSocketPool* socks_pool, | 602 SOCKSClientSocketPool* socks_pool, |
517 HttpProxyClientSocketPool* http_proxy_pool, | 603 HttpProxyClientSocketPool* http_proxy_pool, |
518 SSLConfigService* ssl_config_service, | 604 SSLConfigService* ssl_config_service, |
519 NetLog* net_log) | 605 NetLog* net_log) |
520 : transport_pool_(transport_pool), | 606 : transport_pool_(transport_pool), |
521 socks_pool_(socks_pool), | 607 socks_pool_(socks_pool), |
522 http_proxy_pool_(http_proxy_pool), | 608 http_proxy_pool_(http_proxy_pool), |
523 base_(this, max_sockets, max_sockets_per_group, histograms, | 609 base_(this, |
610 max_sockets, | |
611 max_sockets_per_group, | |
612 histograms, | |
524 ClientSocketPool::unused_idle_socket_timeout(), | 613 ClientSocketPool::unused_idle_socket_timeout(), |
525 ClientSocketPool::used_idle_socket_timeout(), | 614 ClientSocketPool::used_idle_socket_timeout(), |
526 new SSLConnectJobFactory(transport_pool, | 615 new SSLConnectJobFactory( |
527 socks_pool, | 616 transport_pool, |
528 http_proxy_pool, | 617 socks_pool, |
529 client_socket_factory, | 618 http_proxy_pool, |
530 host_resolver, | 619 client_socket_factory, |
531 SSLClientSocketContext( | 620 host_resolver, |
532 cert_verifier, | 621 SSLClientSocketContext(cert_verifier, |
533 server_bound_cert_service, | 622 server_bound_cert_service, |
534 transport_security_state, | 623 transport_security_state, |
535 cert_transparency_verifier, | 624 cert_transparency_verifier, |
536 ssl_session_cache_shard), | 625 ssl_session_cache_shard), |
537 net_log)), | 626 net_log)), |
538 ssl_config_service_(ssl_config_service) { | 627 ssl_config_service_(ssl_config_service) { |
539 if (ssl_config_service_.get()) | 628 if (ssl_config_service_.get()) |
540 ssl_config_service_->AddObserver(this); | 629 ssl_config_service_->AddObserver(this); |
541 if (transport_pool_) | 630 if (transport_pool_) |
542 base_.AddLowerLayeredPool(transport_pool_); | 631 base_.AddLowerLayeredPool(transport_pool_); |
543 if (socks_pool_) | 632 if (socks_pool_) |
544 base_.AddLowerLayeredPool(socks_pool_); | 633 base_.AddLowerLayeredPool(socks_pool_); |
545 if (http_proxy_pool_) | 634 if (http_proxy_pool_) |
546 base_.AddLowerLayeredPool(http_proxy_pool_); | 635 base_.AddLowerLayeredPool(http_proxy_pool_); |
547 } | 636 } |
548 | 637 |
549 SSLClientSocketPool::~SSLClientSocketPool() { | 638 SSLClientSocketPool::~SSLClientSocketPool() { |
550 if (ssl_config_service_.get()) | 639 if (ssl_config_service_.get()) |
551 ssl_config_service_->RemoveObserver(this); | 640 ssl_config_service_->RemoveObserver(this); |
552 } | 641 } |
553 | 642 |
554 scoped_ptr<ConnectJob> | 643 scoped_ptr<ConnectJob> |
555 SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( | 644 SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( |
556 const std::string& group_name, | 645 const std::string& group_name, |
557 const PoolBase::Request& request, | 646 const PoolBase::Request& request, |
558 ConnectJob::Delegate* delegate) const { | 647 ConnectJob::Delegate* delegate) const { |
559 return scoped_ptr<ConnectJob>( | 648 PendingJobMap::iterator p = pending_->find(group_name); |
560 new SSLConnectJob(group_name, request.priority(), request.params(), | 649 SSLConnectJob::PendingJobList* pending_job_list; |
561 ConnectionTimeout(), transport_pool_, socks_pool_, | 650 if (p == pending_->end()) { |
562 http_proxy_pool_, client_socket_factory_, | 651 (*pending_)[group_name] = new SSLConnectJob::PendingJobList(); |
563 host_resolver_, context_, delegate, net_log_)); | 652 pending_job_list = (*pending_)[group_name]; |
Ryan Sleevi
2014/06/13 23:24:22
This is actually somewhat inefficient; it does two
mshelley1
2014/06/16 19:02:50
Done.
| |
653 } else | |
654 pending_job_list = p->second; | |
Ryan Sleevi
2014/06/13 23:24:22
If one portion of an if statement includes braces,
mshelley1
2014/06/16 19:02:50
Done.
| |
655 return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name, | |
656 request.priority(), | |
657 request.params(), | |
658 ConnectionTimeout(), | |
659 transport_pool_, | |
660 socks_pool_, | |
661 http_proxy_pool_, | |
662 client_socket_factory_, | |
663 host_resolver_, | |
664 context_, | |
665 delegate, | |
666 net_log_, | |
667 pending_job_list)); | |
564 } | 668 } |
565 | 669 |
566 base::TimeDelta | 670 base::TimeDelta |
567 SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() const { | 671 SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() const { |
568 return timeout_; | 672 return timeout_; |
569 } | 673 } |
570 | 674 |
571 int SSLClientSocketPool::RequestSocket(const std::string& group_name, | 675 int SSLClientSocketPool::RequestSocket(const std::string& group_name, |
572 const void* socket_params, | 676 const void* socket_params, |
573 RequestPriority priority, | 677 RequestPriority priority, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 if (base_.CloseOneIdleSocket()) | 781 if (base_.CloseOneIdleSocket()) |
678 return true; | 782 return true; |
679 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 783 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
680 } | 784 } |
681 | 785 |
682 void SSLClientSocketPool::OnSSLConfigChanged() { | 786 void SSLClientSocketPool::OnSSLConfigChanged() { |
683 FlushWithError(ERR_NETWORK_CHANGED); | 787 FlushWithError(ERR_NETWORK_CHANGED); |
684 } | 788 } |
685 | 789 |
686 } // namespace net | 790 } // namespace net |
OLD | NEW |