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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 | 90 |
| 91 const scoped_refptr<HttpProxySocketParams>& | 91 const scoped_refptr<HttpProxySocketParams>& |
| 92 SSLSocketParams::GetHttpProxyConnectionParams() const { | 92 SSLSocketParams::GetHttpProxyConnectionParams() const { |
| 93 DCHECK_EQ(GetConnectionType(), HTTP_PROXY); | 93 DCHECK_EQ(GetConnectionType(), HTTP_PROXY); |
| 94 return http_proxy_params_; | 94 return http_proxy_params_; |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Timeout for the SSL handshake portion of the connect. | 97 // Timeout for the SSL handshake portion of the connect. |
| 98 static const int kSSLHandshakeTimeoutInSeconds = 30; | 98 static const int kSSLHandshakeTimeoutInSeconds = 30; |
| 99 | 99 |
| 100 // Note: the SSLConnectJob does not own pending_jobs_list | |
| 101 // so it must outlive the job. | |
|
wtc
2014/06/19 19:38:11
Please move this comment to the .h file. Ideally s
mshelley1
2014/06/24 17:03:59
Done.
| |
| 100 SSLConnectJob::SSLConnectJob(const std::string& group_name, | 102 SSLConnectJob::SSLConnectJob(const std::string& group_name, |
| 101 RequestPriority priority, | 103 RequestPriority priority, |
| 102 const scoped_refptr<SSLSocketParams>& params, | 104 const scoped_refptr<SSLSocketParams>& params, |
| 103 const base::TimeDelta& timeout_duration, | 105 const base::TimeDelta& timeout_duration, |
| 104 TransportClientSocketPool* transport_pool, | 106 TransportClientSocketPool* transport_pool, |
| 105 SOCKSClientSocketPool* socks_pool, | 107 SOCKSClientSocketPool* socks_pool, |
| 106 HttpProxyClientSocketPool* http_proxy_pool, | 108 HttpProxyClientSocketPool* http_proxy_pool, |
| 107 ClientSocketFactory* client_socket_factory, | 109 ClientSocketFactory* client_socket_factory, |
| 108 HostResolver* host_resolver, | 110 HostResolver* host_resolver, |
| 109 const SSLClientSocketContext& context, | 111 const SSLClientSocketContext& context, |
| 112 PendingJobList* pending_jobs_list, | |
| 110 Delegate* delegate, | 113 Delegate* delegate, |
| 111 NetLog* net_log) | 114 NetLog* net_log) |
| 112 : ConnectJob(group_name, | 115 : ConnectJob(group_name, |
| 113 timeout_duration, | 116 timeout_duration, |
| 114 priority, | 117 priority, |
| 115 delegate, | 118 delegate, |
| 116 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 119 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 117 params_(params), | 120 params_(params), |
| 118 transport_pool_(transport_pool), | 121 transport_pool_(transport_pool), |
| 119 socks_pool_(socks_pool), | 122 socks_pool_(socks_pool), |
| 120 http_proxy_pool_(http_proxy_pool), | 123 http_proxy_pool_(http_proxy_pool), |
| 121 client_socket_factory_(client_socket_factory), | 124 client_socket_factory_(client_socket_factory), |
| 122 host_resolver_(host_resolver), | 125 host_resolver_(host_resolver), |
| 123 context_(context.cert_verifier, | 126 context_(context.cert_verifier, |
| 124 context.server_bound_cert_service, | 127 context.server_bound_cert_service, |
| 125 context.transport_security_state, | 128 context.transport_security_state, |
| 126 context.cert_transparency_verifier, | 129 context.cert_transparency_verifier, |
| 127 (params->privacy_mode() == PRIVACY_MODE_ENABLED | 130 (params->privacy_mode() == PRIVACY_MODE_ENABLED |
| 128 ? "pm/" + context.ssl_session_cache_shard | 131 ? "pm/" + context.ssl_session_cache_shard |
| 129 : context.ssl_session_cache_shard)), | 132 : context.ssl_session_cache_shard)), |
| 130 callback_(base::Bind(&SSLConnectJob::OnIOComplete, | 133 io_callback_( |
| 131 base::Unretained(this))) {} | 134 base::Bind(&SSLConnectJob::OnIOComplete, base::Unretained(this))), |
| 135 pending_jobs_(pending_jobs_list) { | |
| 136 } | |
| 132 | 137 |
| 133 SSLConnectJob::~SSLConnectJob() {} | 138 SSLConnectJob::~SSLConnectJob() {} |
| 134 | 139 |
| 140 // static | |
| 141 bool SSLConnectJob::enable_job_waiting_ = false; | |
| 142 | |
| 135 LoadState SSLConnectJob::GetLoadState() const { | 143 LoadState SSLConnectJob::GetLoadState() const { |
| 136 switch (next_state_) { | 144 switch (next_state_) { |
| 137 case STATE_TUNNEL_CONNECT_COMPLETE: | 145 case STATE_TUNNEL_CONNECT_COMPLETE: |
| 138 if (transport_socket_handle_->socket()) | 146 if (transport_socket_handle_->socket()) |
| 139 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; | 147 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; |
| 140 // else, fall through. | 148 // else, fall through. |
| 141 case STATE_TRANSPORT_CONNECT: | 149 case STATE_TRANSPORT_CONNECT: |
| 142 case STATE_TRANSPORT_CONNECT_COMPLETE: | 150 case STATE_TRANSPORT_CONNECT_COMPLETE: |
| 143 case STATE_SOCKS_CONNECT: | 151 case STATE_SOCKS_CONNECT: |
| 144 case STATE_SOCKS_CONNECT_COMPLETE: | 152 case STATE_SOCKS_CONNECT_COMPLETE: |
| 145 case STATE_TUNNEL_CONNECT: | 153 case STATE_TUNNEL_CONNECT: |
| 146 return transport_socket_handle_->GetLoadState(); | 154 return transport_socket_handle_->GetLoadState(); |
| 155 case STATE_CREATE_SSL_SOCKET: | |
| 156 case STATE_CHECK_FOR_RESUME: | |
| 147 case STATE_SSL_CONNECT: | 157 case STATE_SSL_CONNECT: |
| 148 case STATE_SSL_CONNECT_COMPLETE: | 158 case STATE_SSL_CONNECT_COMPLETE: |
| 149 return LOAD_STATE_SSL_HANDSHAKE; | 159 return LOAD_STATE_SSL_HANDSHAKE; |
| 150 default: | 160 default: |
| 151 NOTREACHED(); | 161 NOTREACHED(); |
| 152 return LOAD_STATE_IDLE; | 162 return LOAD_STATE_IDLE; |
| 153 } | 163 } |
| 154 } | 164 } |
| 155 | 165 |
| 156 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { | 166 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { |
| 157 // Headers in |error_response_info_| indicate a proxy tunnel setup | 167 // Headers in |error_response_info_| indicate a proxy tunnel setup |
| 158 // problem. See DoTunnelConnectComplete. | 168 // problem. See DoTunnelConnectComplete. |
| 159 if (error_response_info_.headers.get()) { | 169 if (error_response_info_.headers.get()) { |
| 160 handle->set_pending_http_proxy_connection( | 170 handle->set_pending_http_proxy_connection( |
| 161 transport_socket_handle_.release()); | 171 transport_socket_handle_.release()); |
| 162 } | 172 } |
| 163 handle->set_ssl_error_response_info(error_response_info_); | 173 handle->set_ssl_error_response_info(error_response_info_); |
| 164 if (!connect_timing_.ssl_start.is_null()) | 174 if (!connect_timing_.ssl_start.is_null()) |
| 165 handle->set_is_ssl_error(true); | 175 handle->set_is_ssl_error(true); |
| 166 } | 176 } |
| 167 | 177 |
| 178 void SSLConnectJob::EnableJobWaiting(bool enable) { | |
| 179 enable_job_waiting_ = enable; | |
| 180 } | |
| 181 | |
| 168 void SSLConnectJob::OnIOComplete(int result) { | 182 void SSLConnectJob::OnIOComplete(int result) { |
| 169 int rv = DoLoop(result); | 183 int rv = DoLoop(result); |
| 170 if (rv != ERR_IO_PENDING) | 184 if (rv != ERR_IO_PENDING) |
| 171 NotifyDelegateOfCompletion(rv); // Deletes |this|. | 185 NotifyDelegateOfCompletion(rv); // Deletes |this|. |
| 172 } | 186 } |
| 173 | 187 |
| 174 int SSLConnectJob::DoLoop(int result) { | 188 int SSLConnectJob::DoLoop(int result) { |
| 175 DCHECK_NE(next_state_, STATE_NONE); | 189 DCHECK_NE(next_state_, STATE_NONE); |
| 176 | 190 |
| 177 int rv = result; | 191 int rv = result; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 193 case STATE_SOCKS_CONNECT_COMPLETE: | 207 case STATE_SOCKS_CONNECT_COMPLETE: |
| 194 rv = DoSOCKSConnectComplete(rv); | 208 rv = DoSOCKSConnectComplete(rv); |
| 195 break; | 209 break; |
| 196 case STATE_TUNNEL_CONNECT: | 210 case STATE_TUNNEL_CONNECT: |
| 197 DCHECK_EQ(OK, rv); | 211 DCHECK_EQ(OK, rv); |
| 198 rv = DoTunnelConnect(); | 212 rv = DoTunnelConnect(); |
| 199 break; | 213 break; |
| 200 case STATE_TUNNEL_CONNECT_COMPLETE: | 214 case STATE_TUNNEL_CONNECT_COMPLETE: |
| 201 rv = DoTunnelConnectComplete(rv); | 215 rv = DoTunnelConnectComplete(rv); |
| 202 break; | 216 break; |
| 217 case STATE_CREATE_SSL_SOCKET: | |
| 218 rv = DoCreateSSLSocket(); | |
| 219 break; | |
| 220 case STATE_CHECK_FOR_RESUME: | |
| 221 rv = DoCheckForResume(); | |
| 222 break; | |
| 203 case STATE_SSL_CONNECT: | 223 case STATE_SSL_CONNECT: |
| 204 DCHECK_EQ(OK, rv); | 224 DCHECK_EQ(OK, rv); |
| 205 rv = DoSSLConnect(); | 225 rv = DoSSLConnect(); |
| 206 break; | 226 break; |
| 207 case STATE_SSL_CONNECT_COMPLETE: | 227 case STATE_SSL_CONNECT_COMPLETE: |
| 208 rv = DoSSLConnectComplete(rv); | 228 rv = DoSSLConnectComplete(rv); |
| 209 break; | 229 break; |
| 210 default: | 230 default: |
| 211 NOTREACHED() << "bad state"; | 231 NOTREACHED() << "bad state"; |
| 212 rv = ERR_FAILED; | 232 rv = ERR_FAILED; |
| 213 break; | 233 break; |
| 214 } | 234 } |
| 215 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 235 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 216 | 236 |
| 217 return rv; | 237 return rv; |
| 218 } | 238 } |
| 219 | 239 |
| 220 int SSLConnectJob::DoTransportConnect() { | 240 int SSLConnectJob::DoTransportConnect() { |
| 221 DCHECK(transport_pool_); | 241 DCHECK(transport_pool_); |
| 222 | 242 |
| 223 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; | 243 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; |
| 224 transport_socket_handle_.reset(new ClientSocketHandle()); | 244 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 225 scoped_refptr<TransportSocketParams> direct_params = | 245 scoped_refptr<TransportSocketParams> direct_params = |
| 226 params_->GetDirectConnectionParams(); | 246 params_->GetDirectConnectionParams(); |
| 227 return transport_socket_handle_->Init(group_name(), | 247 return transport_socket_handle_->Init(group_name(), |
| 228 direct_params, | 248 direct_params, |
| 229 priority(), | 249 priority(), |
| 230 callback_, | 250 io_callback_, |
| 231 transport_pool_, | 251 transport_pool_, |
| 232 net_log()); | 252 net_log()); |
| 233 } | 253 } |
| 234 | 254 |
| 235 int SSLConnectJob::DoTransportConnectComplete(int result) { | 255 int SSLConnectJob::DoTransportConnectComplete(int result) { |
| 236 if (result == OK) | 256 if (result != OK) |
| 237 next_state_ = STATE_SSL_CONNECT; | 257 return result; |
| 258 | |
| 259 next_state_ = STATE_CREATE_SSL_SOCKET; | |
|
wtc
2014/06/19 19:38:11
Nit: keep this method and DoSOCKSConnectComplete (
mshelley1
2014/06/24 17:03:59
Done.
| |
| 238 | 260 |
| 239 return result; | 261 return result; |
| 240 } | 262 } |
| 241 | 263 |
| 242 int SSLConnectJob::DoSOCKSConnect() { | 264 int SSLConnectJob::DoSOCKSConnect() { |
| 243 DCHECK(socks_pool_); | 265 DCHECK(socks_pool_); |
| 244 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; | 266 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; |
| 245 transport_socket_handle_.reset(new ClientSocketHandle()); | 267 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 246 scoped_refptr<SOCKSSocketParams> socks_proxy_params = | 268 scoped_refptr<SOCKSSocketParams> socks_proxy_params = |
| 247 params_->GetSocksProxyConnectionParams(); | 269 params_->GetSocksProxyConnectionParams(); |
| 248 return transport_socket_handle_->Init(group_name(), | 270 return transport_socket_handle_->Init(group_name(), |
| 249 socks_proxy_params, | 271 socks_proxy_params, |
| 250 priority(), | 272 priority(), |
| 251 callback_, | 273 io_callback_, |
| 252 socks_pool_, | 274 socks_pool_, |
| 253 net_log()); | 275 net_log()); |
| 254 } | 276 } |
| 255 | 277 |
| 256 int SSLConnectJob::DoSOCKSConnectComplete(int result) { | 278 int SSLConnectJob::DoSOCKSConnectComplete(int result) { |
| 257 if (result == OK) | 279 if (result == OK) |
| 258 next_state_ = STATE_SSL_CONNECT; | 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; |
| 315 next_state_ = STATE_CREATE_SSL_SOCKET; | |
| 293 | 316 |
|
wtc
2014/06/19 19:38:10
Nit: reverse lines 315 and 316.
mshelley1
2014/06/24 17:03:59
Done.
| |
| 294 next_state_ = STATE_SSL_CONNECT; | |
| 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 } |
|
wtc
2014/06/19 19:38:10
Please confirm that you think lines 325-340 should
mshelley1
2014/06/24 17:03:59
Yes -- I don't completely understand why, but leav
| |
| 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 is in the cache, continue with the session resumption | |
|
wtc
2014/06/19 19:38:10
Nit: say "If the group's session is in the cache"
mshelley1
2014/06/24 17:03:59
Done.
| |
| 352 // SSL handshake. | |
| 353 if (ssl_socket_->InSessionCache()) { | |
| 354 next_state_ = STATE_SSL_CONNECT; | |
| 355 return OK; | |
| 356 } | |
| 357 | |
| 358 // If there are pending jobs, wait. | |
| 359 if (!pending_jobs_->empty()) { | |
| 360 pending_jobs_->push_back(this); | |
| 361 next_state_ = STATE_CHECK_FOR_RESUME; | |
|
wtc
2014/06/19 19:38:11
I think we should change next_state_ to STATE_SSL_
mshelley1
2014/06/24 17:03:59
Done.
| |
| 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 pending_jobs_->push_back(this); | |
|
wtc
2014/06/19 19:38:11
I got confused by this before, so a comment might
mshelley1
2014/06/24 17:03:59
Done.
| |
| 368 next_state_ = STATE_SSL_CONNECT; | |
| 369 return OK; | |
| 370 } | |
| 371 | |
| 372 int SSLConnectJob::DoSSLConnect() { | |
| 373 next_state_ = STATE_SSL_CONNECT_COMPLETE; | |
| 374 | |
| 375 connect_timing_.ssl_start = base::TimeTicks::Now(); | |
| 376 | |
| 377 return ssl_socket_->Connect(io_callback_); | |
| 325 } | 378 } |
| 326 | 379 |
| 327 int SSLConnectJob::DoSSLConnectComplete(int result) { | 380 int SSLConnectJob::DoSSLConnectComplete(int result) { |
| 328 connect_timing_.ssl_end = base::TimeTicks::Now(); | 381 connect_timing_.ssl_end = base::TimeTicks::Now(); |
| 329 | 382 |
| 330 SSLClientSocket::NextProtoStatus status = | 383 SSLClientSocket::NextProtoStatus status = |
| 331 SSLClientSocket::kNextProtoUnsupported; | 384 SSLClientSocket::kNextProtoUnsupported; |
| 332 std::string proto; | 385 std::string proto; |
| 333 std::string server_protos; | 386 std::string server_protos; |
| 334 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket | 387 // 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 | 388 // 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. | 389 // here, then we know that we called SSL_ImportFD. |
| 337 if (result == OK || IsCertificateError(result)) | 390 if (result == OK || IsCertificateError(result)) |
| 338 status = ssl_socket_->GetNextProto(&proto, &server_protos); | 391 status = ssl_socket_->GetNextProto(&proto, &server_protos); |
| 339 | 392 |
| 340 // If we want spdy over npn, make sure it succeeded. | 393 // If we want spdy over npn, make sure it succeeded. |
| 341 if (status == SSLClientSocket::kNextProtoNegotiated) { | 394 if (status == SSLClientSocket::kNextProtoNegotiated) { |
| 342 ssl_socket_->set_was_npn_negotiated(true); | 395 ssl_socket_->set_was_npn_negotiated(true); |
| 343 NextProto protocol_negotiated = | 396 NextProto protocol_negotiated = |
| 344 SSLClientSocket::NextProtoFromString(proto); | 397 SSLClientSocket::NextProtoFromString(proto); |
| 345 ssl_socket_->set_protocol_negotiated(protocol_negotiated); | 398 ssl_socket_->set_protocol_negotiated(protocol_negotiated); |
| 346 // If we negotiated a SPDY version, it must have been present in | 399 // If we negotiated a SPDY version, it must have been present in |
| 347 // SSLConfig::next_protos. | 400 // SSLConfig::next_protos. |
| 348 // TODO(mbelshe): Verify this. | 401 // TODO(mbelshe): Verify this. |
| 349 if (protocol_negotiated >= kProtoSPDYMinimumVersion && | 402 if (protocol_negotiated >= kProtoSPDYMinimumVersion && |
| 350 protocol_negotiated <= kProtoSPDYMaximumVersion) { | 403 protocol_negotiated <= kProtoSPDYMaximumVersion) { |
| 351 ssl_socket_->set_was_spdy_negotiated(true); | 404 ssl_socket_->set_was_spdy_negotiated(true); |
| 352 } | 405 } |
| 353 } | 406 } |
| 354 if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated()) | 407 if (params_->want_spdy_over_npn() && !ssl_socket_->was_spdy_negotiated()) { |
| 408 if (enable_job_waiting_) | |
| 409 ProcessPendingJobs(ERR_NPN_NEGOTIATION_FAILED); | |
| 355 return ERR_NPN_NEGOTIATION_FAILED; | 410 return ERR_NPN_NEGOTIATION_FAILED; |
| 411 } | |
| 356 | 412 |
| 357 // Spdy might be turned on by default, or it might be over npn. | 413 // Spdy might be turned on by default, or it might be over npn. |
| 358 bool using_spdy = params_->force_spdy_over_ssl() || | 414 bool using_spdy = params_->force_spdy_over_ssl() || |
| 359 params_->want_spdy_over_npn(); | 415 params_->want_spdy_over_npn(); |
| 360 | 416 |
| 361 if (result == OK || | 417 if (result == OK || |
| 362 ssl_socket_->IgnoreCertError(result, params_->load_flags())) { | 418 ssl_socket_->IgnoreCertError(result, params_->load_flags())) { |
| 363 DCHECK(!connect_timing_.ssl_start.is_null()); | 419 DCHECK(!connect_timing_.ssl_start.is_null()); |
| 364 base::TimeDelta connect_duration = | 420 base::TimeDelta connect_duration = |
| 365 connect_timing_.ssl_end - connect_timing_.ssl_start; | 421 connect_timing_.ssl_end - connect_timing_.ssl_start; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 100); | 460 100); |
| 405 } else if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_FULL) { | 461 } else if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_FULL) { |
| 406 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Full_Handshake", | 462 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Full_Handshake", |
| 407 connect_duration, | 463 connect_duration, |
| 408 base::TimeDelta::FromMilliseconds(1), | 464 base::TimeDelta::FromMilliseconds(1), |
| 409 base::TimeDelta::FromMinutes(1), | 465 base::TimeDelta::FromMinutes(1), |
| 410 100); | 466 100); |
| 411 } | 467 } |
| 412 | 468 |
| 413 const std::string& host = params_->host_and_port().host(); | 469 const std::string& host = params_->host_and_port().host(); |
| 414 bool is_google = host == "google.com" || | 470 bool is_google = |
| 415 (host.size() > 11 && | 471 host == "google.com" || |
| 416 host.rfind(".google.com") == host.size() - 11); | 472 (host.size() > 11 && host.rfind(".google.com") == host.size() - 11); |
| 417 if (is_google) { | 473 if (is_google) { |
| 418 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2", | 474 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google2", |
| 419 connect_duration, | 475 connect_duration, |
| 420 base::TimeDelta::FromMilliseconds(1), | 476 base::TimeDelta::FromMilliseconds(1), |
| 421 base::TimeDelta::FromMinutes(1), | 477 base::TimeDelta::FromMinutes(1), |
| 422 100); | 478 100); |
| 423 if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME) { | 479 if (ssl_info.handshake_type == SSLInfo::HANDSHAKE_RESUME) { |
| 424 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_" | 480 UMA_HISTOGRAM_CUSTOM_TIMES("Net.SSL_Connection_Latency_Google_" |
| 425 "Resume_Handshake", | 481 "Resume_Handshake", |
| 426 connect_duration, | 482 connect_duration, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 439 } | 495 } |
| 440 | 496 |
| 441 if (result == OK || IsCertificateError(result)) { | 497 if (result == OK || IsCertificateError(result)) { |
| 442 SetSocket(ssl_socket_.PassAs<StreamSocket>()); | 498 SetSocket(ssl_socket_.PassAs<StreamSocket>()); |
| 443 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 499 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 444 error_response_info_.cert_request_info = new SSLCertRequestInfo; | 500 error_response_info_.cert_request_info = new SSLCertRequestInfo; |
| 445 ssl_socket_->GetSSLCertRequestInfo( | 501 ssl_socket_->GetSSLCertRequestInfo( |
| 446 error_response_info_.cert_request_info.get()); | 502 error_response_info_.cert_request_info.get()); |
| 447 } | 503 } |
| 448 | 504 |
| 505 if (enable_job_waiting_) | |
| 506 ProcessPendingJobs(result); | |
| 507 | |
| 449 return result; | 508 return result; |
| 450 } | 509 } |
| 451 | 510 |
| 511 void SSLConnectJob::ProcessPendingJobs(int result) { | |
| 512 // If there is a pending list | |
| 513 if (!pending_jobs_->empty()) { | |
| 514 // The first element of the vector will always be the leading job. | |
| 515 PendingJobList::iterator it = pending_jobs_->begin(); | |
| 516 | |
| 517 if (result == OK) { | |
| 518 // If the connection was successful, tell all pending jobs to proceed. | |
| 519 for (PendingJobList::iterator job = it + 1; job != pending_jobs_->end(); | |
| 520 ++job) { | |
| 521 (*job)->ResumeSSLConnection(); | |
| 522 } | |
| 523 pending_jobs_->clear(); | |
| 524 } else { | |
| 525 // If the connection failed, tell one (if any) of the remaining jobs | |
| 526 // to proceed as the new leader. | |
| 527 if (it + 1 != pending_jobs_->end()) | |
| 528 (*(it + 1))->ResumeSSLConnection(); | |
| 529 pending_jobs_->erase(it); | |
|
wtc
2014/06/19 19:38:10
We should figure out how to erase the first job or
mshelley1
2014/06/24 17:03:59
Done.
| |
| 530 } | |
| 531 } | |
| 532 } | |
| 533 | |
| 534 void SSLConnectJob::ResumeSSLConnection() { | |
| 535 DCHECK_EQ(next_state_, STATE_CHECK_FOR_RESUME); | |
| 536 next_state_ = STATE_SSL_CONNECT; | |
| 537 OnIOComplete(OK); | |
| 538 } | |
| 539 | |
| 452 SSLConnectJob::State SSLConnectJob::GetInitialState( | 540 SSLConnectJob::State SSLConnectJob::GetInitialState( |
| 453 SSLSocketParams::ConnectionType connection_type) { | 541 SSLSocketParams::ConnectionType connection_type) { |
| 454 switch (connection_type) { | 542 switch (connection_type) { |
| 455 case SSLSocketParams::DIRECT: | 543 case SSLSocketParams::DIRECT: |
| 456 return STATE_TRANSPORT_CONNECT; | 544 return STATE_TRANSPORT_CONNECT; |
| 457 case SSLSocketParams::HTTP_PROXY: | 545 case SSLSocketParams::HTTP_PROXY: |
| 458 return STATE_TUNNEL_CONNECT; | 546 return STATE_TUNNEL_CONNECT; |
| 459 case SSLSocketParams::SOCKS_PROXY: | 547 case SSLSocketParams::SOCKS_PROXY: |
| 460 return STATE_SOCKS_CONNECT; | 548 return STATE_SOCKS_CONNECT; |
| 461 } | 549 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 475 ClientSocketFactory* client_socket_factory, | 563 ClientSocketFactory* client_socket_factory, |
| 476 HostResolver* host_resolver, | 564 HostResolver* host_resolver, |
| 477 const SSLClientSocketContext& context, | 565 const SSLClientSocketContext& context, |
| 478 NetLog* net_log) | 566 NetLog* net_log) |
| 479 : transport_pool_(transport_pool), | 567 : transport_pool_(transport_pool), |
| 480 socks_pool_(socks_pool), | 568 socks_pool_(socks_pool), |
| 481 http_proxy_pool_(http_proxy_pool), | 569 http_proxy_pool_(http_proxy_pool), |
| 482 client_socket_factory_(client_socket_factory), | 570 client_socket_factory_(client_socket_factory), |
| 483 host_resolver_(host_resolver), | 571 host_resolver_(host_resolver), |
| 484 context_(context), | 572 context_(context), |
| 485 net_log_(net_log) { | 573 net_log_(net_log), |
| 574 pending_jobs_map_(new PendingJobMap()) { | |
| 486 base::TimeDelta max_transport_timeout = base::TimeDelta(); | 575 base::TimeDelta max_transport_timeout = base::TimeDelta(); |
| 487 base::TimeDelta pool_timeout; | 576 base::TimeDelta pool_timeout; |
| 488 if (transport_pool_) | 577 if (transport_pool_) |
| 489 max_transport_timeout = transport_pool_->ConnectionTimeout(); | 578 max_transport_timeout = transport_pool_->ConnectionTimeout(); |
| 490 if (socks_pool_) { | 579 if (socks_pool_) { |
| 491 pool_timeout = socks_pool_->ConnectionTimeout(); | 580 pool_timeout = socks_pool_->ConnectionTimeout(); |
| 492 if (pool_timeout > max_transport_timeout) | 581 if (pool_timeout > max_transport_timeout) |
| 493 max_transport_timeout = pool_timeout; | 582 max_transport_timeout = pool_timeout; |
| 494 } | 583 } |
| 495 if (http_proxy_pool_) { | 584 if (http_proxy_pool_) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 513 const std::string& ssl_session_cache_shard, | 602 const std::string& ssl_session_cache_shard, |
| 514 ClientSocketFactory* client_socket_factory, | 603 ClientSocketFactory* client_socket_factory, |
| 515 TransportClientSocketPool* transport_pool, | 604 TransportClientSocketPool* transport_pool, |
| 516 SOCKSClientSocketPool* socks_pool, | 605 SOCKSClientSocketPool* socks_pool, |
| 517 HttpProxyClientSocketPool* http_proxy_pool, | 606 HttpProxyClientSocketPool* http_proxy_pool, |
| 518 SSLConfigService* ssl_config_service, | 607 SSLConfigService* ssl_config_service, |
| 519 NetLog* net_log) | 608 NetLog* net_log) |
| 520 : transport_pool_(transport_pool), | 609 : transport_pool_(transport_pool), |
| 521 socks_pool_(socks_pool), | 610 socks_pool_(socks_pool), |
| 522 http_proxy_pool_(http_proxy_pool), | 611 http_proxy_pool_(http_proxy_pool), |
| 523 base_(this, max_sockets, max_sockets_per_group, histograms, | 612 base_(this, |
| 613 max_sockets, | |
| 614 max_sockets_per_group, | |
| 615 histograms, | |
| 524 ClientSocketPool::unused_idle_socket_timeout(), | 616 ClientSocketPool::unused_idle_socket_timeout(), |
| 525 ClientSocketPool::used_idle_socket_timeout(), | 617 ClientSocketPool::used_idle_socket_timeout(), |
| 526 new SSLConnectJobFactory(transport_pool, | 618 new SSLConnectJobFactory( |
| 527 socks_pool, | 619 transport_pool, |
| 528 http_proxy_pool, | 620 socks_pool, |
| 529 client_socket_factory, | 621 http_proxy_pool, |
| 530 host_resolver, | 622 client_socket_factory, |
| 531 SSLClientSocketContext( | 623 host_resolver, |
| 532 cert_verifier, | 624 SSLClientSocketContext(cert_verifier, |
| 533 server_bound_cert_service, | 625 server_bound_cert_service, |
| 534 transport_security_state, | 626 transport_security_state, |
| 535 cert_transparency_verifier, | 627 cert_transparency_verifier, |
| 536 ssl_session_cache_shard), | 628 ssl_session_cache_shard), |
| 537 net_log)), | 629 net_log)), |
| 538 ssl_config_service_(ssl_config_service) { | 630 ssl_config_service_(ssl_config_service) { |
| 539 if (ssl_config_service_.get()) | 631 if (ssl_config_service_.get()) |
| 540 ssl_config_service_->AddObserver(this); | 632 ssl_config_service_->AddObserver(this); |
| 541 if (transport_pool_) | 633 if (transport_pool_) |
| 542 base_.AddLowerLayeredPool(transport_pool_); | 634 base_.AddLowerLayeredPool(transport_pool_); |
| 543 if (socks_pool_) | 635 if (socks_pool_) |
| 544 base_.AddLowerLayeredPool(socks_pool_); | 636 base_.AddLowerLayeredPool(socks_pool_); |
| 545 if (http_proxy_pool_) | 637 if (http_proxy_pool_) |
| 546 base_.AddLowerLayeredPool(http_proxy_pool_); | 638 base_.AddLowerLayeredPool(http_proxy_pool_); |
| 547 } | 639 } |
| 548 | 640 |
| 549 SSLClientSocketPool::~SSLClientSocketPool() { | 641 SSLClientSocketPool::~SSLClientSocketPool() { |
| 550 if (ssl_config_service_.get()) | 642 if (ssl_config_service_.get()) |
| 551 ssl_config_service_->RemoveObserver(this); | 643 ssl_config_service_->RemoveObserver(this); |
| 552 } | 644 } |
| 553 | 645 |
| 554 scoped_ptr<ConnectJob> | 646 scoped_ptr<ConnectJob> |
| 555 SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( | 647 SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( |
| 556 const std::string& group_name, | 648 const std::string& group_name, |
| 557 const PoolBase::Request& request, | 649 const PoolBase::Request& request, |
| 558 ConnectJob::Delegate* delegate) const { | 650 ConnectJob::Delegate* delegate) const { |
| 559 return scoped_ptr<ConnectJob>( | 651 SSLConnectJob::PendingJobList* pending_job_list; |
|
wtc
2014/06/19 19:38:10
This code should also be controlled by the enable_
mshelley1
2014/06/24 17:03:59
Done.
| |
| 560 new SSLConnectJob(group_name, request.priority(), request.params(), | 652 std::pair<PendingJobMap::iterator, bool> it = |
| 561 ConnectionTimeout(), transport_pool_, socks_pool_, | 653 pending_jobs_map_->insert(PendingJobMap::value_type( |
| 562 http_proxy_pool_, client_socket_factory_, | 654 group_name, new SSLConnectJob::PendingJobList())); |
|
wtc
2014/06/19 19:38:11
IMPORTANT: there are two memory leaks of PendingJo
mshelley1
2014/06/24 17:03:59
Done.
| |
| 563 host_resolver_, context_, delegate, net_log_)); | 655 pending_job_list = it.first->second; |
|
wtc
2014/06/19 19:38:11
Nit: Delete the declaration of pending_job_list on
mshelley1
2014/06/24 17:03:59
Done.
| |
| 656 | |
| 657 return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name, | |
| 658 request.priority(), | |
| 659 request.params(), | |
| 660 ConnectionTimeout(), | |
| 661 transport_pool_, | |
| 662 socks_pool_, | |
| 663 http_proxy_pool_, | |
| 664 client_socket_factory_, | |
| 665 host_resolver_, | |
| 666 context_, | |
| 667 pending_job_list, | |
| 668 delegate, | |
| 669 net_log_)); | |
| 564 } | 670 } |
| 565 | 671 |
| 566 base::TimeDelta | 672 base::TimeDelta |
| 567 SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() const { | 673 SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() const { |
| 568 return timeout_; | 674 return timeout_; |
| 569 } | 675 } |
| 570 | 676 |
| 571 int SSLClientSocketPool::RequestSocket(const std::string& group_name, | 677 int SSLClientSocketPool::RequestSocket(const std::string& group_name, |
| 572 const void* socket_params, | 678 const void* socket_params, |
| 573 RequestPriority priority, | 679 RequestPriority priority, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 677 if (base_.CloseOneIdleSocket()) | 783 if (base_.CloseOneIdleSocket()) |
| 678 return true; | 784 return true; |
| 679 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 785 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
| 680 } | 786 } |
| 681 | 787 |
| 682 void SSLClientSocketPool::OnSSLConfigChanged() { | 788 void SSLClientSocketPool::OnSSLConfigChanged() { |
| 683 FlushWithError(ERR_NETWORK_CHANGED); | 789 FlushWithError(ERR_NETWORK_CHANGED); |
| 684 } | 790 } |
| 685 | 791 |
| 686 } // namespace net | 792 } // namespace net |
| OLD | NEW |