OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/socket/ssl_client_socket_pool.h" | 5 #include "net/socket/ssl_client_socket_pool.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 SSLConnectJob::SSLConnectJob(const std::string& group_name, | 100 SSLConnectJob::SSLConnectJob(const std::string& group_name, |
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 PendingJobList* pending_jobs_list, | |
110 Delegate* delegate, | 111 Delegate* delegate, |
111 NetLog* net_log) | 112 NetLog* net_log) |
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_jobs_list) { | |
134 } | |
132 | 135 |
133 SSLConnectJob::~SSLConnectJob() {} | 136 SSLConnectJob::~SSLConnectJob() {} |
134 | 137 |
138 // static | |
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_CREATE_SSL_SOCKET: | |
154 case STATE_CHECK_FOR_RESUME: | |
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_CREATE_SSL_SOCKET: | |
216 rv = DoCreateSSLSocket(); | |
217 break; | |
218 case STATE_CHECK_FOR_RESUME: | |
219 rv = DoCheckForResume(); | |
220 break; | |
203 case STATE_SSL_CONNECT: | 221 case STATE_SSL_CONNECT: |
204 DCHECK_EQ(OK, rv); | 222 DCHECK_EQ(OK, rv); |
205 rv = DoSSLConnect(); | 223 rv = DoSSLConnect(); |
206 break; | 224 break; |
207 case STATE_SSL_CONNECT_COMPLETE: | 225 case STATE_SSL_CONNECT_COMPLETE: |
208 rv = DoSSLConnectComplete(rv); | 226 rv = DoSSLConnectComplete(rv); |
209 break; | 227 break; |
228 case STATE_PROCESS_PENDING_JOBS: | |
229 rv = DoProcessPendingJobs(rv); | |
230 break; | |
210 default: | 231 default: |
211 NOTREACHED() << "bad state"; | 232 NOTREACHED() << "bad state"; |
212 rv = ERR_FAILED; | 233 rv = ERR_FAILED; |
213 break; | 234 break; |
214 } | 235 } |
215 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 236 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
216 | 237 |
217 return rv; | 238 return rv; |
218 } | 239 } |
219 | 240 |
220 int SSLConnectJob::DoTransportConnect() { | 241 int SSLConnectJob::DoTransportConnect() { |
221 DCHECK(transport_pool_); | 242 DCHECK(transport_pool_); |
222 | 243 |
223 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; | 244 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; |
224 transport_socket_handle_.reset(new ClientSocketHandle()); | 245 transport_socket_handle_.reset(new ClientSocketHandle()); |
225 scoped_refptr<TransportSocketParams> direct_params = | 246 scoped_refptr<TransportSocketParams> direct_params = |
226 params_->GetDirectConnectionParams(); | 247 params_->GetDirectConnectionParams(); |
227 return transport_socket_handle_->Init(group_name(), | 248 return transport_socket_handle_->Init(group_name(), |
228 direct_params, | 249 direct_params, |
229 priority(), | 250 priority(), |
230 callback_, | 251 io_callback_, |
231 transport_pool_, | 252 transport_pool_, |
232 net_log()); | 253 net_log()); |
233 } | 254 } |
234 | 255 |
235 int SSLConnectJob::DoTransportConnectComplete(int result) { | 256 int SSLConnectJob::DoTransportConnectComplete(int result) { |
236 if (result == OK) | 257 if (result != OK) |
237 next_state_ = STATE_SSL_CONNECT; | 258 return result; |
259 | |
260 next_state_ = STATE_CREATE_SSL_SOCKET; | |
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 io_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 return result; |
282 | |
283 next_state_ = STATE_CREATE_SSL_SOCKET; | |
259 | 284 |
260 return result; | 285 return result; |
261 } | 286 } |
262 | 287 |
263 int SSLConnectJob::DoTunnelConnect() { | 288 int SSLConnectJob::DoTunnelConnect() { |
264 DCHECK(http_proxy_pool_); | 289 DCHECK(http_proxy_pool_); |
265 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; | 290 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; |
266 | 291 |
267 transport_socket_handle_.reset(new ClientSocketHandle()); | 292 transport_socket_handle_.reset(new ClientSocketHandle()); |
268 scoped_refptr<HttpProxySocketParams> http_proxy_params = | 293 scoped_refptr<HttpProxySocketParams> http_proxy_params = |
269 params_->GetHttpProxyConnectionParams(); | 294 params_->GetHttpProxyConnectionParams(); |
270 return transport_socket_handle_->Init(group_name(), | 295 return transport_socket_handle_->Init(group_name(), |
271 http_proxy_params, | 296 http_proxy_params, |
272 priority(), | 297 priority(), |
273 callback_, | 298 io_callback_, |
274 http_proxy_pool_, | 299 http_proxy_pool_, |
275 net_log()); | 300 net_log()); |
276 } | 301 } |
277 | 302 |
278 int SSLConnectJob::DoTunnelConnectComplete(int result) { | 303 int SSLConnectJob::DoTunnelConnectComplete(int result) { |
279 // Extract the information needed to prompt for appropriate proxy | 304 // Extract the information needed to prompt for appropriate proxy |
280 // authentication so that when ClientSocketPoolBaseHelper calls | 305 // authentication so that when ClientSocketPoolBaseHelper calls |
281 // |GetAdditionalErrorState|, we can easily set the state. | 306 // |GetAdditionalErrorState|, we can easily set the state. |
282 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 307 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
283 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); | 308 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); |
284 } else if (result == ERR_PROXY_AUTH_REQUESTED || | 309 } else if (result == ERR_PROXY_AUTH_REQUESTED || |
285 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { | 310 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { |
286 StreamSocket* socket = transport_socket_handle_->socket(); | 311 StreamSocket* socket = transport_socket_handle_->socket(); |
287 HttpProxyClientSocket* tunnel_socket = | 312 HttpProxyClientSocket* tunnel_socket = |
288 static_cast<HttpProxyClientSocket*>(socket); | 313 static_cast<HttpProxyClientSocket*>(socket); |
289 error_response_info_ = *tunnel_socket->GetConnectResponseInfo(); | 314 error_response_info_ = *tunnel_socket->GetConnectResponseInfo(); |
290 } | 315 } |
291 if (result < 0) | 316 if (result < 0) |
292 return result; | 317 return result; |
293 | 318 |
294 next_state_ = STATE_SSL_CONNECT; | 319 next_state_ = STATE_CREATE_SSL_SOCKET; |
295 return result; | 320 return result; |
296 } | 321 } |
297 | 322 |
298 int SSLConnectJob::DoSSLConnect() { | 323 int SSLConnectJob::DoCreateSSLSocket() { |
299 next_state_ = STATE_SSL_CONNECT_COMPLETE; | 324 if (enable_job_waiting_) |
325 next_state_ = STATE_CHECK_FOR_RESUME; | |
326 else | |
327 next_state_ = STATE_SSL_CONNECT; | |
300 // Reset the timeout to just the time allowed for the SSL handshake. | 328 // Reset the timeout to just the time allowed for the SSL handshake. |
301 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); | 329 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); |
302 | 330 |
303 // If the handle has a fresh socket, get its connect start and DNS times. | 331 // If the handle has a fresh socket, get its connect start and DNS times. |
304 // This should always be the case. | 332 // This should always be the case. |
305 const LoadTimingInfo::ConnectTiming& socket_connect_timing = | 333 const LoadTimingInfo::ConnectTiming& socket_connect_timing = |
306 transport_socket_handle_->connect_timing(); | 334 transport_socket_handle_->connect_timing(); |
307 if (!transport_socket_handle_->is_reused() && | 335 if (!transport_socket_handle_->is_reused() && |
308 !socket_connect_timing.connect_start.is_null()) { | 336 !socket_connect_timing.connect_start.is_null()) { |
309 // Overwriting |connect_start| serves two purposes - it adjusts timing so | 337 // Overwriting |connect_start| serves two purposes - it adjusts timing so |
310 // |connect_start| doesn't include dns times, and it adjusts the time so | 338 // |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. | 339 // as not to include time spent waiting for an idle socket. |
312 connect_timing_.connect_start = socket_connect_timing.connect_start; | 340 connect_timing_.connect_start = socket_connect_timing.connect_start; |
313 connect_timing_.dns_start = socket_connect_timing.dns_start; | 341 connect_timing_.dns_start = socket_connect_timing.dns_start; |
314 connect_timing_.dns_end = socket_connect_timing.dns_end; | 342 connect_timing_.dns_end = socket_connect_timing.dns_end; |
315 } | 343 } |
316 | 344 |
317 connect_timing_.ssl_start = base::TimeTicks::Now(); | |
318 | |
319 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket( | 345 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket( |
320 transport_socket_handle_.Pass(), | 346 transport_socket_handle_.Pass(), |
321 params_->host_and_port(), | 347 params_->host_and_port(), |
322 params_->ssl_config(), | 348 params_->ssl_config(), |
323 context_); | 349 context_); |
324 return ssl_socket_->Connect(callback_); | 350 return OK; |
351 } | |
352 | |
353 int SSLConnectJob::DoCheckForResume() { | |
354 // If the group's session is in the cache, continue with the session | |
355 // resumption SSL handshake. | |
wtc
2014/06/26 17:48:17
Move this comment to line 358.
| |
356 next_state_ = STATE_SSL_CONNECT; | |
357 | |
358 if (ssl_socket_->InSessionCache()) | |
359 return OK; | |
360 | |
361 // If there are pending jobs, wait. | |
362 if (!pending_jobs_->empty()) { | |
363 pending_jobs_->push_back(this); | |
364 return ERR_IO_PENDING; | |
365 } | |
366 | |
367 // If there are no pending jobs, continue the full SSL handshake | |
368 // because a resumption handshake is not possible. | |
369 // | |
370 // Add |this| to pending jobs to ensure that future jobs | |
371 // will know that there is a job in progress. | |
372 pending_jobs_->push_back(this); | |
373 return OK; | |
wtc
2014/06/26 17:48:17
Nit: it is possible to rewrite lines 361-373 to el
| |
374 } | |
375 | |
376 int SSLConnectJob::DoSSLConnect() { | |
377 next_state_ = STATE_SSL_CONNECT_COMPLETE; | |
378 | |
379 connect_timing_.ssl_start = base::TimeTicks::Now(); | |
380 | |
381 return ssl_socket_->Connect(io_callback_); | |
325 } | 382 } |
326 | 383 |
327 int SSLConnectJob::DoSSLConnectComplete(int result) { | 384 int SSLConnectJob::DoSSLConnectComplete(int result) { |
328 connect_timing_.ssl_end = base::TimeTicks::Now(); | 385 connect_timing_.ssl_end = base::TimeTicks::Now(); |
329 | 386 |
387 if (enable_job_waiting_) | |
388 next_state_ = STATE_PROCESS_PENDING_JOBS; | |
389 | |
330 SSLClientSocket::NextProtoStatus status = | 390 SSLClientSocket::NextProtoStatus status = |
331 SSLClientSocket::kNextProtoUnsupported; | 391 SSLClientSocket::kNextProtoUnsupported; |
332 std::string proto; | 392 std::string proto; |
333 std::string server_protos; | 393 std::string server_protos; |
334 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket | 394 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket |
335 // that hasn't had SSL_ImportFD called on it. If we get a certificate error | 395 // that hasn't had SSL_ImportFD called on it. If we get a certificate error |
336 // here, then we know that we called SSL_ImportFD. | 396 // here, then we know that we called SSL_ImportFD. |
337 if (result == OK || IsCertificateError(result)) | 397 if (result == OK || IsCertificateError(result)) |
338 status = ssl_socket_->GetNextProto(&proto, &server_protos); | 398 status = ssl_socket_->GetNextProto(&proto, &server_protos); |
339 | 399 |
340 // If we want spdy over npn, make sure it succeeded. | 400 // If we want spdy over npn, make sure it succeeded. |
341 if (status == SSLClientSocket::kNextProtoNegotiated) { | 401 if (status == SSLClientSocket::kNextProtoNegotiated) { |
342 ssl_socket_->set_was_npn_negotiated(true); | 402 ssl_socket_->set_was_npn_negotiated(true); |
343 NextProto protocol_negotiated = | 403 NextProto protocol_negotiated = |
344 SSLClientSocket::NextProtoFromString(proto); | 404 SSLClientSocket::NextProtoFromString(proto); |
345 ssl_socket_->set_protocol_negotiated(protocol_negotiated); | 405 ssl_socket_->set_protocol_negotiated(protocol_negotiated); |
346 // If we negotiated a SPDY version, it must have been present in | 406 // If we negotiated a SPDY version, it must have been present in |
347 // SSLConfig::next_protos. | 407 // SSLConfig::next_protos. |
348 // TODO(mbelshe): Verify this. | 408 // TODO(mbelshe): Verify this. |
349 if (protocol_negotiated >= kProtoSPDYMinimumVersion && | 409 if (protocol_negotiated >= kProtoSPDYMinimumVersion && |
350 protocol_negotiated <= kProtoSPDYMaximumVersion) { | 410 protocol_negotiated <= kProtoSPDYMaximumVersion) { |
351 ssl_socket_->set_was_spdy_negotiated(true); | 411 ssl_socket_->set_was_spdy_negotiated(true); |
352 } | 412 } |
353 } | 413 } |
354 if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated()) | 414 if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated()) { |
355 return ERR_NPN_NEGOTIATION_FAILED; | 415 return ERR_NPN_NEGOTIATION_FAILED; |
416 } | |
356 | 417 |
357 // Spdy might be turned on by default, or it might be over npn. | 418 // Spdy might be turned on by default, or it might be over npn. |
358 bool using_spdy = params_->force_spdy_over_ssl() || | 419 bool using_spdy = params_->force_spdy_over_ssl() || |
359 params_->want_spdy_over_npn(); | 420 params_->want_spdy_over_npn(); |
360 | 421 |
361 if (result == OK || | 422 if (result == OK || |
362 ssl_socket_->IgnoreCertError(result, params_->load_flags())) { | 423 ssl_socket_->IgnoreCertError(result, params_->load_flags())) { |
363 DCHECK(!connect_timing_.ssl_start.is_null()); | 424 DCHECK(!connect_timing_.ssl_start.is_null()); |
364 base::TimeDelta connect_duration = | 425 base::TimeDelta connect_duration = |
365 connect_timing_.ssl_end - connect_timing_.ssl_start; | 426 connect_timing_.ssl_end - connect_timing_.ssl_start; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 100); | 465 100); |
405 } else if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_FULL) { | 466 } else if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_FULL) { |
406 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Full_Handshake", | 467 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Full_Handshake", |
407 connect_duration, | 468 connect_duration, |
408 base::TimeDelta::FromMilliseconds(1), | 469 base::TimeDelta::FromMilliseconds(1), |
409 base::TimeDelta::FromMinutes(1), | 470 base::TimeDelta::FromMinutes(1), |
410 100); | 471 100); |
411 } | 472 } |
412 | 473 |
413 const std::string& host = params_->host_and_port().host(); | 474 const std::string& host = params_->host_and_port().host(); |
414 bool is_google = host == "google.com" || | 475 bool is_google = |
415 (host.size() > 11 && | 476 host == "google.com" || |
416 host.rfind(".google.com") == host.size() - 11); | 477 (host.size() > 11 && host.rfind(".google.com") == host.size() - 11); |
417 if (is_google) { | 478 if (is_google) { |
418 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2", | 479 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2", |
419 connect_duration, | 480 connect_duration, |
420 base::TimeDelta::FromMilliseconds(1), | 481 base::TimeDelta::FromMilliseconds(1), |
421 base::TimeDelta::FromMinutes(1), | 482 base::TimeDelta::FromMinutes(1), |
422 100); | 483 100); |
423 if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME) { | 484 if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME) { |
424 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_" | 485 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_" |
425 "Resume_Handshake", | 486 "Resume_Handshake", |
426 connect_duration, | 487 connect_duration, |
(...skipping 15 matching lines...) Expand all Loading... | |
442 SetSocket(ssl_socket_.PassAs<StreamSocket>()); | 503 SetSocket(ssl_socket_.PassAs<StreamSocket>()); |
443 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 504 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
444 error_response_info_.cert_request_info = new SSLCertRequestInfo; | 505 error_response_info_.cert_request_info = new SSLCertRequestInfo; |
445 ssl_socket_->GetSSLCertRequestInfo( | 506 ssl_socket_->GetSSLCertRequestInfo( |
446 error_response_info_.cert_request_info.get()); | 507 error_response_info_.cert_request_info.get()); |
447 } | 508 } |
448 | 509 |
449 return result; | 510 return result; |
450 } | 511 } |
451 | 512 |
513 int SSLConnectJob::DoProcessPendingJobs(int result) { | |
514 ProcessPendingJobs(result); | |
515 return result; | |
516 } | |
517 | |
518 void SSLConnectJob::ProcessPendingJobs(int result) { | |
wtc
2014/06/26 17:48:17
Nit: I would get rid of the ProcessPendingJobs fun
| |
519 // If there is a pending list | |
520 if (!pending_jobs_->empty()) { | |
521 // The first element of the vector will always be the leading job. | |
522 PendingJobList::iterator it = pending_jobs_->begin(); | |
523 | |
524 if (result == OK) { | |
525 // If the connection was successful, tell all pending jobs to proceed. | |
526 PendingJobList pending_jobs(it + 1, pending_jobs_->end()); | |
527 pending_jobs_->clear(); | |
528 for (PendingJobList::iterator job = pending_jobs.begin(); | |
wtc
2014/06/26 17:48:17
Nit: this can be a const_iterator.
| |
529 job != pending_jobs.end(); | |
530 ++job) { | |
531 (*job)->ResumeSSLConnection(); | |
532 } | |
533 | |
534 } else { | |
535 // If the connection failed, tell one (if any) of the remaining jobs | |
536 // to proceed as the new leader. | |
537 it = pending_jobs_->erase(it); | |
538 if (it != pending_jobs_->end()) | |
539 (*it)->ResumeSSLConnection(); | |
540 } | |
541 } | |
542 } | |
543 | |
544 void SSLConnectJob::ResumeSSLConnection() { | |
545 DCHECK_EQ(next_state_, STATE_SSL_CONNECT); | |
546 next_state_ = STATE_SSL_CONNECT; | |
wtc
2014/06/26 17:48:17
Delete this line.
| |
547 OnIOComplete(OK); | |
548 } | |
549 | |
550 bool SSLConnectJob::GetEnableJobWaiting() { | |
wtc
2014/06/26 17:48:17
Move this to line 178, to follow the definition of
| |
551 return enable_job_waiting_; | |
552 } | |
553 | |
452 SSLConnectJob::State SSLConnectJob::GetInitialState( | 554 SSLConnectJob::State SSLConnectJob::GetInitialState( |
453 SSLSocketParams::ConnectionType connection_type) { | 555 SSLSocketParams::ConnectionType connection_type) { |
454 switch (connection_type) { | 556 switch (connection_type) { |
455 case SSLSocketParams::DIRECT: | 557 case SSLSocketParams::DIRECT: |
456 return STATE_TRANSPORT_CONNECT; | 558 return STATE_TRANSPORT_CONNECT; |
457 case SSLSocketParams::HTTP_PROXY: | 559 case SSLSocketParams::HTTP_PROXY: |
458 return STATE_TUNNEL_CONNECT; | 560 return STATE_TUNNEL_CONNECT; |
459 case SSLSocketParams::SOCKS_PROXY: | 561 case SSLSocketParams::SOCKS_PROXY: |
460 return STATE_SOCKS_CONNECT; | 562 return STATE_SOCKS_CONNECT; |
461 } | 563 } |
(...skipping 13 matching lines...) Expand all Loading... | |
475 ClientSocketFactory* client_socket_factory, | 577 ClientSocketFactory* client_socket_factory, |
476 HostResolver* host_resolver, | 578 HostResolver* host_resolver, |
477 const SSLClientSocketContext& context, | 579 const SSLClientSocketContext& context, |
478 NetLog* net_log) | 580 NetLog* net_log) |
479 : transport_pool_(transport_pool), | 581 : transport_pool_(transport_pool), |
480 socks_pool_(socks_pool), | 582 socks_pool_(socks_pool), |
481 http_proxy_pool_(http_proxy_pool), | 583 http_proxy_pool_(http_proxy_pool), |
482 client_socket_factory_(client_socket_factory), | 584 client_socket_factory_(client_socket_factory), |
483 host_resolver_(host_resolver), | 585 host_resolver_(host_resolver), |
484 context_(context), | 586 context_(context), |
485 net_log_(net_log) { | 587 net_log_(net_log), |
588 pending_jobs_map_(new PendingJobMap()) { | |
486 base::TimeDelta max_transport_timeout = base::TimeDelta(); | 589 base::TimeDelta max_transport_timeout = base::TimeDelta(); |
487 base::TimeDelta pool_timeout; | 590 base::TimeDelta pool_timeout; |
488 if (transport_pool_) | 591 if (transport_pool_) |
489 max_transport_timeout = transport_pool_->ConnectionTimeout(); | 592 max_transport_timeout = transport_pool_->ConnectionTimeout(); |
490 if (socks_pool_) { | 593 if (socks_pool_) { |
491 pool_timeout = socks_pool_->ConnectionTimeout(); | 594 pool_timeout = socks_pool_->ConnectionTimeout(); |
492 if (pool_timeout > max_transport_timeout) | 595 if (pool_timeout > max_transport_timeout) |
493 max_transport_timeout = pool_timeout; | 596 max_transport_timeout = pool_timeout; |
494 } | 597 } |
495 if (http_proxy_pool_) { | 598 if (http_proxy_pool_) { |
(...skipping 17 matching lines...) Expand all Loading... | |
513 const std::string& ssl_session_cache_shard, | 616 const std::string& ssl_session_cache_shard, |
514 ClientSocketFactory* client_socket_factory, | 617 ClientSocketFactory* client_socket_factory, |
515 TransportClientSocketPool* transport_pool, | 618 TransportClientSocketPool* transport_pool, |
516 SOCKSClientSocketPool* socks_pool, | 619 SOCKSClientSocketPool* socks_pool, |
517 HttpProxyClientSocketPool* http_proxy_pool, | 620 HttpProxyClientSocketPool* http_proxy_pool, |
518 SSLConfigService* ssl_config_service, | 621 SSLConfigService* ssl_config_service, |
519 NetLog* net_log) | 622 NetLog* net_log) |
520 : transport_pool_(transport_pool), | 623 : transport_pool_(transport_pool), |
521 socks_pool_(socks_pool), | 624 socks_pool_(socks_pool), |
522 http_proxy_pool_(http_proxy_pool), | 625 http_proxy_pool_(http_proxy_pool), |
523 base_(this, max_sockets, max_sockets_per_group, histograms, | 626 base_(this, |
627 max_sockets, | |
628 max_sockets_per_group, | |
629 histograms, | |
524 ClientSocketPool::unused_idle_socket_timeout(), | 630 ClientSocketPool::unused_idle_socket_timeout(), |
525 ClientSocketPool::used_idle_socket_timeout(), | 631 ClientSocketPool::used_idle_socket_timeout(), |
526 new SSLConnectJobFactory(transport_pool, | 632 new SSLConnectJobFactory( |
527 socks_pool, | 633 transport_pool, |
528 http_proxy_pool, | 634 socks_pool, |
529 client_socket_factory, | 635 http_proxy_pool, |
530 host_resolver, | 636 client_socket_factory, |
531 SSLClientSocketContext( | 637 host_resolver, |
532 cert_verifier, | 638 SSLClientSocketContext(cert_verifier, |
533 server_bound_cert_service, | 639 server_bound_cert_service, |
534 transport_security_state, | 640 transport_security_state, |
535 cert_transparency_verifier, | 641 cert_transparency_verifier, |
536 ssl_session_cache_shard), | 642 ssl_session_cache_shard), |
537 net_log)), | 643 net_log)), |
538 ssl_config_service_(ssl_config_service) { | 644 ssl_config_service_(ssl_config_service) { |
539 if (ssl_config_service_.get()) | 645 if (ssl_config_service_.get()) |
540 ssl_config_service_->AddObserver(this); | 646 ssl_config_service_->AddObserver(this); |
541 if (transport_pool_) | 647 if (transport_pool_) |
542 base_.AddLowerLayeredPool(transport_pool_); | 648 base_.AddLowerLayeredPool(transport_pool_); |
543 if (socks_pool_) | 649 if (socks_pool_) |
544 base_.AddLowerLayeredPool(socks_pool_); | 650 base_.AddLowerLayeredPool(socks_pool_); |
545 if (http_proxy_pool_) | 651 if (http_proxy_pool_) |
546 base_.AddLowerLayeredPool(http_proxy_pool_); | 652 base_.AddLowerLayeredPool(http_proxy_pool_); |
547 } | 653 } |
548 | 654 |
549 SSLClientSocketPool::~SSLClientSocketPool() { | 655 SSLClientSocketPool::~SSLClientSocketPool() { |
550 if (ssl_config_service_.get()) | 656 if (ssl_config_service_.get()) |
551 ssl_config_service_->RemoveObserver(this); | 657 ssl_config_service_->RemoveObserver(this); |
552 } | 658 } |
553 | 659 |
554 scoped_ptr<ConnectJob> | 660 scoped_ptr<ConnectJob> |
555 SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( | 661 SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( |
556 const std::string& group_name, | 662 const std::string& group_name, |
557 const PoolBase::Request& request, | 663 const PoolBase::Request& request, |
558 ConnectJob::Delegate* delegate) const { | 664 ConnectJob::Delegate* delegate) const { |
559 return scoped_ptr<ConnectJob>( | 665 SSLConnectJob::PendingJobList* pending_job_list; |
560 new SSLConnectJob(group_name, request.priority(), request.params(), | 666 if (SSLConnectJob::GetEnableJobWaiting()) { |
561 ConnectionTimeout(), transport_pool_, socks_pool_, | 667 PendingJobMap::const_iterator it = pending_jobs_map_->find(group_name); |
562 http_proxy_pool_, client_socket_factory_, | 668 if (it == pending_jobs_map_->end()) { |
563 host_resolver_, context_, delegate, net_log_)); | 669 std::pair<PendingJobMap::iterator, bool> iter = |
wtc
2014/06/26 17:48:17
Nit: it is a little confusing to have variables na
| |
670 pending_jobs_map_->insert(PendingJobMap::value_type( | |
wtc
2014/06/26 17:48:17
Nit: it seems that this line is indented with thre
| |
671 group_name, new SSLConnectJob::PendingJobList())); | |
672 | |
673 it = iter.first; | |
674 } | |
675 | |
676 pending_job_list = it->second; | |
677 } else { | |
678 pending_job_list = NULL; | |
679 } | |
680 | |
681 return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name, | |
682 request.priority(), | |
683 request.params(), | |
684 ConnectionTimeout(), | |
685 transport_pool_, | |
686 socks_pool_, | |
687 http_proxy_pool_, | |
688 client_socket_factory_, | |
689 host_resolver_, | |
690 context_, | |
691 pending_job_list, | |
692 delegate, | |
693 net_log_)); | |
564 } | 694 } |
565 | 695 |
566 base::TimeDelta | 696 base::TimeDelta |
567 SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() const { | 697 SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() const { |
568 return timeout_; | 698 return timeout_; |
569 } | 699 } |
570 | 700 |
571 int SSLClientSocketPool::RequestSocket(const std::string& group_name, | 701 int SSLClientSocketPool::RequestSocket(const std::string& group_name, |
572 const void* socket_params, | 702 const void* socket_params, |
573 RequestPriority priority, | 703 RequestPriority priority, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 if (base_.CloseOneIdleSocket()) | 807 if (base_.CloseOneIdleSocket()) |
678 return true; | 808 return true; |
679 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 809 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
680 } | 810 } |
681 | 811 |
682 void SSLClientSocketPool::OnSSLConfigChanged() { | 812 void SSLClientSocketPool::OnSSLConfigChanged() { |
683 FlushWithError(ERR_NETWORK_CHANGED); | 813 FlushWithError(ERR_NETWORK_CHANGED); |
684 } | 814 } |
685 | 815 |
686 } // namespace net | 816 } // namespace net |
OLD | NEW |