| 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_( |
| 203 base::Bind(&SSLConnectJob::OnIOComplete, base::Unretained(this))), | 130 base::Bind(&SSLConnectJob::OnIOComplete, base::Unretained(this))) { |
| 204 messenger_(NULL), | |
| 205 get_messenger_callback_(get_messenger_callback), | |
| 206 weak_factory_(this) { | |
| 207 } | 131 } |
| 208 | 132 |
| 209 SSLConnectJob::~SSLConnectJob() { | 133 SSLConnectJob::~SSLConnectJob() { |
| 210 if (ssl_socket_.get() && messenger_) | |
| 211 messenger_->RemovePendingSocket(ssl_socket_.get()); | |
| 212 } | 134 } |
| 213 | 135 |
| 214 LoadState SSLConnectJob::GetLoadState() const { | 136 LoadState SSLConnectJob::GetLoadState() const { |
| 215 switch (next_state_) { | 137 switch (next_state_) { |
| 216 case STATE_TUNNEL_CONNECT_COMPLETE: | 138 case STATE_TUNNEL_CONNECT_COMPLETE: |
| 217 if (transport_socket_handle_->socket()) | 139 if (transport_socket_handle_->socket()) |
| 218 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; | 140 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; |
| 219 // else, fall through. | 141 // else, fall through. |
| 220 case STATE_TRANSPORT_CONNECT: | 142 case STATE_TRANSPORT_CONNECT: |
| 221 case STATE_TRANSPORT_CONNECT_COMPLETE: | 143 case STATE_TRANSPORT_CONNECT_COMPLETE: |
| 222 case STATE_SOCKS_CONNECT: | 144 case STATE_SOCKS_CONNECT: |
| 223 case STATE_SOCKS_CONNECT_COMPLETE: | 145 case STATE_SOCKS_CONNECT_COMPLETE: |
| 224 case STATE_TUNNEL_CONNECT: | 146 case STATE_TUNNEL_CONNECT: |
| 225 return transport_socket_handle_->GetLoadState(); | 147 return transport_socket_handle_->GetLoadState(); |
| 226 case STATE_CREATE_SSL_SOCKET: | |
| 227 case STATE_CHECK_FOR_RESUME: | |
| 228 case STATE_SSL_CONNECT: | 148 case STATE_SSL_CONNECT: |
| 229 case STATE_SSL_CONNECT_COMPLETE: | 149 case STATE_SSL_CONNECT_COMPLETE: |
| 230 return LOAD_STATE_SSL_HANDSHAKE; | 150 return LOAD_STATE_SSL_HANDSHAKE; |
| 231 default: | 151 default: |
| 232 NOTREACHED(); | 152 NOTREACHED(); |
| 233 return LOAD_STATE_IDLE; | 153 return LOAD_STATE_IDLE; |
| 234 } | 154 } |
| 235 } | 155 } |
| 236 | 156 |
| 237 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { | 157 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 case STATE_SOCKS_CONNECT_COMPLETE: | 194 case STATE_SOCKS_CONNECT_COMPLETE: |
| 275 rv = DoSOCKSConnectComplete(rv); | 195 rv = DoSOCKSConnectComplete(rv); |
| 276 break; | 196 break; |
| 277 case STATE_TUNNEL_CONNECT: | 197 case STATE_TUNNEL_CONNECT: |
| 278 DCHECK_EQ(OK, rv); | 198 DCHECK_EQ(OK, rv); |
| 279 rv = DoTunnelConnect(); | 199 rv = DoTunnelConnect(); |
| 280 break; | 200 break; |
| 281 case STATE_TUNNEL_CONNECT_COMPLETE: | 201 case STATE_TUNNEL_CONNECT_COMPLETE: |
| 282 rv = DoTunnelConnectComplete(rv); | 202 rv = DoTunnelConnectComplete(rv); |
| 283 break; | 203 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: | 204 case STATE_SSL_CONNECT: |
| 291 DCHECK_EQ(OK, rv); | 205 DCHECK_EQ(OK, rv); |
| 292 rv = DoSSLConnect(); | 206 rv = DoSSLConnect(); |
| 293 break; | 207 break; |
| 294 case STATE_SSL_CONNECT_COMPLETE: | 208 case STATE_SSL_CONNECT_COMPLETE: |
| 295 rv = DoSSLConnectComplete(rv); | 209 rv = DoSSLConnectComplete(rv); |
| 296 break; | 210 break; |
| 297 default: | 211 default: |
| 298 NOTREACHED() << "bad state"; | 212 NOTREACHED() << "bad state"; |
| 299 rv = ERR_FAILED; | 213 rv = ERR_FAILED; |
| 300 break; | 214 break; |
| 301 } | 215 } |
| 302 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 216 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 303 | 217 |
| 304 return rv; | 218 return rv; |
| 305 } | 219 } |
| 306 | 220 |
| 307 int SSLConnectJob::DoTransportConnect() { | 221 int SSLConnectJob::DoTransportConnect() { |
| 308 DCHECK(transport_pool_); | 222 DCHECK(transport_pool_); |
| 309 | 223 |
| 310 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; | 224 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; |
| 311 transport_socket_handle_.reset(new ClientSocketHandle()); | 225 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 312 scoped_refptr<TransportSocketParams> direct_params = | 226 scoped_refptr<TransportSocketParams> direct_params = |
| 313 params_->GetDirectConnectionParams(); | 227 params_->GetDirectConnectionParams(); |
| 314 return transport_socket_handle_->Init(group_name(), | 228 return transport_socket_handle_->Init(group_name(), direct_params, priority(), |
| 315 direct_params, | 229 callback_, transport_pool_, net_log()); |
| 316 priority(), | |
| 317 io_callback_, | |
| 318 transport_pool_, | |
| 319 net_log()); | |
| 320 } | 230 } |
| 321 | 231 |
| 322 int SSLConnectJob::DoTransportConnectComplete(int result) { | 232 int SSLConnectJob::DoTransportConnectComplete(int result) { |
| 323 if (result == OK) | 233 if (result == OK) |
| 324 next_state_ = STATE_CREATE_SSL_SOCKET; | 234 next_state_ = STATE_SSL_CONNECT; |
| 325 | 235 |
| 326 return result; | 236 return result; |
| 327 } | 237 } |
| 328 | 238 |
| 329 int SSLConnectJob::DoSOCKSConnect() { | 239 int SSLConnectJob::DoSOCKSConnect() { |
| 330 DCHECK(socks_pool_); | 240 DCHECK(socks_pool_); |
| 331 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; | 241 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; |
| 332 transport_socket_handle_.reset(new ClientSocketHandle()); | 242 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 333 scoped_refptr<SOCKSSocketParams> socks_proxy_params = | 243 scoped_refptr<SOCKSSocketParams> socks_proxy_params = |
| 334 params_->GetSocksProxyConnectionParams(); | 244 params_->GetSocksProxyConnectionParams(); |
| 335 return transport_socket_handle_->Init(group_name(), | 245 return transport_socket_handle_->Init(group_name(), socks_proxy_params, |
| 336 socks_proxy_params, | 246 priority(), callback_, socks_pool_, |
| 337 priority(), | |
| 338 io_callback_, | |
| 339 socks_pool_, | |
| 340 net_log()); | 247 net_log()); |
| 341 } | 248 } |
| 342 | 249 |
| 343 int SSLConnectJob::DoSOCKSConnectComplete(int result) { | 250 int SSLConnectJob::DoSOCKSConnectComplete(int result) { |
| 344 if (result == OK) | 251 if (result == OK) |
| 345 next_state_ = STATE_CREATE_SSL_SOCKET; | 252 next_state_ = STATE_SSL_CONNECT; |
| 346 | 253 |
| 347 return result; | 254 return result; |
| 348 } | 255 } |
| 349 | 256 |
| 350 int SSLConnectJob::DoTunnelConnect() { | 257 int SSLConnectJob::DoTunnelConnect() { |
| 351 DCHECK(http_proxy_pool_); | 258 DCHECK(http_proxy_pool_); |
| 352 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; | 259 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; |
| 353 | 260 |
| 354 transport_socket_handle_.reset(new ClientSocketHandle()); | 261 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 355 scoped_refptr<HttpProxySocketParams> http_proxy_params = | 262 scoped_refptr<HttpProxySocketParams> http_proxy_params = |
| 356 params_->GetHttpProxyConnectionParams(); | 263 params_->GetHttpProxyConnectionParams(); |
| 357 return transport_socket_handle_->Init(group_name(), | 264 return transport_socket_handle_->Init(group_name(), http_proxy_params, |
| 358 http_proxy_params, | 265 priority(), callback_, http_proxy_pool_, |
| 359 priority(), | |
| 360 io_callback_, | |
| 361 http_proxy_pool_, | |
| 362 net_log()); | 266 net_log()); |
| 363 } | 267 } |
| 364 | 268 |
| 365 int SSLConnectJob::DoTunnelConnectComplete(int result) { | 269 int SSLConnectJob::DoTunnelConnectComplete(int result) { |
| 366 // Extract the information needed to prompt for appropriate proxy | 270 // Extract the information needed to prompt for appropriate proxy |
| 367 // authentication so that when ClientSocketPoolBaseHelper calls | 271 // authentication so that when ClientSocketPoolBaseHelper calls |
| 368 // |GetAdditionalErrorState|, we can easily set the state. | 272 // |GetAdditionalErrorState|, we can easily set the state. |
| 369 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 273 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 370 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); | 274 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); |
| 371 } else if (result == ERR_PROXY_AUTH_REQUESTED || | 275 } else if (result == ERR_PROXY_AUTH_REQUESTED || |
| 372 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { | 276 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { |
| 373 StreamSocket* socket = transport_socket_handle_->socket(); | 277 StreamSocket* socket = transport_socket_handle_->socket(); |
| 374 ProxyClientSocket* tunnel_socket = static_cast<ProxyClientSocket*>(socket); | 278 ProxyClientSocket* tunnel_socket = static_cast<ProxyClientSocket*>(socket); |
| 375 error_response_info_ = *tunnel_socket->GetConnectResponseInfo(); | 279 error_response_info_ = *tunnel_socket->GetConnectResponseInfo(); |
| 376 } | 280 } |
| 377 if (result < 0) | 281 if (result < 0) |
| 378 return result; | 282 return result; |
| 379 next_state_ = STATE_CREATE_SSL_SOCKET; | 283 |
| 284 next_state_ = STATE_SSL_CONNECT; |
| 380 return result; | 285 return result; |
| 381 } | 286 } |
| 382 | 287 |
| 383 int SSLConnectJob::DoCreateSSLSocket() { | 288 int SSLConnectJob::DoSSLConnect() { |
| 384 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462815 is fixed. | 289 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462815 is fixed. |
| 385 tracked_objects::ScopedTracker tracking_profile( | 290 tracked_objects::ScopedTracker tracking_profile( |
| 386 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 291 FROM_HERE_WITH_EXPLICIT_FUNCTION("462815 SSLConnectJob::DoSSLConnect")); |
| 387 "462815 SSLConnectJob::DoCreateSSLSocket")); | 292 |
| 388 next_state_ = STATE_CHECK_FOR_RESUME; | 293 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
| 389 | 294 |
| 390 // Reset the timeout to just the time allowed for the SSL handshake. | 295 // Reset the timeout to just the time allowed for the SSL handshake. |
| 391 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); | 296 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); |
| 392 | 297 |
| 393 // If the handle has a fresh socket, get its connect start and DNS times. | 298 // If the handle has a fresh socket, get its connect start and DNS times. |
| 394 // This should always be the case. | 299 // This should always be the case. |
| 395 const LoadTimingInfo::ConnectTiming& socket_connect_timing = | 300 const LoadTimingInfo::ConnectTiming& socket_connect_timing = |
| 396 transport_socket_handle_->connect_timing(); | 301 transport_socket_handle_->connect_timing(); |
| 397 if (!transport_socket_handle_->is_reused() && | 302 if (!transport_socket_handle_->is_reused() && |
| 398 !socket_connect_timing.connect_start.is_null()) { | 303 !socket_connect_timing.connect_start.is_null()) { |
| 399 // Overwriting |connect_start| serves two purposes - it adjusts timing so | 304 // Overwriting |connect_start| serves two purposes - it adjusts timing so |
| 400 // |connect_start| doesn't include dns times, and it adjusts the time so | 305 // |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. | 306 // as not to include time spent waiting for an idle socket. |
| 402 connect_timing_.connect_start = socket_connect_timing.connect_start; | 307 connect_timing_.connect_start = socket_connect_timing.connect_start; |
| 403 connect_timing_.dns_start = socket_connect_timing.dns_start; | 308 connect_timing_.dns_start = socket_connect_timing.dns_start; |
| 404 connect_timing_.dns_end = socket_connect_timing.dns_end; | 309 connect_timing_.dns_end = socket_connect_timing.dns_end; |
| 405 } | 310 } |
| 406 | 311 |
| 312 connect_timing_.ssl_start = base::TimeTicks::Now(); |
| 313 |
| 407 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket( | 314 ssl_socket_ = client_socket_factory_->CreateSSLClientSocket( |
| 408 transport_socket_handle_.Pass(), | 315 transport_socket_handle_.Pass(), |
| 409 params_->host_and_port(), | 316 params_->host_and_port(), |
| 410 params_->ssl_config(), | 317 params_->ssl_config(), |
| 411 context_); | 318 context_); |
| 412 | 319 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 } | 320 } |
| 450 | 321 |
| 451 int SSLConnectJob::DoSSLConnectComplete(int result) { | 322 int SSLConnectJob::DoSSLConnectComplete(int result) { |
| 452 connect_timing_.ssl_end = base::TimeTicks::Now(); | 323 connect_timing_.ssl_end = base::TimeTicks::Now(); |
| 453 | 324 |
| 454 SSLClientSocket::NextProtoStatus status = | 325 SSLClientSocket::NextProtoStatus status = |
| 455 SSLClientSocket::kNextProtoUnsupported; | 326 SSLClientSocket::kNextProtoUnsupported; |
| 456 std::string proto; | 327 std::string proto; |
| 457 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket | 328 // 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 | 329 // that hasn't had SSL_ImportFD called on it. If we get a certificate error |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 SetSocket(ssl_socket_.Pass()); | 442 SetSocket(ssl_socket_.Pass()); |
| 572 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 443 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 573 error_response_info_.cert_request_info = new SSLCertRequestInfo; | 444 error_response_info_.cert_request_info = new SSLCertRequestInfo; |
| 574 ssl_socket_->GetSSLCertRequestInfo( | 445 ssl_socket_->GetSSLCertRequestInfo( |
| 575 error_response_info_.cert_request_info.get()); | 446 error_response_info_.cert_request_info.get()); |
| 576 } | 447 } |
| 577 | 448 |
| 578 return result; | 449 return result; |
| 579 } | 450 } |
| 580 | 451 |
| 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( | 452 SSLConnectJob::State SSLConnectJob::GetInitialState( |
| 588 SSLSocketParams::ConnectionType connection_type) { | 453 SSLSocketParams::ConnectionType connection_type) { |
| 589 switch (connection_type) { | 454 switch (connection_type) { |
| 590 case SSLSocketParams::DIRECT: | 455 case SSLSocketParams::DIRECT: |
| 591 return STATE_TRANSPORT_CONNECT; | 456 return STATE_TRANSPORT_CONNECT; |
| 592 case SSLSocketParams::HTTP_PROXY: | 457 case SSLSocketParams::HTTP_PROXY: |
| 593 return STATE_TUNNEL_CONNECT; | 458 return STATE_TUNNEL_CONNECT; |
| 594 case SSLSocketParams::SOCKS_PROXY: | 459 case SSLSocketParams::SOCKS_PROXY: |
| 595 return STATE_SOCKS_CONNECT; | 460 return STATE_SOCKS_CONNECT; |
| 596 } | 461 } |
| 597 NOTREACHED(); | 462 NOTREACHED(); |
| 598 return STATE_NONE; | 463 return STATE_NONE; |
| 599 } | 464 } |
| 600 | 465 |
| 601 int SSLConnectJob::ConnectInternal() { | 466 int SSLConnectJob::ConnectInternal() { |
| 602 next_state_ = GetInitialState(params_->GetConnectionType()); | 467 next_state_ = GetInitialState(params_->GetConnectionType()); |
| 603 return DoLoop(OK); | 468 return DoLoop(OK); |
| 604 } | 469 } |
| 605 | 470 |
| 606 SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory( | 471 SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory( |
| 607 TransportClientSocketPool* transport_pool, | 472 TransportClientSocketPool* transport_pool, |
| 608 SOCKSClientSocketPool* socks_pool, | 473 SOCKSClientSocketPool* socks_pool, |
| 609 HttpProxyClientSocketPool* http_proxy_pool, | 474 HttpProxyClientSocketPool* http_proxy_pool, |
| 610 ClientSocketFactory* client_socket_factory, | 475 ClientSocketFactory* client_socket_factory, |
| 611 const SSLClientSocketContext& context, | 476 const SSLClientSocketContext& context, |
| 612 const SSLConnectJob::GetMessengerCallback& get_messenger_callback, | |
| 613 NetLog* net_log) | 477 NetLog* net_log) |
| 614 : transport_pool_(transport_pool), | 478 : transport_pool_(transport_pool), |
| 615 socks_pool_(socks_pool), | 479 socks_pool_(socks_pool), |
| 616 http_proxy_pool_(http_proxy_pool), | 480 http_proxy_pool_(http_proxy_pool), |
| 617 client_socket_factory_(client_socket_factory), | 481 client_socket_factory_(client_socket_factory), |
| 618 context_(context), | 482 context_(context), |
| 619 get_messenger_callback_(get_messenger_callback), | |
| 620 net_log_(net_log) { | 483 net_log_(net_log) { |
| 621 base::TimeDelta max_transport_timeout = base::TimeDelta(); | 484 base::TimeDelta max_transport_timeout = base::TimeDelta(); |
| 622 base::TimeDelta pool_timeout; | 485 base::TimeDelta pool_timeout; |
| 623 if (transport_pool_) | 486 if (transport_pool_) |
| 624 max_transport_timeout = transport_pool_->ConnectionTimeout(); | 487 max_transport_timeout = transport_pool_->ConnectionTimeout(); |
| 625 if (socks_pool_) { | 488 if (socks_pool_) { |
| 626 pool_timeout = socks_pool_->ConnectionTimeout(); | 489 pool_timeout = socks_pool_->ConnectionTimeout(); |
| 627 if (pool_timeout > max_transport_timeout) | 490 if (pool_timeout > max_transport_timeout) |
| 628 max_transport_timeout = pool_timeout; | 491 max_transport_timeout = pool_timeout; |
| 629 } | 492 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 647 ChannelIDService* channel_id_service, | 510 ChannelIDService* channel_id_service, |
| 648 TransportSecurityState* transport_security_state, | 511 TransportSecurityState* transport_security_state, |
| 649 CTVerifier* cert_transparency_verifier, | 512 CTVerifier* cert_transparency_verifier, |
| 650 CertPolicyEnforcer* cert_policy_enforcer, | 513 CertPolicyEnforcer* cert_policy_enforcer, |
| 651 const std::string& ssl_session_cache_shard, | 514 const std::string& ssl_session_cache_shard, |
| 652 ClientSocketFactory* client_socket_factory, | 515 ClientSocketFactory* client_socket_factory, |
| 653 TransportClientSocketPool* transport_pool, | 516 TransportClientSocketPool* transport_pool, |
| 654 SOCKSClientSocketPool* socks_pool, | 517 SOCKSClientSocketPool* socks_pool, |
| 655 HttpProxyClientSocketPool* http_proxy_pool, | 518 HttpProxyClientSocketPool* http_proxy_pool, |
| 656 SSLConfigService* ssl_config_service, | 519 SSLConfigService* ssl_config_service, |
| 657 bool enable_ssl_connect_job_waiting, | |
| 658 NetLog* net_log) | 520 NetLog* net_log) |
| 659 : transport_pool_(transport_pool), | 521 : transport_pool_(transport_pool), |
| 660 socks_pool_(socks_pool), | 522 socks_pool_(socks_pool), |
| 661 http_proxy_pool_(http_proxy_pool), | 523 http_proxy_pool_(http_proxy_pool), |
| 662 base_(this, | 524 base_(this, |
| 663 max_sockets, | 525 max_sockets, |
| 664 max_sockets_per_group, | 526 max_sockets_per_group, |
| 665 histograms, | 527 histograms, |
| 666 ClientSocketPool::unused_idle_socket_timeout(), | 528 ClientSocketPool::unused_idle_socket_timeout(), |
| 667 ClientSocketPool::used_idle_socket_timeout(), | 529 ClientSocketPool::used_idle_socket_timeout(), |
| 668 new SSLConnectJobFactory( | 530 new SSLConnectJobFactory( |
| 669 transport_pool, | 531 transport_pool, |
| 670 socks_pool, | 532 socks_pool, |
| 671 http_proxy_pool, | 533 http_proxy_pool, |
| 672 client_socket_factory, | 534 client_socket_factory, |
| 673 SSLClientSocketContext(cert_verifier, | 535 SSLClientSocketContext(cert_verifier, |
| 674 channel_id_service, | 536 channel_id_service, |
| 675 transport_security_state, | 537 transport_security_state, |
| 676 cert_transparency_verifier, | 538 cert_transparency_verifier, |
| 677 cert_policy_enforcer, | 539 cert_policy_enforcer, |
| 678 ssl_session_cache_shard), | 540 ssl_session_cache_shard), |
| 679 base::Bind( | |
| 680 &SSLClientSocketPool::GetOrCreateSSLConnectJobMessenger, | |
| 681 base::Unretained(this)), | |
| 682 net_log)), | 541 net_log)), |
| 683 ssl_config_service_(ssl_config_service), | 542 ssl_config_service_(ssl_config_service) { |
| 684 enable_ssl_connect_job_waiting_(enable_ssl_connect_job_waiting) { | |
| 685 if (ssl_config_service_.get()) | 543 if (ssl_config_service_.get()) |
| 686 ssl_config_service_->AddObserver(this); | 544 ssl_config_service_->AddObserver(this); |
| 687 if (transport_pool_) | 545 if (transport_pool_) |
| 688 base_.AddLowerLayeredPool(transport_pool_); | 546 base_.AddLowerLayeredPool(transport_pool_); |
| 689 if (socks_pool_) | 547 if (socks_pool_) |
| 690 base_.AddLowerLayeredPool(socks_pool_); | 548 base_.AddLowerLayeredPool(socks_pool_); |
| 691 if (http_proxy_pool_) | 549 if (http_proxy_pool_) |
| 692 base_.AddLowerLayeredPool(http_proxy_pool_); | 550 base_.AddLowerLayeredPool(http_proxy_pool_); |
| 693 } | 551 } |
| 694 | 552 |
| 695 SSLClientSocketPool::~SSLClientSocketPool() { | 553 SSLClientSocketPool::~SSLClientSocketPool() { |
| 696 STLDeleteContainerPairSecondPointers(messenger_map_.begin(), | |
| 697 messenger_map_.end()); | |
| 698 if (ssl_config_service_.get()) | 554 if (ssl_config_service_.get()) |
| 699 ssl_config_service_->RemoveObserver(this); | 555 ssl_config_service_->RemoveObserver(this); |
| 700 } | 556 } |
| 701 | 557 |
| 702 scoped_ptr<ConnectJob> SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( | 558 scoped_ptr<ConnectJob> SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( |
| 703 const std::string& group_name, | 559 const std::string& group_name, |
| 704 const PoolBase::Request& request, | 560 const PoolBase::Request& request, |
| 705 ConnectJob::Delegate* delegate) const { | 561 ConnectJob::Delegate* delegate) const { |
| 706 return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name, | 562 return scoped_ptr<ConnectJob>(new SSLConnectJob(group_name, |
| 707 request.priority(), | 563 request.priority(), |
| 708 request.params(), | 564 request.params(), |
| 709 ConnectionTimeout(), | 565 ConnectionTimeout(), |
| 710 transport_pool_, | 566 transport_pool_, |
| 711 socks_pool_, | 567 socks_pool_, |
| 712 http_proxy_pool_, | 568 http_proxy_pool_, |
| 713 client_socket_factory_, | 569 client_socket_factory_, |
| 714 context_, | 570 context_, |
| 715 get_messenger_callback_, | |
| 716 delegate, | 571 delegate, |
| 717 net_log_)); | 572 net_log_)); |
| 718 } | 573 } |
| 719 | 574 |
| 720 base::TimeDelta SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() | 575 base::TimeDelta SSLClientSocketPool::SSLConnectJobFactory::ConnectionTimeout() |
| 721 const { | 576 const { |
| 722 return timeout_; | 577 return timeout_; |
| 723 } | 578 } |
| 724 | 579 |
| 725 int SSLClientSocketPool::RequestSocket(const std::string& group_name, | 580 int SSLClientSocketPool::RequestSocket(const std::string& group_name, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 HigherLayeredPool* higher_pool) { | 681 HigherLayeredPool* higher_pool) { |
| 827 base_.RemoveHigherLayeredPool(higher_pool); | 682 base_.RemoveHigherLayeredPool(higher_pool); |
| 828 } | 683 } |
| 829 | 684 |
| 830 bool SSLClientSocketPool::CloseOneIdleConnection() { | 685 bool SSLClientSocketPool::CloseOneIdleConnection() { |
| 831 if (base_.CloseOneIdleSocket()) | 686 if (base_.CloseOneIdleSocket()) |
| 832 return true; | 687 return true; |
| 833 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 688 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
| 834 } | 689 } |
| 835 | 690 |
| 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() { | 691 void SSLClientSocketPool::OnSSLConfigChanged() { |
| 863 FlushWithError(ERR_NETWORK_CHANGED); | 692 FlushWithError(ERR_NETWORK_CHANGED); |
| 864 } | 693 } |
| 865 | 694 |
| 866 } // namespace net | 695 } // namespace net |
| OLD | NEW |