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