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

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

Issue 328903004: SSL Connect Job Waiting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Redesigned cache accessing functions. Created 6 years, 6 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 RequestPriority priority, 101 RequestPriority priority,
102 const scoped_refptr<SSLSocketParams>& params, 102 const scoped_refptr<SSLSocketParams>& params,
103 const base::TimeDelta& timeout_duration, 103 const base::TimeDelta& timeout_duration,
104 TransportClientSocketPool* transport_pool, 104 TransportClientSocketPool* transport_pool,
105 SOCKSClientSocketPool* socks_pool, 105 SOCKSClientSocketPool* socks_pool,
106 HttpProxyClientSocketPool* http_proxy_pool, 106 HttpProxyClientSocketPool* http_proxy_pool,
107 ClientSocketFactory* client_socket_factory, 107 ClientSocketFactory* client_socket_factory,
108 HostResolver* host_resolver, 108 HostResolver* host_resolver,
109 const SSLClientSocketContext& context, 109 const SSLClientSocketContext& context,
110 Delegate* delegate, 110 Delegate* delegate,
111 NetLog* net_log) 111 NetLog* net_log,
112 PendingJobList* pending)
112 : ConnectJob(group_name, 113 : ConnectJob(group_name,
113 timeout_duration, 114 timeout_duration,
114 priority, 115 priority,
115 delegate, 116 delegate,
116 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), 117 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)),
117 params_(params), 118 params_(params),
118 transport_pool_(transport_pool), 119 transport_pool_(transport_pool),
119 socks_pool_(socks_pool), 120 socks_pool_(socks_pool),
120 http_proxy_pool_(http_proxy_pool), 121 http_proxy_pool_(http_proxy_pool),
121 client_socket_factory_(client_socket_factory), 122 client_socket_factory_(client_socket_factory),
122 host_resolver_(host_resolver), 123 host_resolver_(host_resolver),
123 context_(context.cert_verifier, 124 context_(context.cert_verifier,
124 context.server_bound_cert_service, 125 context.server_bound_cert_service,
125 context.transport_security_state, 126 context.transport_security_state,
126 context.cert_transparency_verifier, 127 context.cert_transparency_verifier,
127 (params->privacy_mode() == PRIVACY_MODE_ENABLED 128 (params->privacy_mode() == PRIVACY_MODE_ENABLED
128 ? "pm/" + context.ssl_session_cache_shard 129 ? "pm/" + context.ssl_session_cache_shard
129 : context.ssl_session_cache_shard)), 130 : context.ssl_session_cache_shard)),
130 callback_(base::Bind(&SSLConnectJob::OnIOComplete, 131 io_callback_(
131 base::Unretained(this))) {} 132 base::Bind(&SSLConnectJob::OnIOComplete, base::Unretained(this))),
133 pending_jobs_(pending) {
134 }
132 135
133 SSLConnectJob::~SSLConnectJob() {} 136 SSLConnectJob::~SSLConnectJob() {}
134 137
138 bool SSLConnectJob::enable_job_waiting_ = false;
wtc 2014/06/17 17:44:40 Nit: add a // static comment before this line. (Th
mshelley1 2014/06/18 18:53:49 Done.
139
135 LoadState SSLConnectJob::GetLoadState() const { 140 LoadState SSLConnectJob::GetLoadState() const {
136 switch (next_state_) { 141 switch (next_state_) {
137 case STATE_TUNNEL_CONNECT_COMPLETE: 142 case STATE_TUNNEL_CONNECT_COMPLETE:
138 if (transport_socket_handle_->socket()) 143 if (transport_socket_handle_->socket())
139 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; 144 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL;
140 // else, fall through. 145 // else, fall through.
141 case STATE_TRANSPORT_CONNECT: 146 case STATE_TRANSPORT_CONNECT:
142 case STATE_TRANSPORT_CONNECT_COMPLETE: 147 case STATE_TRANSPORT_CONNECT_COMPLETE:
143 case STATE_SOCKS_CONNECT: 148 case STATE_SOCKS_CONNECT:
144 case STATE_SOCKS_CONNECT_COMPLETE: 149 case STATE_SOCKS_CONNECT_COMPLETE:
145 case STATE_TUNNEL_CONNECT: 150 case STATE_TUNNEL_CONNECT:
146 return transport_socket_handle_->GetLoadState(); 151 return transport_socket_handle_->GetLoadState();
152 case STATE_CHECK_FOR_RESUME:
wtc 2014/06/17 17:44:40 Should we also add the STATE_CREATE_SSL_SOCKET sta
mshelley1 2014/06/18 18:53:49 Done.
147 case STATE_SSL_CONNECT: 153 case STATE_SSL_CONNECT:
148 case STATE_SSL_CONNECT_COMPLETE: 154 case STATE_SSL_CONNECT_COMPLETE:
149 return LOAD_STATE_SSL_HANDSHAKE; 155 return LOAD_STATE_SSL_HANDSHAKE;
150 default: 156 default:
151 NOTREACHED(); 157 NOTREACHED();
152 return LOAD_STATE_IDLE; 158 return LOAD_STATE_IDLE;
153 } 159 }
154 } 160 }
155 161
156 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { 162 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) {
157 // Headers in |error_response_info_| indicate a proxy tunnel setup 163 // Headers in |error_response_info_| indicate a proxy tunnel setup
158 // problem. See DoTunnelConnectComplete. 164 // problem. See DoTunnelConnectComplete.
159 if (error_response_info_.headers.get()) { 165 if (error_response_info_.headers.get()) {
160 handle->set_pending_http_proxy_connection( 166 handle->set_pending_http_proxy_connection(
161 transport_socket_handle_.release()); 167 transport_socket_handle_.release());
162 } 168 }
163 handle->set_ssl_error_response_info(error_response_info_); 169 handle->set_ssl_error_response_info(error_response_info_);
164 if (!connect_timing_.ssl_start.is_null()) 170 if (!connect_timing_.ssl_start.is_null())
165 handle->set_is_ssl_error(true); 171 handle->set_is_ssl_error(true);
166 } 172 }
167 173
174 void SSLConnectJob::EnableJobWaiting(bool enable) {
175 enable_job_waiting_ = enable;
176 }
177
168 void SSLConnectJob::OnIOComplete(int result) { 178 void SSLConnectJob::OnIOComplete(int result) {
169 int rv = DoLoop(result); 179 int rv = DoLoop(result);
170 if (rv != ERR_IO_PENDING) 180 if (rv != ERR_IO_PENDING)
171 NotifyDelegateOfCompletion(rv); // Deletes |this|. 181 NotifyDelegateOfCompletion(rv); // Deletes |this|.
172 } 182 }
173 183
174 int SSLConnectJob::DoLoop(int result) { 184 int SSLConnectJob::DoLoop(int result) {
175 DCHECK_NE(next_state_, STATE_NONE); 185 DCHECK_NE(next_state_, STATE_NONE);
176 186
177 int rv = result; 187 int rv = result;
(...skipping 15 matching lines...) Expand all
193 case STATE_SOCKS_CONNECT_COMPLETE: 203 case STATE_SOCKS_CONNECT_COMPLETE:
194 rv = DoSOCKSConnectComplete(rv); 204 rv = DoSOCKSConnectComplete(rv);
195 break; 205 break;
196 case STATE_TUNNEL_CONNECT: 206 case STATE_TUNNEL_CONNECT:
197 DCHECK_EQ(OK, rv); 207 DCHECK_EQ(OK, rv);
198 rv = DoTunnelConnect(); 208 rv = DoTunnelConnect();
199 break; 209 break;
200 case STATE_TUNNEL_CONNECT_COMPLETE: 210 case STATE_TUNNEL_CONNECT_COMPLETE:
201 rv = DoTunnelConnectComplete(rv); 211 rv = DoTunnelConnectComplete(rv);
202 break; 212 break;
213 case STATE_CREATE_SSL_SOCKET:
214 rv = DoCreateSSLSocket();
215 break;
216 case STATE_CHECK_FOR_RESUME:
217 rv = DoCheckForResume();
218 break;
203 case STATE_SSL_CONNECT: 219 case STATE_SSL_CONNECT:
204 DCHECK_EQ(OK, rv); 220 DCHECK_EQ(OK, rv);
205 rv = DoSSLConnect(); 221 rv = DoSSLConnect();
206 break; 222 break;
207 case STATE_SSL_CONNECT_COMPLETE: 223 case STATE_SSL_CONNECT_COMPLETE:
208 rv = DoSSLConnectComplete(rv); 224 rv = DoSSLConnectComplete(rv);
209 break; 225 break;
210 default: 226 default:
211 NOTREACHED() << "bad state"; 227 NOTREACHED() << "bad state";
212 rv = ERR_FAILED; 228 rv = ERR_FAILED;
213 break; 229 break;
214 } 230 }
215 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); 231 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
216 232
217 return rv; 233 return rv;
218 } 234 }
219 235
220 int SSLConnectJob::DoTransportConnect() { 236 int SSLConnectJob::DoTransportConnect() {
221 DCHECK(transport_pool_); 237 DCHECK(transport_pool_);
222 238
223 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; 239 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE;
224 transport_socket_handle_.reset(new ClientSocketHandle()); 240 transport_socket_handle_.reset(new ClientSocketHandle());
225 scoped_refptr<TransportSocketParams> direct_params = 241 scoped_refptr<TransportSocketParams> direct_params =
226 params_->GetDirectConnectionParams(); 242 params_->GetDirectConnectionParams();
227 return transport_socket_handle_->Init(group_name(), 243 return transport_socket_handle_->Init(group_name(),
228 direct_params, 244 direct_params,
229 priority(), 245 priority(),
230 callback_, 246 io_callback_,
231 transport_pool_, 247 transport_pool_,
232 net_log()); 248 net_log());
233 } 249 }
234 250
235 int SSLConnectJob::DoTransportConnectComplete(int result) { 251 int SSLConnectJob::DoTransportConnectComplete(int result) {
236 if (result == OK) 252 if (result != OK)
237 next_state_ = STATE_SSL_CONNECT; 253 return result;
254
255 next_state_ = STATE_CREATE_SSL_SOCKET;
238 256
239 return result; 257 return result;
240 } 258 }
241 259
242 int SSLConnectJob::DoSOCKSConnect() { 260 int SSLConnectJob::DoSOCKSConnect() {
243 DCHECK(socks_pool_); 261 DCHECK(socks_pool_);
244 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; 262 next_state_ = STATE_SOCKS_CONNECT_COMPLETE;
245 transport_socket_handle_.reset(new ClientSocketHandle()); 263 transport_socket_handle_.reset(new ClientSocketHandle());
246 scoped_refptr<SOCKSSocketParams> socks_proxy_params = 264 scoped_refptr<SOCKSSocketParams> socks_proxy_params =
247 params_->GetSocksProxyConnectionParams(); 265 params_->GetSocksProxyConnectionParams();
248 return transport_socket_handle_->Init(group_name(), 266 return transport_socket_handle_->Init(group_name(),
249 socks_proxy_params, 267 socks_proxy_params,
250 priority(), 268 priority(),
251 callback_, 269 io_callback_,
252 socks_pool_, 270 socks_pool_,
253 net_log()); 271 net_log());
254 } 272 }
255 273
256 int SSLConnectJob::DoSOCKSConnectComplete(int result) { 274 int SSLConnectJob::DoSOCKSConnectComplete(int result) {
257 if (result == OK) 275 if (result == OK) {
258 next_state_ = STATE_SSL_CONNECT; 276 next_state_ = STATE_CREATE_SSL_SOCKET;
277 }
wtc 2014/06/17 17:44:40 Nit: omit the curly braces if the if statement's c
mshelley1 2014/06/18 18:53:50 Done.
259 278
260 return result; 279 return result;
261 } 280 }
262 281
263 int SSLConnectJob::DoTunnelConnect() { 282 int SSLConnectJob::DoTunnelConnect() {
264 DCHECK(http_proxy_pool_); 283 DCHECK(http_proxy_pool_);
265 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; 284 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE;
266 285
267 transport_socket_handle_.reset(new ClientSocketHandle()); 286 transport_socket_handle_.reset(new ClientSocketHandle());
268 scoped_refptr<HttpProxySocketParams> http_proxy_params = 287 scoped_refptr<HttpProxySocketParams> http_proxy_params =
269 params_->GetHttpProxyConnectionParams(); 288 params_->GetHttpProxyConnectionParams();
270 return transport_socket_handle_->Init(group_name(), 289 return transport_socket_handle_->Init(group_name(),
271 http_proxy_params, 290 http_proxy_params,
272 priority(), 291 priority(),
273 callback_, 292 io_callback_,
274 http_proxy_pool_, 293 http_proxy_pool_,
275 net_log()); 294 net_log());
276 } 295 }
277 296
278 int SSLConnectJob::DoTunnelConnectComplete(int result) { 297 int SSLConnectJob::DoTunnelConnectComplete(int result) {
279 // Extract the information needed to prompt for appropriate proxy 298 // Extract the information needed to prompt for appropriate proxy
280 // authentication so that when ClientSocketPoolBaseHelper calls 299 // authentication so that when ClientSocketPoolBaseHelper calls
281 // |GetAdditionalErrorState|, we can easily set the state. 300 // |GetAdditionalErrorState|, we can easily set the state.
282 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { 301 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) {
283 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); 302 error_response_info_ = transport_socket_handle_->ssl_error_response_info();
284 } else if (result == ERR_PROXY_AUTH_REQUESTED || 303 } else if (result == ERR_PROXY_AUTH_REQUESTED ||
285 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { 304 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) {
286 StreamSocket* socket = transport_socket_handle_->socket(); 305 StreamSocket* socket = transport_socket_handle_->socket();
287 HttpProxyClientSocket* tunnel_socket = 306 HttpProxyClientSocket* tunnel_socket =
288 static_cast<HttpProxyClientSocket*>(socket); 307 static_cast<HttpProxyClientSocket*>(socket);
289 error_response_info_ = *tunnel_socket->GetConnectResponseInfo(); 308 error_response_info_ = *tunnel_socket->GetConnectResponseInfo();
290 } 309 }
291 if (result < 0) 310 if (result < 0)
292 return result; 311 return result;
312 next_state_ = STATE_CREATE_SSL_SOCKET;
293 313
294 next_state_ = STATE_SSL_CONNECT;
295 return result; 314 return result;
296 } 315 }
297 316
298 int SSLConnectJob::DoSSLConnect() { 317 int SSLConnectJob::DoCreateSSLSocket() {
299 next_state_ = STATE_SSL_CONNECT_COMPLETE; 318 if (enable_job_waiting_)
319 next_state_ = STATE_CHECK_FOR_RESUME;
320 else
321 next_state_ = STATE_SSL_CONNECT;
300 // Reset the timeout to just the time allowed for the SSL handshake. 322 // Reset the timeout to just the time allowed for the SSL handshake.
301 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); 323 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds));
302 324
303 // If the handle has a fresh socket, get its connect start and DNS times. 325 // If the handle has a fresh socket, get its connect start and DNS times.
304 // This should always be the case. 326 // This should always be the case.
305 const LoadTimingInfo::ConnectTiming& socket_connect_timing = 327 const LoadTimingInfo::ConnectTiming& socket_connect_timing =
306 transport_socket_handle_->connect_timing(); 328 transport_socket_handle_->connect_timing();
307 if (!transport_socket_handle_->is_reused() && 329 if (!transport_socket_handle_->is_reused() &&
308 !socket_connect_timing.connect_start.is_null()) { 330 !socket_connect_timing.connect_start.is_null()) {
309 // Overwriting |connect_start| serves two purposes - it adjusts timing so
310 // |connect_start| doesn't include dns times, and it adjusts the time so
311 // as not to include time spent waiting for an idle socket.
312 connect_timing_.connect_start = socket_connect_timing.connect_start; 331 connect_timing_.connect_start = socket_connect_timing.connect_start;
313 connect_timing_.dns_start = socket_connect_timing.dns_start; 332 connect_timing_.dns_start = socket_connect_timing.dns_start;
314 connect_timing_.dns_end = socket_connect_timing.dns_end; 333 connect_timing_.dns_end = socket_connect_timing.dns_end;
315 } 334 }
316 335
317 connect_timing_.ssl_start = base::TimeTicks::Now();
318
319 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket( 336 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket(
320 transport_socket_handle_.Pass(), 337 transport_socket_handle_.Pass(),
321 params_->host_and_port(), 338 params_->host_and_port(),
322 params_->ssl_config(), 339 params_->ssl_config(),
323 context_); 340 context_);
324 return ssl_socket_->Connect(callback_); 341 return OK;
342 }
343
344 int SSLConnectJob::DoCheckForResume() {
345 // If the group is in the cache, continue.
wtc 2014/06/17 17:44:40 This comment should point out that this SSL handsh
mshelley1 2014/06/18 18:53:49 Done.
346 if (ssl_socket_->InSessionCache()) {
347 next_state_ = STATE_SSL_CONNECT;
348 return OK;
349 }
350
351 // If there are pending jobs, wait.
352 if (!pending_jobs_->empty()) {
353 pending_jobs_->push_back(this);
354 next_state_ = STATE_CHECK_FOR_RESUME;
355 return ERR_IO_PENDING;
356 }
357
358 // If there are no pending jobs, continue
wtc 2014/06/17 17:44:40 Nit: it would be good to elaborate in this comment
mshelley1 2014/06/18 18:53:49 Done.
359 pending_jobs_->push_back(this);
360 next_state_ = STATE_SSL_CONNECT;
361 return OK;
362 }
363
364 int SSLConnectJob::DoSSLConnect() {
365 next_state_ = STATE_SSL_CONNECT_COMPLETE;
366 // Overwriting |connect_start| serves two purposes - it adjusts timing so
367 // |connect_start| doesn't include dns times, and it adjusts the time so
368 // as not to include time spent waiting for an idle socket.
wtc 2014/06/17 17:44:40 This comment was copied here by mistake. Please mo
mshelley1 2014/06/18 18:53:49 Done.
369
370 connect_timing_.ssl_start = base::TimeTicks::Now();
371
372 return ssl_socket_->Connect(io_callback_);
325 } 373 }
326 374
327 int SSLConnectJob::DoSSLConnectComplete(int result) { 375 int SSLConnectJob::DoSSLConnectComplete(int result) {
328 connect_timing_.ssl_end = base::TimeTicks::Now(); 376 connect_timing_.ssl_end = base::TimeTicks::Now();
329 377
330 SSLClientSocket::NextProtoStatus status = 378 SSLClientSocket::NextProtoStatus status =
331 SSLClientSocket::kNextProtoUnsupported; 379 SSLClientSocket::kNextProtoUnsupported;
332 std::string proto; 380 std::string proto;
333 std::string server_protos; 381 std::string server_protos;
334 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket 382 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket
(...skipping 10 matching lines...) Expand all
345 ssl_socket_->set_protocol_negotiated(protocol_negotiated); 393 ssl_socket_->set_protocol_negotiated(protocol_negotiated);
346 // If we negotiated a SPDY version, it must have been present in 394 // If we negotiated a SPDY version, it must have been present in
347 // SSLConfig::next_protos. 395 // SSLConfig::next_protos.
348 // TODO(mbelshe): Verify this. 396 // TODO(mbelshe): Verify this.
349 if (protocol_negotiated >= kProtoSPDYMinimumVersion && 397 if (protocol_negotiated >= kProtoSPDYMinimumVersion &&
350 protocol_negotiated <= kProtoSPDYMaximumVersion) { 398 protocol_negotiated <= kProtoSPDYMaximumVersion) {
351 ssl_socket_->set_was_spdy_negotiated(true); 399 ssl_socket_->set_was_spdy_negotiated(true);
352 } 400 }
353 } 401 }
354 if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated()) 402 if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated())
355 return ERR_NPN_NEGOTIATION_FAILED; 403 return ERR_NPN_NEGOTIATION_FAILED;
wtc 2014/06/17 17:44:40 IMPORTANT: Do we need to wake up the pending jobs
mshelley1 2014/06/18 18:53:50 Yes we do -- I believe I can just call the Process
356 404
357 // Spdy might be turned on by default, or it might be over npn. 405 // Spdy might be turned on by default, or it might be over npn.
358 bool using_spdy = params_->force_spdy_over_ssl() || 406 bool using_spdy = params_->force_spdy_over_ssl() ||
359 params_->want_spdy_over_npn(); 407 params_->want_spdy_over_npn();
360 408
361 if (result == OK || 409 if (result == OK ||
362 ssl_socket_->IgnoreCertError(result, params_->load_flags())) { 410 ssl_socket_->IgnoreCertError(result, params_->load_flags())) {
363 DCHECK(!connect_timing_.ssl_start.is_null()); 411 DCHECK(!connect_timing_.ssl_start.is_null());
364 base::TimeDelta connect_duration = 412 base::TimeDelta connect_duration =
365 connect_timing_.ssl_end - connect_timing_.ssl_start; 413 connect_timing_.ssl_end - connect_timing_.ssl_start;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 100); 452 100);
405 } else if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_FULL) { 453 } else if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_FULL) {
406 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Full_Handshake", 454 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Full_Handshake",
407 connect_duration, 455 connect_duration,
408 base::TimeDelta::FromMilliseconds(1), 456 base::TimeDelta::FromMilliseconds(1),
409 base::TimeDelta::FromMinutes(1), 457 base::TimeDelta::FromMinutes(1),
410 100); 458 100);
411 } 459 }
412 460
413 const std::string& host = params_->host_and_port().host(); 461 const std::string& host = params_->host_and_port().host();
414 bool is_google = host == "google.com" || 462 bool is_google =
415 (host.size() > 11 && 463 host == "google.com" ||
416 host.rfind(".google.com") == host.size() - 11); 464 (host.size() > 11 && host.rfind(".google.com") == host.size() - 11);
417 if (is_google) { 465 if (is_google) {
418 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2", 466 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2",
419 connect_duration, 467 connect_duration,
420 base::TimeDelta::FromMilliseconds(1), 468 base::TimeDelta::FromMilliseconds(1),
421 base::TimeDelta::FromMinutes(1), 469 base::TimeDelta::FromMinutes(1),
422 100); 470 100);
423 if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME) { 471 if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME) {
424 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_" 472 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_"
425 "Resume_Handshake", 473 "Resume_Handshake",
426 connect_duration, 474 connect_duration,
(...skipping 12 matching lines...) Expand all
439 } 487 }
440 488
441 if (result == OK || IsCertificateError(result)) { 489 if (result == OK || IsCertificateError(result)) {
442 SetSocket(ssl_socket_.PassAs<StreamSocket>()); 490 SetSocket(ssl_socket_.PassAs<StreamSocket>());
443 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { 491 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) {
444 error_response_info_.cert_request_info = new SSLCertRequestInfo; 492 error_response_info_.cert_request_info = new SSLCertRequestInfo;
445 ssl_socket_->GetSSLCertRequestInfo( 493 ssl_socket_->GetSSLCertRequestInfo(
446 error_response_info_.cert_request_info.get()); 494 error_response_info_.cert_request_info.get());
447 } 495 }
448 496
497 if (enable_job_waiting_) {
498 ProcessPendingJobs(result);
499 }
wtc 2014/06/17 17:44:40 Nit: omit curly braces.
mshelley1 2014/06/18 18:53:50 Done.
500
449 return result; 501 return result;
450 } 502 }
451 503
504 void SSLConnectJob::ProcessPendingJobs(int result) {
505 // If there is a pending list
506 if (!pending_jobs_->empty()) {
507 // The first element of the vector will always be the leading job.
508 PendingJobList::iterator i = pending_jobs_->begin();
wtc 2014/06/17 17:44:40 Nit: name the iterator |it| or |iter|.
mshelley1 2014/06/18 18:53:50 Done.
509 // If the connection was successful, tell all pending jobs to proceed.
510 if (result == OK) {
511 for (PendingJobList::iterator job = i + 1; job != pending_jobs_->end();
512 ++job) {
513 (*job)->ResumeSSLConnection();
514 }
515 pending_jobs_->clear();
516 }
517 // If the connection failed, tell only one job to proceed as the new
518 // leader.
519 else if (i + 1 != pending_jobs_->end()) {
520 (*(i + 1))->ResumeSSLConnection();
521 pending_jobs_->erase(i);
522 }
523 // If there are no more jobs and the leader failed, delete the entry.
524 else
wtc 2014/06/17 17:44:40 On lines 519 and 524, the else should follow the p
mshelley1 2014/06/18 18:53:49 Done.
525 pending_jobs_->erase(i);
wtc 2014/06/17 17:44:40 Nit: I think this if-else-if-else statement can be
mshelley1 2014/06/18 18:53:50 I decided to go with your first suggestion. The se
526 }
527 }
528
529 void SSLConnectJob::ResumeSSLConnection() {
530 next_state_ = STATE_SSL_CONNECT;
wtc 2014/06/17 17:44:40 Please add DCHECK_EQ(next_state_, STATE_CHECK_FO
mshelley1 2014/06/18 18:53:50 Done.
531 OnIOComplete(OK);
532 }
533
534 std::string SSLConnectJob::GetSessionCacheKey() {
535 return params_->host_and_port().ToString() + "/" +
536 context_.ssl_session_cache_shard;
537 }
538
452 SSLConnectJob::State SSLConnectJob::GetInitialState( 539 SSLConnectJob::State SSLConnectJob::GetInitialState(
453 SSLSocketParams::ConnectionType connection_type) { 540 SSLSocketParams::ConnectionType connection_type) {
454 switch (connection_type) { 541 switch (connection_type) {
455 case SSLSocketParams::DIRECT: 542 case SSLSocketParams::DIRECT:
456 return STATE_TRANSPORT_CONNECT; 543 return STATE_TRANSPORT_CONNECT;
457 case SSLSocketParams::HTTP_PROXY: 544 case SSLSocketParams::HTTP_PROXY:
458 return STATE_TUNNEL_CONNECT; 545 return STATE_TUNNEL_CONNECT;
459 case SSLSocketParams::SOCKS_PROXY: 546 case SSLSocketParams::SOCKS_PROXY:
460 return STATE_SOCKS_CONNECT; 547 return STATE_SOCKS_CONNECT;
461 } 548 }
(...skipping 13 matching lines...) Expand all
475 ClientSocketFactory* client_socket_factory, 562 ClientSocketFactory* client_socket_factory,
476 HostResolver* host_resolver, 563 HostResolver* host_resolver,
477 const SSLClientSocketContext& context, 564 const SSLClientSocketContext& context,
478 NetLog* net_log) 565 NetLog* net_log)
479 : transport_pool_(transport_pool), 566 : transport_pool_(transport_pool),
480 socks_pool_(socks_pool), 567 socks_pool_(socks_pool),
481 http_proxy_pool_(http_proxy_pool), 568 http_proxy_pool_(http_proxy_pool),
482 client_socket_factory_(client_socket_factory), 569 client_socket_factory_(client_socket_factory),
483 host_resolver_(host_resolver), 570 host_resolver_(host_resolver),
484 context_(context), 571 context_(context),
485 net_log_(net_log) { 572 net_log_(net_log),
573 pending_jobs_(new PendingJobMap()) {
wtc 2014/06/17 17:44:40 BUG: this PendingJobMap object is leaked. We shoul
mshelley1 2014/06/18 18:53:49 As you implied in your comment on the .h file, mak
wtc 2014/06/19 19:38:10 Yes, it is. But I suggested a better solution.
486 base::TimeDelta max_transport_timeout = base::TimeDelta(); 574 base::TimeDelta max_transport_timeout = base::TimeDelta();
487 base::TimeDelta pool_timeout; 575 base::TimeDelta pool_timeout;
488 if (transport_pool_) 576 if (transport_pool_)
489 max_transport_timeout = transport_pool_->ConnectionTimeout(); 577 max_transport_timeout = transport_pool_->ConnectionTimeout();
490 if (socks_pool_) { 578 if (socks_pool_) {
491 pool_timeout = socks_pool_->ConnectionTimeout(); 579 pool_timeout = socks_pool_->ConnectionTimeout();
492 if (pool_timeout > max_transport_timeout) 580 if (pool_timeout > max_transport_timeout)
493 max_transport_timeout = pool_timeout; 581 max_transport_timeout = pool_timeout;
494 } 582 }
495 if (http_proxy_pool_) { 583 if (http_proxy_pool_) {
(...skipping 17 matching lines...) Expand all
513 const std::string& ssl_session_cache_shard, 601 const std::string& ssl_session_cache_shard,
514 ClientSocketFactory* client_socket_factory, 602 ClientSocketFactory* client_socket_factory,
515 TransportClientSocketPool* transport_pool, 603 TransportClientSocketPool* transport_pool,
516 SOCKSClientSocketPool* socks_pool, 604 SOCKSClientSocketPool* socks_pool,
517 HttpProxyClientSocketPool* http_proxy_pool, 605 HttpProxyClientSocketPool* http_proxy_pool,
518 SSLConfigService* ssl_config_service, 606 SSLConfigService* ssl_config_service,
519 NetLog* net_log) 607 NetLog* net_log)
520 : transport_pool_(transport_pool), 608 : transport_pool_(transport_pool),
521 socks_pool_(socks_pool), 609 socks_pool_(socks_pool),
522 http_proxy_pool_(http_proxy_pool), 610 http_proxy_pool_(http_proxy_pool),
523 base_(this, max_sockets, max_sockets_per_group, histograms, 611 base_(this,
612 max_sockets,
613 max_sockets_per_group,
614 histograms,
524 ClientSocketPool::unused_idle_socket_timeout(), 615 ClientSocketPool::unused_idle_socket_timeout(),
525 ClientSocketPool::used_idle_socket_timeout(), 616 ClientSocketPool::used_idle_socket_timeout(),
526 new SSLConnectJobFactory(transport_pool, 617 new SSLConnectJobFactory(
527 socks_pool, 618 transport_pool,
528 http_proxy_pool, 619 socks_pool,
529 client_socket_factory, 620 http_proxy_pool,
530 host_resolver, 621 client_socket_factory,
531 SSLClientSocketContext( 622 host_resolver,
532 cert_verifier, 623 SSLClientSocketContext(cert_verifier,
533 server_bound_cert_service, 624 server_bound_cert_service,
534 transport_security_state, 625 transport_security_state,
535 cert_transparency_verifier, 626 cert_transparency_verifier,
536 ssl_session_cache_shard), 627 ssl_session_cache_shard),
537 net_log)), 628 net_log)),
538 ssl_config_service_(ssl_config_service) { 629 ssl_config_service_(ssl_config_service) {
539 if (ssl_config_service_.get()) 630 if (ssl_config_service_.get())
540 ssl_config_service_->AddObserver(this); 631 ssl_config_service_->AddObserver(this);
541 if (transport_pool_) 632 if (transport_pool_)
542 base_.AddLowerLayeredPool(transport_pool_); 633 base_.AddLowerLayeredPool(transport_pool_);
543 if (socks_pool_) 634 if (socks_pool_)
544 base_.AddLowerLayeredPool(socks_pool_); 635 base_.AddLowerLayeredPool(socks_pool_);
545 if (http_proxy_pool_) 636 if (http_proxy_pool_)
546 base_.AddLowerLayeredPool(http_proxy_pool_); 637 base_.AddLowerLayeredPool(http_proxy_pool_);
547 } 638 }
548 639
549 SSLClientSocketPool::~SSLClientSocketPool() { 640 SSLClientSocketPool::~SSLClientSocketPool() {
550 if (ssl_config_service_.get()) 641 if (ssl_config_service_.get())
551 ssl_config_service_->RemoveObserver(this); 642 ssl_config_service_->RemoveObserver(this);
552 } 643 }
553 644
554 scoped_ptr<ConnectJob> 645 scoped_ptr<ConnectJob>
555 SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( 646 SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob(
556 const std::string& group_name, 647 const std::string& group_name,
557 const PoolBase::Request& request, 648 const PoolBase::Request& request,
558 ConnectJob::Delegate* delegate) const { 649 ConnectJob::Delegate* delegate) const {
559 return scoped_ptr<ConnectJob>( 650 SSLConnectJob::PendingJobList* pending_job_list;
560 new SSLConnectJob(group_name, request.priority(), request.params(), 651 std::pair<PendingJobMap::iterator, bool> it =
561 ConnectionTimeout(), transport_pool_, socks_pool_, 652 pending_jobs_->insert(PendingJobMap::value_type(
562 http_proxy_pool_, client_socket_factory_, 653 group_name, new SSLConnectJob::PendingJobList()));
wtc 2014/06/17 17:44:40 IMPORTANT: it seems wrong to create a new SSLConne
mshelley1 2014/06/18 18:53:49 If I understand the documentation for std::map::in
Ryan Sleevi 2014/06/19 20:20:43 So, it's a little complicated: .insert() will alw
563 host_resolver_, context_, delegate, net_log_)); 654 pending_job_list = it.first->second;
655
656 return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name,
657 request.priority(),
658 request.params(),
659 ConnectionTimeout(),
660 transport_pool_,
661 socks_pool_,
662 http_proxy_pool_,
663 client_socket_factory_,
664 host_resolver_,
665 context_,
666 delegate,
667 net_log_,
668 pending_job_list));
564 } 669 }
565 670
566 base::TimeDelta 671 base::TimeDelta
567 SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() const { 672 SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() const {
568 return timeout_; 673 return timeout_;
569 } 674 }
570 675
571 int SSLClientSocketPool::RequestSocket(const std::string& group_name, 676 int SSLClientSocketPool::RequestSocket(const std::string& group_name,
572 const void* socket_params, 677 const void* socket_params,
573 RequestPriority priority, 678 RequestPriority priority,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 if (base_.CloseOneIdleSocket()) 782 if (base_.CloseOneIdleSocket())
678 return true; 783 return true;
679 return base_.CloseOneIdleConnectionInHigherLayeredPool(); 784 return base_.CloseOneIdleConnectionInHigherLayeredPool();
680 } 785 }
681 786
682 void SSLClientSocketPool::OnSSLConfigChanged() { 787 void SSLClientSocketPool::OnSSLConfigChanged() {
683 FlushWithError(ERR_NETWORK_CHANGED); 788 FlushWithError(ERR_NETWORK_CHANGED);
684 } 789 }
685 790
686 } // namespace net 791 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698