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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 122 } |
123 | 123 |
124 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { | 124 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { |
125 // Headers in |error_response_info_| indicate a proxy tunnel setup | 125 // Headers in |error_response_info_| indicate a proxy tunnel setup |
126 // problem. See DoTunnelConnectComplete. | 126 // problem. See DoTunnelConnectComplete. |
127 if (error_response_info_.headers) { | 127 if (error_response_info_.headers) { |
128 handle->set_pending_http_proxy_connection( | 128 handle->set_pending_http_proxy_connection( |
129 transport_socket_handle_.release()); | 129 transport_socket_handle_.release()); |
130 } | 130 } |
131 handle->set_ssl_error_response_info(error_response_info_); | 131 handle->set_ssl_error_response_info(error_response_info_); |
132 if (!ssl_connect_start_time_.is_null()) | 132 if (!connect_timing_.ssl_start.is_null()) |
133 handle->set_is_ssl_error(true); | 133 handle->set_is_ssl_error(true); |
134 } | 134 } |
135 | 135 |
136 void SSLConnectJob::OnIOComplete(int result) { | 136 void SSLConnectJob::OnIOComplete(int result) { |
137 int rv = DoLoop(result); | 137 int rv = DoLoop(result); |
138 if (rv != ERR_IO_PENDING) | 138 if (rv != ERR_IO_PENDING) |
139 NotifyDelegateOfCompletion(rv); // Deletes |this|. | 139 NotifyDelegateOfCompletion(rv); // Deletes |this|. |
140 } | 140 } |
141 | 141 |
142 int SSLConnectJob::DoLoop(int result) { | 142 int SSLConnectJob::DoLoop(int result) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 return result; | 252 return result; |
253 | 253 |
254 next_state_ = STATE_SSL_CONNECT; | 254 next_state_ = STATE_SSL_CONNECT; |
255 return result; | 255 return result; |
256 } | 256 } |
257 | 257 |
258 int SSLConnectJob::DoSSLConnect() { | 258 int SSLConnectJob::DoSSLConnect() { |
259 next_state_ = STATE_SSL_CONNECT_COMPLETE; | 259 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
260 // Reset the timeout to just the time allowed for the SSL handshake. | 260 // Reset the timeout to just the time allowed for the SSL handshake. |
261 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); | 261 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); |
262 ssl_connect_start_time_ = base::TimeTicks::Now(); | 262 |
| 263 // If the handle has a fresh socket, get its connect start and DNS times. |
| 264 // This should always be the case. |
| 265 const LoadTimingInfo::ConnectTiming& socket_connect_timing = |
| 266 transport_socket_handle_->connect_timing(); |
| 267 if (!transport_socket_handle_->is_reused() && |
| 268 !socket_connect_timing.connect_start.is_null()) { |
| 269 // Overwriting |connect_start| serves two purposes - it adjusts timing so |
| 270 // |connect_start| doesn't include dns times, and it adjusts the time so |
| 271 // as not to include time spent waiting for an idle socket. |
| 272 connect_timing_.connect_start = socket_connect_timing.connect_start; |
| 273 connect_timing_.dns_start = socket_connect_timing.dns_start; |
| 274 connect_timing_.dns_end = socket_connect_timing.dns_end; |
| 275 } |
| 276 |
| 277 connect_timing_.ssl_start = base::TimeTicks::Now(); |
263 | 278 |
264 ssl_socket_.reset(client_socket_factory_->CreateSSLClientSocket( | 279 ssl_socket_.reset(client_socket_factory_->CreateSSLClientSocket( |
265 transport_socket_handle_.release(), params_->host_and_port(), | 280 transport_socket_handle_.release(), params_->host_and_port(), |
266 params_->ssl_config(), context_)); | 281 params_->ssl_config(), context_)); |
267 return ssl_socket_->Connect(callback_); | 282 return ssl_socket_->Connect(callback_); |
268 } | 283 } |
269 | 284 |
270 int SSLConnectJob::DoSSLConnectComplete(int result) { | 285 int SSLConnectJob::DoSSLConnectComplete(int result) { |
| 286 connect_timing_.ssl_end = base::TimeTicks::Now(); |
| 287 |
271 SSLClientSocket::NextProtoStatus status = | 288 SSLClientSocket::NextProtoStatus status = |
272 SSLClientSocket::kNextProtoUnsupported; | 289 SSLClientSocket::kNextProtoUnsupported; |
273 std::string proto; | 290 std::string proto; |
274 std::string server_protos; | 291 std::string server_protos; |
275 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket | 292 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket |
276 // that hasn't had SSL_ImportFD called on it. If we get a certificate error | 293 // that hasn't had SSL_ImportFD called on it. If we get a certificate error |
277 // here, then we know that we called SSL_ImportFD. | 294 // here, then we know that we called SSL_ImportFD. |
278 if (result == OK || IsCertificateError(result)) | 295 if (result == OK || IsCertificateError(result)) |
279 status = ssl_socket_->GetNextProto(&proto, &server_protos); | 296 status = ssl_socket_->GetNextProto(&proto, &server_protos); |
280 | 297 |
(...skipping 14 matching lines...) Expand all Loading... |
295 } | 312 } |
296 if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated()) | 313 if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated()) |
297 return ERR_NPN_NEGOTIATION_FAILED; | 314 return ERR_NPN_NEGOTIATION_FAILED; |
298 | 315 |
299 // Spdy might be turned on by default, or it might be over npn. | 316 // Spdy might be turned on by default, or it might be over npn. |
300 bool using_spdy = params_->force_spdy_over_ssl() || | 317 bool using_spdy = params_->force_spdy_over_ssl() || |
301 params_->want_spdy_over_npn(); | 318 params_->want_spdy_over_npn(); |
302 | 319 |
303 if (result == OK || | 320 if (result == OK || |
304 ssl_socket_->IgnoreCertError(result, params_->load_flags())) { | 321 ssl_socket_->IgnoreCertError(result, params_->load_flags())) { |
305 DCHECK(ssl_connect_start_time_ != base::TimeTicks()); | 322 DCHECK(!connect_timing_.ssl_start.is_null()); |
306 base::TimeDelta connect_duration = | 323 base::TimeDelta connect_duration = |
307 base::TimeTicks::Now() - ssl_connect_start_time_; | 324 connect_timing_.ssl_end - connect_timing_.ssl_start; |
308 if (using_spdy) { | 325 if (using_spdy) { |
309 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SpdyConnectionLatency", | 326 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SpdyConnectionLatency", |
310 connect_duration, | 327 connect_duration, |
311 base::TimeDelta::FromMilliseconds(1), | 328 base::TimeDelta::FromMilliseconds(1), |
312 base::TimeDelta::FromMinutes(10), | 329 base::TimeDelta::FromMinutes(10), |
313 100); | 330 100); |
314 } | 331 } |
315 | 332 |
316 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency", | 333 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency", |
317 connect_duration, | 334 connect_duration, |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 FlushWithError(ERR_NETWORK_CHANGED); | 623 FlushWithError(ERR_NETWORK_CHANGED); |
607 } | 624 } |
608 | 625 |
609 bool SSLClientSocketPool::CloseOneIdleConnection() { | 626 bool SSLClientSocketPool::CloseOneIdleConnection() { |
610 if (base_.CloseOneIdleSocket()) | 627 if (base_.CloseOneIdleSocket()) |
611 return true; | 628 return true; |
612 return base_.CloseOneIdleConnectionInLayeredPool(); | 629 return base_.CloseOneIdleConnectionInLayeredPool(); |
613 } | 630 } |
614 | 631 |
615 } // namespace net | 632 } // namespace net |
OLD | NEW |