| 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 is currently always be the case. |
| 265 const 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 connect_timing().connect_start = socket_connect_timing.connect_start; |
| 270 connect_timing().dns_start = socket_connect_timing.dns_start; |
| 271 connect_timing().dns_end = socket_connect_timing.dns_end; |
| 272 } |
| 273 |
| 274 connect_timing().ssl_start = base::TimeTicks::Now(); |
| 263 | 275 |
| 264 ssl_socket_.reset(client_socket_factory_->CreateSSLClientSocket( | 276 ssl_socket_.reset(client_socket_factory_->CreateSSLClientSocket( |
| 265 transport_socket_handle_.release(), params_->host_and_port(), | 277 transport_socket_handle_.release(), params_->host_and_port(), |
| 266 params_->ssl_config(), context_)); | 278 params_->ssl_config(), context_)); |
| 267 return ssl_socket_->Connect(callback_); | 279 return ssl_socket_->Connect(callback_); |
| 268 } | 280 } |
| 269 | 281 |
| 270 int SSLConnectJob::DoSSLConnectComplete(int result) { | 282 int SSLConnectJob::DoSSLConnectComplete(int result) { |
| 283 connect_timing().ssl_end = base::TimeTicks::Now(); |
| 284 |
| 271 SSLClientSocket::NextProtoStatus status = | 285 SSLClientSocket::NextProtoStatus status = |
| 272 SSLClientSocket::kNextProtoUnsupported; | 286 SSLClientSocket::kNextProtoUnsupported; |
| 273 std::string proto; | 287 std::string proto; |
| 274 std::string server_protos; | 288 std::string server_protos; |
| 275 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket | 289 // 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 | 290 // 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. | 291 // here, then we know that we called SSL_ImportFD. |
| 278 if (result == OK || IsCertificateError(result)) | 292 if (result == OK || IsCertificateError(result)) |
| 279 status = ssl_socket_->GetNextProto(&proto, &server_protos); | 293 status = ssl_socket_->GetNextProto(&proto, &server_protos); |
| 280 | 294 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 295 } | 309 } |
| 296 if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated()) | 310 if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated()) |
| 297 return ERR_NPN_NEGOTIATION_FAILED; | 311 return ERR_NPN_NEGOTIATION_FAILED; |
| 298 | 312 |
| 299 // Spdy might be turned on by default, or it might be over npn. | 313 // Spdy might be turned on by default, or it might be over npn. |
| 300 bool using_spdy = params_->force_spdy_over_ssl() || | 314 bool using_spdy = params_->force_spdy_over_ssl() || |
| 301 params_->want_spdy_over_npn(); | 315 params_->want_spdy_over_npn(); |
| 302 | 316 |
| 303 if (result == OK || | 317 if (result == OK || |
| 304 ssl_socket_->IgnoreCertError(result, params_->load_flags())) { | 318 ssl_socket_->IgnoreCertError(result, params_->load_flags())) { |
| 305 DCHECK(ssl_connect_start_time_ != base::TimeTicks()); | 319 DCHECK(connect_timing().ssl_start != base::TimeTicks()); |
| 306 base::TimeDelta connect_duration = | 320 base::TimeDelta connect_duration = |
| 307 base::TimeTicks::Now() - ssl_connect_start_time_; | 321 connect_timing().ssl_end - connect_timing().ssl_start; |
| 308 if (using_spdy) { | 322 if (using_spdy) { |
| 309 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SpdyConnectionLatency", | 323 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SpdyConnectionLatency", |
| 310 connect_duration, | 324 connect_duration, |
| 311 base::TimeDelta::FromMilliseconds(1), | 325 base::TimeDelta::FromMilliseconds(1), |
| 312 base::TimeDelta::FromMinutes(10), | 326 base::TimeDelta::FromMinutes(10), |
| 313 100); | 327 100); |
| 314 } | 328 } |
| 315 | 329 |
| 316 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency", | 330 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency", |
| 317 connect_duration, | 331 connect_duration, |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 Flush(); | 620 Flush(); |
| 607 } | 621 } |
| 608 | 622 |
| 609 bool SSLClientSocketPool::CloseOneIdleConnection() { | 623 bool SSLClientSocketPool::CloseOneIdleConnection() { |
| 610 if (base_.CloseOneIdleSocket()) | 624 if (base_.CloseOneIdleSocket()) |
| 611 return true; | 625 return true; |
| 612 return base_.CloseOneIdleConnectionInLayeredPool(); | 626 return base_.CloseOneIdleConnectionInLayeredPool(); |
| 613 } | 627 } |
| 614 | 628 |
| 615 } // namespace net | 629 } // namespace net |
| OLD | NEW |