| 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/stl_util.h" | |
| 13 #include "base/values.h" | 12 #include "base/values.h" |
| 14 #include "net/base/host_port_pair.h" | 13 #include "net/base/host_port_pair.h" |
| 15 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 16 #include "net/http/http_proxy_client_socket.h" | 15 #include "net/http/http_proxy_client_socket.h" |
| 17 #include "net/http/http_proxy_client_socket_pool.h" | 16 #include "net/http/http_proxy_client_socket_pool.h" |
| 18 #include "net/socket/client_socket_factory.h" | 17 #include "net/socket/client_socket_factory.h" |
| 19 #include "net/socket/client_socket_handle.h" | 18 #include "net/socket/client_socket_handle.h" |
| 20 #include "net/socket/socks_client_socket_pool.h" | 19 #include "net/socket/socks_client_socket_pool.h" |
| 21 #include "net/socket/ssl_client_socket.h" | 20 #include "net/socket/ssl_client_socket.h" |
| 22 #include "net/socket/transport_client_socket_pool.h" | 21 #include "net/socket/transport_client_socket_pool.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 DCHECK_EQ(GetConnectionType(), SOCKS_PROXY); | 87 DCHECK_EQ(GetConnectionType(), SOCKS_PROXY); |
| 89 return socks_proxy_params_; | 88 return socks_proxy_params_; |
| 90 } | 89 } |
| 91 | 90 |
| 92 const scoped_refptr<HttpProxySocketParams>& | 91 const scoped_refptr<HttpProxySocketParams>& |
| 93 SSLSocketParams::GetHttpProxyConnectionParams() const { | 92 SSLSocketParams::GetHttpProxyConnectionParams() const { |
| 94 DCHECK_EQ(GetConnectionType(), HTTP_PROXY); | 93 DCHECK_EQ(GetConnectionType(), HTTP_PROXY); |
| 95 return http_proxy_params_; | 94 return http_proxy_params_; |
| 96 } | 95 } |
| 97 | 96 |
| 98 SSLConnectJobMessenger::SocketAndCallback::SocketAndCallback( | |
| 99 SSLClientSocket* ssl_socket, | |
| 100 const base::Closure& job_resumption_callback) | |
| 101 : socket(ssl_socket), callback(job_resumption_callback) { | |
| 102 } | |
| 103 | |
| 104 SSLConnectJobMessenger::SocketAndCallback::~SocketAndCallback() { | |
| 105 } | |
| 106 | |
| 107 SSLConnectJobMessenger::SSLConnectJobMessenger( | |
| 108 const base::Closure& messenger_finished_callback) | |
| 109 : messenger_finished_callback_(messenger_finished_callback), | |
| 110 weak_factory_(this) { | |
| 111 } | |
| 112 | |
| 113 SSLConnectJobMessenger::~SSLConnectJobMessenger() { | |
| 114 } | |
| 115 | |
| 116 void SSLConnectJobMessenger::RemovePendingSocket(SSLClientSocket* ssl_socket) { | |
| 117 // Sockets do not need to be removed from connecting_sockets_ because | |
| 118 // OnSSLHandshakeCompleted will do this. | |
| 119 for (SSLPendingSocketsAndCallbacks::iterator it = | |
| 120 pending_sockets_and_callbacks_.begin(); | |
| 121 it != pending_sockets_and_callbacks_.end(); | |
| 122 ++it) { | |
| 123 if (it->socket == ssl_socket) { | |
| 124 pending_sockets_and_callbacks_.erase(it); | |
| 125 return; | |
| 126 } | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 bool SSLConnectJobMessenger::CanProceed(SSLClientSocket* ssl_socket) { | |
| 131 // If there are no connecting sockets, allow the connection to proceed. | |
| 132 return connecting_sockets_.empty(); | |
| 133 } | |
| 134 | |
| 135 void SSLConnectJobMessenger::MonitorConnectionResult( | |
| 136 SSLClientSocket* ssl_socket) { | |
| 137 connecting_sockets_.push_back(ssl_socket); | |
| 138 ssl_socket->SetHandshakeCompletionCallback( | |
| 139 base::Bind(&SSLConnectJobMessenger::OnSSLHandshakeCompleted, | |
| 140 weak_factory_.GetWeakPtr())); | |
| 141 } | |
| 142 | |
| 143 void SSLConnectJobMessenger::AddPendingSocket(SSLClientSocket* ssl_socket, | |
| 144 const base::Closure& callback) { | |
| 145 DCHECK(!connecting_sockets_.empty()); | |
| 146 pending_sockets_and_callbacks_.push_back( | |
| 147 SocketAndCallback(ssl_socket, callback)); | |
| 148 } | |
| 149 | |
| 150 void SSLConnectJobMessenger::OnSSLHandshakeCompleted() { | |
| 151 connecting_sockets_.clear(); | |
| 152 SSLPendingSocketsAndCallbacks temp_list; | |
| 153 temp_list.swap(pending_sockets_and_callbacks_); | |
| 154 base::Closure messenger_finished_callback = messenger_finished_callback_; | |
| 155 messenger_finished_callback.Run(); | |
| 156 RunAllCallbacks(temp_list); | |
| 157 } | |
| 158 | |
| 159 void SSLConnectJobMessenger::RunAllCallbacks( | |
| 160 const SSLPendingSocketsAndCallbacks& pending_sockets_and_callbacks) { | |
| 161 for (std::vector<SocketAndCallback>::const_iterator it = | |
| 162 pending_sockets_and_callbacks.begin(); | |
| 163 it != pending_sockets_and_callbacks.end(); | |
| 164 ++it) { | |
| 165 it->callback.Run(); | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 // Timeout for the SSL handshake portion of the connect. | 97 // Timeout for the SSL handshake portion of the connect. |
| 170 static const int kSSLHandshakeTimeoutInSeconds = 30; | 98 static const int kSSLHandshakeTimeoutInSeconds = 30; |
| 171 | 99 |
| 172 SSLConnectJob::SSLConnectJob(const std::string& group_name, | 100 SSLConnectJob::SSLConnectJob(const std::string& group_name, |
| 173 RequestPriority priority, | 101 RequestPriority priority, |
| 174 const scoped_refptr<SSLSocketParams>& params, | 102 const scoped_refptr<SSLSocketParams>& params, |
| 175 const base::TimeDelta& timeout_duration, | 103 const base::TimeDelta& timeout_duration, |
| 176 TransportClientSocketPool* transport_pool, | 104 TransportClientSocketPool* transport_pool, |
| 177 SOCKSClientSocketPool* socks_pool, | 105 SOCKSClientSocketPool* socks_pool, |
| 178 HttpProxyClientSocketPool* http_proxy_pool, | 106 HttpProxyClientSocketPool* http_proxy_pool, |
| 179 ClientSocketFactory* client_socket_factory, | 107 ClientSocketFactory* client_socket_factory, |
| 180 const SSLClientSocketContext& context, | 108 const SSLClientSocketContext& context, |
| 181 const GetMessengerCallback& get_messenger_callback, | |
| 182 Delegate* delegate, | 109 Delegate* delegate, |
| 183 NetLog* net_log) | 110 NetLog* net_log) |
| 184 : ConnectJob(group_name, | 111 : ConnectJob(group_name, |
| 185 timeout_duration, | 112 timeout_duration, |
| 186 priority, | 113 priority, |
| 187 delegate, | 114 delegate, |
| 188 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 115 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 189 params_(params), | 116 params_(params), |
| 190 transport_pool_(transport_pool), | 117 transport_pool_(transport_pool), |
| 191 socks_pool_(socks_pool), | 118 socks_pool_(socks_pool), |
| 192 http_proxy_pool_(http_proxy_pool), | 119 http_proxy_pool_(http_proxy_pool), |
| 193 client_socket_factory_(client_socket_factory), | 120 client_socket_factory_(client_socket_factory), |
| 194 context_(context.cert_verifier, | 121 context_(context.cert_verifier, |
| 195 context.channel_id_service, | 122 context.channel_id_service, |
| 196 context.transport_security_state, | 123 context.transport_security_state, |
| 197 context.cert_transparency_verifier, | 124 context.cert_transparency_verifier, |
| 198 context.cert_policy_enforcer, | 125 context.cert_policy_enforcer, |
| 199 (params->privacy_mode() == PRIVACY_MODE_ENABLED | 126 (params->privacy_mode() == PRIVACY_MODE_ENABLED |
| 200 ? "pm/" + context.ssl_session_cache_shard | 127 ? "pm/" + context.ssl_session_cache_shard |
| 201 : context.ssl_session_cache_shard)), | 128 : context.ssl_session_cache_shard)), |
| 202 io_callback_( | 129 callback_(base::Bind(&SSLConnectJob::OnIOComplete, |
| 203 base::Bind(&SSLConnectJob::OnIOComplete, base::Unretained(this))), | 130 base::Unretained(this))) {} |
| 204 messenger_(NULL), | |
| 205 get_messenger_callback_(get_messenger_callback), | |
| 206 weak_factory_(this) { | |
| 207 } | |
| 208 | 131 |
| 209 SSLConnectJob::~SSLConnectJob() { | 132 SSLConnectJob::~SSLConnectJob() {} |
| 210 if (ssl_socket_.get() && messenger_) | |
| 211 messenger_->RemovePendingSocket(ssl_socket_.get()); | |
| 212 } | |
| 213 | 133 |
| 214 LoadState SSLConnectJob::GetLoadState() const { | 134 LoadState SSLConnectJob::GetLoadState() const { |
| 215 switch (next_state_) { | 135 switch (next_state_) { |
| 216 case STATE_TUNNEL_CONNECT_COMPLETE: | 136 case STATE_TUNNEL_CONNECT_COMPLETE: |
| 217 if (transport_socket_handle_->socket()) | 137 if (transport_socket_handle_->socket()) |
| 218 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; | 138 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; |
| 219 // else, fall through. | 139 // else, fall through. |
| 220 case STATE_TRANSPORT_CONNECT: | 140 case STATE_TRANSPORT_CONNECT: |
| 221 case STATE_TRANSPORT_CONNECT_COMPLETE: | 141 case STATE_TRANSPORT_CONNECT_COMPLETE: |
| 222 case STATE_SOCKS_CONNECT: | 142 case STATE_SOCKS_CONNECT: |
| 223 case STATE_SOCKS_CONNECT_COMPLETE: | 143 case STATE_SOCKS_CONNECT_COMPLETE: |
| 224 case STATE_TUNNEL_CONNECT: | 144 case STATE_TUNNEL_CONNECT: |
| 225 return transport_socket_handle_->GetLoadState(); | 145 return transport_socket_handle_->GetLoadState(); |
| 226 case STATE_CREATE_SSL_SOCKET: | |
| 227 case STATE_CHECK_FOR_RESUME: | |
| 228 case STATE_SSL_CONNECT: | 146 case STATE_SSL_CONNECT: |
| 229 case STATE_SSL_CONNECT_COMPLETE: | 147 case STATE_SSL_CONNECT_COMPLETE: |
| 230 return LOAD_STATE_SSL_HANDSHAKE; | 148 return LOAD_STATE_SSL_HANDSHAKE; |
| 231 default: | 149 default: |
| 232 NOTREACHED(); | 150 NOTREACHED(); |
| 233 return LOAD_STATE_IDLE; | 151 return LOAD_STATE_IDLE; |
| 234 } | 152 } |
| 235 } | 153 } |
| 236 | 154 |
| 237 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { | 155 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 case STATE_SOCKS_CONNECT_COMPLETE: | 192 case STATE_SOCKS_CONNECT_COMPLETE: |
| 275 rv = DoSOCKSConnectComplete(rv); | 193 rv = DoSOCKSConnectComplete(rv); |
| 276 break; | 194 break; |
| 277 case STATE_TUNNEL_CONNECT: | 195 case STATE_TUNNEL_CONNECT: |
| 278 DCHECK_EQ(OK, rv); | 196 DCHECK_EQ(OK, rv); |
| 279 rv = DoTunnelConnect(); | 197 rv = DoTunnelConnect(); |
| 280 break; | 198 break; |
| 281 case STATE_TUNNEL_CONNECT_COMPLETE: | 199 case STATE_TUNNEL_CONNECT_COMPLETE: |
| 282 rv = DoTunnelConnectComplete(rv); | 200 rv = DoTunnelConnectComplete(rv); |
| 283 break; | 201 break; |
| 284 case STATE_CREATE_SSL_SOCKET: | |
| 285 rv = DoCreateSSLSocket(); | |
| 286 break; | |
| 287 case STATE_CHECK_FOR_RESUME: | |
| 288 rv = DoCheckForResume(); | |
| 289 break; | |
| 290 case STATE_SSL_CONNECT: | 202 case STATE_SSL_CONNECT: |
| 291 DCHECK_EQ(OK, rv); | 203 DCHECK_EQ(OK, rv); |
| 292 rv = DoSSLConnect(); | 204 rv = DoSSLConnect(); |
| 293 break; | 205 break; |
| 294 case STATE_SSL_CONNECT_COMPLETE: | 206 case STATE_SSL_CONNECT_COMPLETE: |
| 295 rv = DoSSLConnectComplete(rv); | 207 rv = DoSSLConnectComplete(rv); |
| 296 break; | 208 break; |
| 297 default: | 209 default: |
| 298 NOTREACHED() << "bad state"; | 210 NOTREACHED() << "bad state"; |
| 299 rv = ERR_FAILED; | 211 rv = ERR_FAILED; |
| 300 break; | 212 break; |
| 301 } | 213 } |
| 302 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 214 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 303 | 215 |
| 304 return rv; | 216 return rv; |
| 305 } | 217 } |
| 306 | 218 |
| 307 int SSLConnectJob::DoTransportConnect() { | 219 int SSLConnectJob::DoTransportConnect() { |
| 308 DCHECK(transport_pool_); | 220 DCHECK(transport_pool_); |
| 309 | 221 |
| 310 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; | 222 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; |
| 311 transport_socket_handle_.reset(new ClientSocketHandle()); | 223 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 312 scoped_refptr<TransportSocketParams> direct_params = | 224 scoped_refptr<TransportSocketParams> direct_params = |
| 313 params_->GetDirectConnectionParams(); | 225 params_->GetDirectConnectionParams(); |
| 314 return transport_socket_handle_->Init(group_name(), | 226 return transport_socket_handle_->Init(group_name(), |
| 315 direct_params, | 227 direct_params, |
| 316 priority(), | 228 priority(), |
| 317 io_callback_, | 229 callback_, |
| 318 transport_pool_, | 230 transport_pool_, |
| 319 net_log()); | 231 net_log()); |
| 320 } | 232 } |
| 321 | 233 |
| 322 int SSLConnectJob::DoTransportConnectComplete(int result) { | 234 int SSLConnectJob::DoTransportConnectComplete(int result) { |
| 323 if (result == OK) | 235 if (result == OK) |
| 324 next_state_ = STATE_CREATE_SSL_SOCKET; | 236 next_state_ = STATE_SSL_CONNECT; |
| 325 | 237 |
| 326 return result; | 238 return result; |
| 327 } | 239 } |
| 328 | 240 |
| 329 int SSLConnectJob::DoSOCKSConnect() { | 241 int SSLConnectJob::DoSOCKSConnect() { |
| 330 DCHECK(socks_pool_); | 242 DCHECK(socks_pool_); |
| 331 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; | 243 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; |
| 332 transport_socket_handle_.reset(new ClientSocketHandle()); | 244 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 333 scoped_refptr<SOCKSSocketParams> socks_proxy_params = | 245 scoped_refptr<SOCKSSocketParams> socks_proxy_params = |
| 334 params_->GetSocksProxyConnectionParams(); | 246 params_->GetSocksProxyConnectionParams(); |
| 335 return transport_socket_handle_->Init(group_name(), | 247 return transport_socket_handle_->Init(group_name(), |
| 336 socks_proxy_params, | 248 socks_proxy_params, |
| 337 priority(), | 249 priority(), |
| 338 io_callback_, | 250 callback_, |
| 339 socks_pool_, | 251 socks_pool_, |
| 340 net_log()); | 252 net_log()); |
| 341 } | 253 } |
| 342 | 254 |
| 343 int SSLConnectJob::DoSOCKSConnectComplete(int result) { | 255 int SSLConnectJob::DoSOCKSConnectComplete(int result) { |
| 344 if (result == OK) | 256 if (result == OK) |
| 345 next_state_ = STATE_CREATE_SSL_SOCKET; | 257 next_state_ = STATE_SSL_CONNECT; |
| 346 | 258 |
| 347 return result; | 259 return result; |
| 348 } | 260 } |
| 349 | 261 |
| 350 int SSLConnectJob::DoTunnelConnect() { | 262 int SSLConnectJob::DoTunnelConnect() { |
| 351 DCHECK(http_proxy_pool_); | 263 DCHECK(http_proxy_pool_); |
| 352 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; | 264 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; |
| 353 | 265 |
| 354 transport_socket_handle_.reset(new ClientSocketHandle()); | 266 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 355 scoped_refptr<HttpProxySocketParams> http_proxy_params = | 267 scoped_refptr<HttpProxySocketParams> http_proxy_params = |
| 356 params_->GetHttpProxyConnectionParams(); | 268 params_->GetHttpProxyConnectionParams(); |
| 357 return transport_socket_handle_->Init(group_name(), | 269 return transport_socket_handle_->Init(group_name(), |
| 358 http_proxy_params, | 270 http_proxy_params, |
| 359 priority(), | 271 priority(), |
| 360 io_callback_, | 272 callback_, |
| 361 http_proxy_pool_, | 273 http_proxy_pool_, |
| 362 net_log()); | 274 net_log()); |
| 363 } | 275 } |
| 364 | 276 |
| 365 int SSLConnectJob::DoTunnelConnectComplete(int result) { | 277 int SSLConnectJob::DoTunnelConnectComplete(int result) { |
| 366 // Extract the information needed to prompt for appropriate proxy | 278 // Extract the information needed to prompt for appropriate proxy |
| 367 // authentication so that when ClientSocketPoolBaseHelper calls | 279 // authentication so that when ClientSocketPoolBaseHelper calls |
| 368 // |GetAdditionalErrorState|, we can easily set the state. | 280 // |GetAdditionalErrorState|, we can easily set the state. |
| 369 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 281 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 370 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); | 282 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); |
| 371 } else if (result == ERR_PROXY_AUTH_REQUESTED || | 283 } else if (result == ERR_PROXY_AUTH_REQUESTED || |
| 372 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { | 284 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { |
| 373 StreamSocket* socket = transport_socket_handle_->socket(); | 285 StreamSocket* socket = transport_socket_handle_->socket(); |
| 374 ProxyClientSocket* tunnel_socket = static_cast<ProxyClientSocket*>(socket); | 286 ProxyClientSocket* tunnel_socket = static_cast<ProxyClientSocket*>(socket); |
| 375 error_response_info_ = *tunnel_socket->GetConnectResponseInfo(); | 287 error_response_info_ = *tunnel_socket->GetConnectResponseInfo(); |
| 376 } | 288 } |
| 377 if (result < 0) | 289 if (result < 0) |
| 378 return result; | 290 return result; |
| 379 next_state_ = STATE_CREATE_SSL_SOCKET; | 291 |
| 292 next_state_ = STATE_SSL_CONNECT; |
| 380 return result; | 293 return result; |
| 381 } | 294 } |
| 382 | 295 |
| 383 int SSLConnectJob::DoCreateSSLSocket() { | 296 int SSLConnectJob::DoSSLConnect() { |
| 384 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462815 is fixed. | 297 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462815 is fixed. |
| 385 tracked_objects::ScopedTracker tracking_profile( | 298 tracked_objects::ScopedTracker tracking_profile( |
| 386 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 299 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 387 "462815 SSLConnectJob::DoCreateSSLSocket")); | 300 "462815 SSLConnectJob::DoSSLConnect")); |
| 388 next_state_ = STATE_CHECK_FOR_RESUME; | 301 |
| 302 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
| 389 | 303 |
| 390 // Reset the timeout to just the time allowed for the SSL handshake. | 304 // Reset the timeout to just the time allowed for the SSL handshake. |
| 391 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); | 305 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); |
| 392 | 306 |
| 393 // If the handle has a fresh socket, get its connect start and DNS times. | 307 // If the handle has a fresh socket, get its connect start and DNS times. |
| 394 // This should always be the case. | 308 // This should always be the case. |
| 395 const LoadTimingInfo::ConnectTiming& socket_connect_timing = | 309 const LoadTimingInfo::ConnectTiming& socket_connect_timing = |
| 396 transport_socket_handle_->connect_timing(); | 310 transport_socket_handle_->connect_timing(); |
| 397 if (!transport_socket_handle_->is_reused() && | 311 if (!transport_socket_handle_->is_reused() && |
| 398 !socket_connect_timing.connect_start.is_null()) { | 312 !socket_connect_timing.connect_start.is_null()) { |
| 399 // Overwriting |connect_start| serves two purposes - it adjusts timing so | 313 // Overwriting |connect_start| serves two purposes - it adjusts timing so |
| 400 // |connect_start| doesn't include dns times, and it adjusts the time so | 314 // |connect_start| doesn't include dns times, and it adjusts the time so |
| 401 // as not to include time spent waiting for an idle socket. | 315 // as not to include time spent waiting for an idle socket. |
| 402 connect_timing_.connect_start = socket_connect_timing.connect_start; | 316 connect_timing_.connect_start = socket_connect_timing.connect_start; |
| 403 connect_timing_.dns_start = socket_connect_timing.dns_start; | 317 connect_timing_.dns_start = socket_connect_timing.dns_start; |
| 404 connect_timing_.dns_end = socket_connect_timing.dns_end; | 318 connect_timing_.dns_end = socket_connect_timing.dns_end; |
| 405 } | 319 } |
| 406 | 320 |
| 321 connect_timing_.ssl_start = base::TimeTicks::Now(); |
| 322 |
| 407 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket( | 323 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket( |
| 408 transport_socket_handle_.Pass(), | 324 transport_socket_handle_.Pass(), |
| 409 params_->host_and_port(), | 325 params_->host_and_port(), |
| 410 params_->ssl_config(), | 326 params_->ssl_config(), |
| 411 context_); | 327 context_); |
| 412 | 328 return ssl_socket_->Connect(callback_); |
| 413 if (!ssl_socket_->InSessionCache()) | |
| 414 messenger_ = get_messenger_callback_.Run(ssl_socket_->GetSessionCacheKey()); | |
| 415 | |
| 416 return OK; | |
| 417 } | |
| 418 | |
| 419 int SSLConnectJob::DoCheckForResume() { | |
| 420 next_state_ = STATE_SSL_CONNECT; | |
| 421 | |
| 422 if (!messenger_) | |
| 423 return OK; | |
| 424 | |
| 425 if (messenger_->CanProceed(ssl_socket_.get())) { | |
| 426 messenger_->MonitorConnectionResult(ssl_socket_.get()); | |
| 427 // The SSLConnectJob no longer needs access to the messenger after this | |
| 428 // point. | |
| 429 messenger_ = NULL; | |
| 430 return OK; | |
| 431 } | |
| 432 | |
| 433 messenger_->AddPendingSocket(ssl_socket_.get(), | |
| 434 base::Bind(&SSLConnectJob::ResumeSSLConnection, | |
| 435 weak_factory_.GetWeakPtr())); | |
| 436 | |
| 437 return ERR_IO_PENDING; | |
| 438 } | |
| 439 | |
| 440 int SSLConnectJob::DoSSLConnect() { | |
| 441 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462813 is fixed. | |
| 442 tracked_objects::ScopedTracker tracking_profile( | |
| 443 FROM_HERE_WITH_EXPLICIT_FUNCTION("462813 SSLConnectJob::DoSSLConnect")); | |
| 444 next_state_ = STATE_SSL_CONNECT_COMPLETE; | |
| 445 | |
| 446 connect_timing_.ssl_start = base::TimeTicks::Now(); | |
| 447 | |
| 448 return ssl_socket_->Connect(io_callback_); | |
| 449 } | 329 } |
| 450 | 330 |
| 451 int SSLConnectJob::DoSSLConnectComplete(int result) { | 331 int SSLConnectJob::DoSSLConnectComplete(int result) { |
| 452 connect_timing_.ssl_end = base::TimeTicks::Now(); | 332 connect_timing_.ssl_end = base::TimeTicks::Now(); |
| 453 | 333 |
| 454 SSLClientSocket::NextProtoStatus status = | 334 SSLClientSocket::NextProtoStatus status = |
| 455 SSLClientSocket::kNextProtoUnsupported; | 335 SSLClientSocket::kNextProtoUnsupported; |
| 456 std::string proto; | 336 std::string proto; |
| 457 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket | 337 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket |
| 458 // that hasn't had SSL_ImportFD called on it. If we get a certificate error | 338 // that hasn't had SSL_ImportFD called on it. If we get a certificate error |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 100); | 407 100); |
| 528 } else if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_FULL) { | 408 } else if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_FULL) { |
| 529 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Full_Handshake", | 409 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Full_Handshake", |
| 530 connect_duration, | 410 connect_duration, |
| 531 base::TimeDelta::FromMilliseconds(1), | 411 base::TimeDelta::FromMilliseconds(1), |
| 532 base::TimeDelta::FromMinutes(1), | 412 base::TimeDelta::FromMinutes(1), |
| 533 100); | 413 100); |
| 534 } | 414 } |
| 535 | 415 |
| 536 const std::string& host = params_->host_and_port().host(); | 416 const std::string& host = params_->host_and_port().host(); |
| 537 bool is_google = | 417 bool is_google = host == "google.com" || |
| 538 host == "google.com" || | 418 (host.size() > 11 && |
| 539 (host.size() > 11 && host.rfind(".google.com") == host.size() - 11); | 419 host.rfind(".google.com") == host.size() - 11); |
| 540 if (is_google) { | 420 if (is_google) { |
| 541 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2", | 421 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2", |
| 542 connect_duration, | 422 connect_duration, |
| 543 base::TimeDelta::FromMilliseconds(1), | 423 base::TimeDelta::FromMilliseconds(1), |
| 544 base::TimeDelta::FromMinutes(1), | 424 base::TimeDelta::FromMinutes(1), |
| 545 100); | 425 100); |
| 546 if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME) { | 426 if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME) { |
| 547 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_" | 427 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_" |
| 548 "Resume_Handshake", | 428 "Resume_Handshake", |
| 549 connect_duration, | 429 connect_duration, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 571 SetSocket(ssl_socket_.Pass()); | 451 SetSocket(ssl_socket_.Pass()); |
| 572 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 452 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 573 error_response_info_.cert_request_info = new SSLCertRequestInfo; | 453 error_response_info_.cert_request_info = new SSLCertRequestInfo; |
| 574 ssl_socket_->GetSSLCertRequestInfo( | 454 ssl_socket_->GetSSLCertRequestInfo( |
| 575 error_response_info_.cert_request_info.get()); | 455 error_response_info_.cert_request_info.get()); |
| 576 } | 456 } |
| 577 | 457 |
| 578 return result; | 458 return result; |
| 579 } | 459 } |
| 580 | 460 |
| 581 void SSLConnectJob::ResumeSSLConnection() { | |
| 582 DCHECK_EQ(next_state_, STATE_SSL_CONNECT); | |
| 583 messenger_ = NULL; | |
| 584 OnIOComplete(OK); | |
| 585 } | |
| 586 | |
| 587 SSLConnectJob::State SSLConnectJob::GetInitialState( | 461 SSLConnectJob::State SSLConnectJob::GetInitialState( |
| 588 SSLSocketParams::ConnectionType connection_type) { | 462 SSLSocketParams::ConnectionType connection_type) { |
| 589 switch (connection_type) { | 463 switch (connection_type) { |
| 590 case SSLSocketParams::DIRECT: | 464 case SSLSocketParams::DIRECT: |
| 591 return STATE_TRANSPORT_CONNECT; | 465 return STATE_TRANSPORT_CONNECT; |
| 592 case SSLSocketParams::HTTP_PROXY: | 466 case SSLSocketParams::HTTP_PROXY: |
| 593 return STATE_TUNNEL_CONNECT; | 467 return STATE_TUNNEL_CONNECT; |
| 594 case SSLSocketParams::SOCKS_PROXY: | 468 case SSLSocketParams::SOCKS_PROXY: |
| 595 return STATE_SOCKS_CONNECT; | 469 return STATE_SOCKS_CONNECT; |
| 596 } | 470 } |
| 597 NOTREACHED(); | 471 NOTREACHED(); |
| 598 return STATE_NONE; | 472 return STATE_NONE; |
| 599 } | 473 } |
| 600 | 474 |
| 601 int SSLConnectJob::ConnectInternal() { | 475 int SSLConnectJob::ConnectInternal() { |
| 602 next_state_ = GetInitialState(params_->GetConnectionType()); | 476 next_state_ = GetInitialState(params_->GetConnectionType()); |
| 603 return DoLoop(OK); | 477 return DoLoop(OK); |
| 604 } | 478 } |
| 605 | 479 |
| 606 SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory( | 480 SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory( |
| 607 TransportClientSocketPool* transport_pool, | 481 TransportClientSocketPool* transport_pool, |
| 608 SOCKSClientSocketPool* socks_pool, | 482 SOCKSClientSocketPool* socks_pool, |
| 609 HttpProxyClientSocketPool* http_proxy_pool, | 483 HttpProxyClientSocketPool* http_proxy_pool, |
| 610 ClientSocketFactory* client_socket_factory, | 484 ClientSocketFactory* client_socket_factory, |
| 611 const SSLClientSocketContext& context, | 485 const SSLClientSocketContext& context, |
| 612 const SSLConnectJob::GetMessengerCallback& get_messenger_callback, | |
| 613 NetLog* net_log) | 486 NetLog* net_log) |
| 614 : transport_pool_(transport_pool), | 487 : transport_pool_(transport_pool), |
| 615 socks_pool_(socks_pool), | 488 socks_pool_(socks_pool), |
| 616 http_proxy_pool_(http_proxy_pool), | 489 http_proxy_pool_(http_proxy_pool), |
| 617 client_socket_factory_(client_socket_factory), | 490 client_socket_factory_(client_socket_factory), |
| 618 context_(context), | 491 context_(context), |
| 619 get_messenger_callback_(get_messenger_callback), | |
| 620 net_log_(net_log) { | 492 net_log_(net_log) { |
| 621 base::TimeDelta max_transport_timeout = base::TimeDelta(); | 493 base::TimeDelta max_transport_timeout = base::TimeDelta(); |
| 622 base::TimeDelta pool_timeout; | 494 base::TimeDelta pool_timeout; |
| 623 if (transport_pool_) | 495 if (transport_pool_) |
| 624 max_transport_timeout = transport_pool_->ConnectionTimeout(); | 496 max_transport_timeout = transport_pool_->ConnectionTimeout(); |
| 625 if (socks_pool_) { | 497 if (socks_pool_) { |
| 626 pool_timeout = socks_pool_->ConnectionTimeout(); | 498 pool_timeout = socks_pool_->ConnectionTimeout(); |
| 627 if (pool_timeout > max_transport_timeout) | 499 if (pool_timeout > max_transport_timeout) |
| 628 max_transport_timeout = pool_timeout; | 500 max_transport_timeout = pool_timeout; |
| 629 } | 501 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 647 ChannelIDService* channel_id_service, | 519 ChannelIDService* channel_id_service, |
| 648 TransportSecurityState* transport_security_state, | 520 TransportSecurityState* transport_security_state, |
| 649 CTVerifier* cert_transparency_verifier, | 521 CTVerifier* cert_transparency_verifier, |
| 650 CertPolicyEnforcer* cert_policy_enforcer, | 522 CertPolicyEnforcer* cert_policy_enforcer, |
| 651 const std::string& ssl_session_cache_shard, | 523 const std::string& ssl_session_cache_shard, |
| 652 ClientSocketFactory* client_socket_factory, | 524 ClientSocketFactory* client_socket_factory, |
| 653 TransportClientSocketPool* transport_pool, | 525 TransportClientSocketPool* transport_pool, |
| 654 SOCKSClientSocketPool* socks_pool, | 526 SOCKSClientSocketPool* socks_pool, |
| 655 HttpProxyClientSocketPool* http_proxy_pool, | 527 HttpProxyClientSocketPool* http_proxy_pool, |
| 656 SSLConfigService* ssl_config_service, | 528 SSLConfigService* ssl_config_service, |
| 657 bool enable_ssl_connect_job_waiting, | |
| 658 NetLog* net_log) | 529 NetLog* net_log) |
| 659 : transport_pool_(transport_pool), | 530 : transport_pool_(transport_pool), |
| 660 socks_pool_(socks_pool), | 531 socks_pool_(socks_pool), |
| 661 http_proxy_pool_(http_proxy_pool), | 532 http_proxy_pool_(http_proxy_pool), |
| 662 base_(this, | 533 base_(this, max_sockets, max_sockets_per_group, histograms, |
| 663 max_sockets, | |
| 664 max_sockets_per_group, | |
| 665 histograms, | |
| 666 ClientSocketPool::unused_idle_socket_timeout(), | 534 ClientSocketPool::unused_idle_socket_timeout(), |
| 667 ClientSocketPool::used_idle_socket_timeout(), | 535 ClientSocketPool::used_idle_socket_timeout(), |
| 668 new SSLConnectJobFactory( | 536 new SSLConnectJobFactory( |
| 669 transport_pool, | 537 transport_pool, |
| 670 socks_pool, | 538 socks_pool, |
| 671 http_proxy_pool, | 539 http_proxy_pool, |
| 672 client_socket_factory, | 540 client_socket_factory, |
| 673 SSLClientSocketContext(cert_verifier, | 541 SSLClientSocketContext(cert_verifier, |
| 674 channel_id_service, | 542 channel_id_service, |
| 675 transport_security_state, | 543 transport_security_state, |
| 676 cert_transparency_verifier, | 544 cert_transparency_verifier, |
| 677 cert_policy_enforcer, | 545 cert_policy_enforcer, |
| 678 ssl_session_cache_shard), | 546 ssl_session_cache_shard), |
| 679 base::Bind( | |
| 680 &SSLClientSocketPool::GetOrCreateSSLConnectJobMessenger, | |
| 681 base::Unretained(this)), | |
| 682 net_log)), | 547 net_log)), |
| 683 ssl_config_service_(ssl_config_service), | 548 ssl_config_service_(ssl_config_service) { |
| 684 enable_ssl_connect_job_waiting_(enable_ssl_connect_job_waiting) { | |
| 685 if (ssl_config_service_.get()) | 549 if (ssl_config_service_.get()) |
| 686 ssl_config_service_->AddObserver(this); | 550 ssl_config_service_->AddObserver(this); |
| 687 if (transport_pool_) | 551 if (transport_pool_) |
| 688 base_.AddLowerLayeredPool(transport_pool_); | 552 base_.AddLowerLayeredPool(transport_pool_); |
| 689 if (socks_pool_) | 553 if (socks_pool_) |
| 690 base_.AddLowerLayeredPool(socks_pool_); | 554 base_.AddLowerLayeredPool(socks_pool_); |
| 691 if (http_proxy_pool_) | 555 if (http_proxy_pool_) |
| 692 base_.AddLowerLayeredPool(http_proxy_pool_); | 556 base_.AddLowerLayeredPool(http_proxy_pool_); |
| 693 } | 557 } |
| 694 | 558 |
| 695 SSLClientSocketPool::~SSLClientSocketPool() { | 559 SSLClientSocketPool::~SSLClientSocketPool() { |
| 696 STLDeleteContainerPairSecondPointers(messenger_map_.begin(), | |
| 697 messenger_map_.end()); | |
| 698 if (ssl_config_service_.get()) | 560 if (ssl_config_service_.get()) |
| 699 ssl_config_service_->RemoveObserver(this); | 561 ssl_config_service_->RemoveObserver(this); |
| 700 } | 562 } |
| 701 | 563 |
| 702 scoped_ptr<ConnectJob> SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( | 564 scoped_ptr<ConnectJob> |
| 565 SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( |
| 703 const std::string& group_name, | 566 const std::string& group_name, |
| 704 const PoolBase::Request& request, | 567 const PoolBase::Request& request, |
| 705 ConnectJob::Delegate* delegate) const { | 568 ConnectJob::Delegate* delegate) const { |
| 706 return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name, | 569 return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name, |
| 707 request.priority(), | 570 request.priority(), |
| 708 request.params(), | 571 request.params(), |
| 709 ConnectionTimeout(), | 572 ConnectionTimeout(), |
| 710 transport_pool_, | 573 transport_pool_, |
| 711 socks_pool_, | 574 socks_pool_, |
| 712 http_proxy_pool_, | 575 http_proxy_pool_, |
| 713 client_socket_factory_, | 576 client_socket_factory_, |
| 714 context_, | 577 context_, |
| 715 get_messenger_callback_, | |
| 716 delegate, | 578 delegate, |
| 717 net_log_)); | 579 net_log_)); |
| 718 } | 580 } |
| 719 | 581 |
| 720 base::TimeDelta SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() | 582 base::TimeDelta |
| 721 const { | 583 SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() const { |
| 722 return timeout_; | 584 return timeout_; |
| 723 } | 585 } |
| 724 | 586 |
| 725 int SSLClientSocketPool::RequestSocket(const std::string& group_name, | 587 int SSLClientSocketPool::RequestSocket(const std::string& group_name, |
| 726 const void* socket_params, | 588 const void* socket_params, |
| 727 RequestPriority priority, | 589 RequestPriority priority, |
| 728 ClientSocketHandle* handle, | 590 ClientSocketHandle* handle, |
| 729 const CompletionCallback& callback, | 591 const CompletionCallback& callback, |
| 730 const BoundNetLog& net_log) { | 592 const BoundNetLog& net_log) { |
| 731 const scoped_refptr<SSLSocketParams>* casted_socket_params = | 593 const scoped_refptr<SSLSocketParams>* casted_socket_params = |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 HigherLayeredPool* higher_pool) { | 688 HigherLayeredPool* higher_pool) { |
| 827 base_.RemoveHigherLayeredPool(higher_pool); | 689 base_.RemoveHigherLayeredPool(higher_pool); |
| 828 } | 690 } |
| 829 | 691 |
| 830 bool SSLClientSocketPool::CloseOneIdleConnection() { | 692 bool SSLClientSocketPool::CloseOneIdleConnection() { |
| 831 if (base_.CloseOneIdleSocket()) | 693 if (base_.CloseOneIdleSocket()) |
| 832 return true; | 694 return true; |
| 833 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 695 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
| 834 } | 696 } |
| 835 | 697 |
| 836 SSLConnectJobMessenger* SSLClientSocketPool::GetOrCreateSSLConnectJobMessenger( | |
| 837 const std::string& cache_key) { | |
| 838 if (!enable_ssl_connect_job_waiting_) | |
| 839 return NULL; | |
| 840 MessengerMap::const_iterator it = messenger_map_.find(cache_key); | |
| 841 if (it == messenger_map_.end()) { | |
| 842 std::pair<MessengerMap::iterator, bool> iter = | |
| 843 messenger_map_.insert(MessengerMap::value_type( | |
| 844 cache_key, | |
| 845 new SSLConnectJobMessenger( | |
| 846 base::Bind(&SSLClientSocketPool::DeleteSSLConnectJobMessenger, | |
| 847 base::Unretained(this), | |
| 848 cache_key)))); | |
| 849 it = iter.first; | |
| 850 } | |
| 851 return it->second; | |
| 852 } | |
| 853 | |
| 854 void SSLClientSocketPool::DeleteSSLConnectJobMessenger( | |
| 855 const std::string& cache_key) { | |
| 856 MessengerMap::iterator it = messenger_map_.find(cache_key); | |
| 857 CHECK(it != messenger_map_.end()); | |
| 858 delete it->second; | |
| 859 messenger_map_.erase(it); | |
| 860 } | |
| 861 | |
| 862 void SSLClientSocketPool::OnSSLConfigChanged() { | 698 void SSLClientSocketPool::OnSSLConfigChanged() { |
| 863 FlushWithError(ERR_NETWORK_CHANGED); | 699 FlushWithError(ERR_NETWORK_CHANGED); |
| 864 } | 700 } |
| 865 | 701 |
| 866 } // namespace net | 702 } // namespace net |
| OLD | NEW |