| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 : ConnectJob(group_name, timeout_duration, delegate, | 87 : ConnectJob(group_name, timeout_duration, delegate, |
| 88 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 88 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 89 params_(params), | 89 params_(params), |
| 90 transport_pool_(transport_pool), | 90 transport_pool_(transport_pool), |
| 91 socks_pool_(socks_pool), | 91 socks_pool_(socks_pool), |
| 92 http_proxy_pool_(http_proxy_pool), | 92 http_proxy_pool_(http_proxy_pool), |
| 93 client_socket_factory_(client_socket_factory), | 93 client_socket_factory_(client_socket_factory), |
| 94 host_resolver_(host_resolver), | 94 host_resolver_(host_resolver), |
| 95 context_(context), | 95 context_(context), |
| 96 ALLOW_THIS_IN_INITIALIZER_LIST( | 96 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 97 callback_(this, &SSLConnectJob::OnIOComplete)) {} | 97 callback_(base::Bind(&SSLConnectJob::OnIOComplete, |
| 98 base::Unretained(this)))), |
| 99 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 100 callback_old_(this, &SSLConnectJob::OnIOComplete)) {} |
| 98 | 101 |
| 99 SSLConnectJob::~SSLConnectJob() {} | 102 SSLConnectJob::~SSLConnectJob() {} |
| 100 | 103 |
| 101 LoadState SSLConnectJob::GetLoadState() const { | 104 LoadState SSLConnectJob::GetLoadState() const { |
| 102 switch (next_state_) { | 105 switch (next_state_) { |
| 103 case STATE_TUNNEL_CONNECT_COMPLETE: | 106 case STATE_TUNNEL_CONNECT_COMPLETE: |
| 104 if (transport_socket_handle_->socket()) | 107 if (transport_socket_handle_->socket()) |
| 105 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; | 108 return LOAD_STATE_ESTABLISHING_PROXY_TUNNEL; |
| 106 // else, fall through. | 109 // else, fall through. |
| 107 case STATE_TRANSPORT_CONNECT: | 110 case STATE_TRANSPORT_CONNECT: |
| 108 case STATE_TRANSPORT_CONNECT_COMPLETE: | 111 case STATE_TRANSPORT_CONNECT_COMPLETE: |
| 109 case STATE_SOCKS_CONNECT: | 112 case STATE_SOCKS_CONNECT: |
| 110 case STATE_SOCKS_CONNECT_COMPLETE: | 113 case STATE_SOCKS_CONNECT_COMPLETE: |
| 111 case STATE_TUNNEL_CONNECT: | 114 case STATE_TUNNEL_CONNECT: |
| 112 return transport_socket_handle_->GetLoadState(); | 115 return transport_socket_handle_->GetLoadState(); |
| 113 case STATE_SSL_CONNECT: | 116 case STATE_SSL_CONNECT: |
| 114 case STATE_SSL_CONNECT_COMPLETE: | 117 case STATE_SSL_CONNECT_COMPLETE: |
| 115 return LOAD_STATE_SSL_HANDSHAKE; | 118 return LOAD_STATE_SSL_HANDSHAKE; |
| 116 default: | 119 default: |
| 117 NOTREACHED(); | 120 NOTREACHED(); |
| 118 return LOAD_STATE_IDLE; | 121 return LOAD_STATE_IDLE; |
| 119 } | 122 } |
| 120 } | 123 } |
| 121 | 124 |
| 122 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle * handle) { | 125 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle* handle) { |
| 123 // Headers in |error_response_info_| indicate a proxy tunnel setup | 126 // Headers in |error_response_info_| indicate a proxy tunnel setup |
| 124 // problem. See DoTunnelConnectComplete. | 127 // problem. See DoTunnelConnectComplete. |
| 125 if (error_response_info_.headers) { | 128 if (error_response_info_.headers) { |
| 126 handle->set_pending_http_proxy_connection( | 129 handle->set_pending_http_proxy_connection( |
| 127 transport_socket_handle_.release()); | 130 transport_socket_handle_.release()); |
| 128 } | 131 } |
| 129 handle->set_ssl_error_response_info(error_response_info_); | 132 handle->set_ssl_error_response_info(error_response_info_); |
| 130 if (!ssl_connect_start_time_.is_null()) | 133 if (!ssl_connect_start_time_.is_null()) |
| 131 handle->set_is_ssl_error(true); | 134 handle->set_is_ssl_error(true); |
| 132 } | 135 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 203 } |
| 201 | 204 |
| 202 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; | 205 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; |
| 203 transport_socket_handle_.reset(new ClientSocketHandle()); | 206 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 204 scoped_refptr<TransportSocketParams> transport_params = | 207 scoped_refptr<TransportSocketParams> transport_params = |
| 205 params_->transport_params(); | 208 params_->transport_params(); |
| 206 return transport_socket_handle_->Init( | 209 return transport_socket_handle_->Init( |
| 207 group_name(), | 210 group_name(), |
| 208 transport_params, | 211 transport_params, |
| 209 transport_params->destination().priority(), | 212 transport_params->destination().priority(), |
| 210 &callback_, transport_pool_, net_log()); | 213 &callback_old_, transport_pool_, net_log()); |
| 211 } | 214 } |
| 212 | 215 |
| 213 int SSLConnectJob::DoTransportConnectComplete(int result) { | 216 int SSLConnectJob::DoTransportConnectComplete(int result) { |
| 214 if (result == OK) | 217 if (result == OK) |
| 215 next_state_ = STATE_SSL_CONNECT; | 218 next_state_ = STATE_SSL_CONNECT; |
| 216 | 219 |
| 217 return result; | 220 return result; |
| 218 } | 221 } |
| 219 | 222 |
| 220 int SSLConnectJob::DoSOCKSConnect() { | 223 int SSLConnectJob::DoSOCKSConnect() { |
| 221 DCHECK(socks_pool_); | 224 DCHECK(socks_pool_); |
| 222 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; | 225 next_state_ = STATE_SOCKS_CONNECT_COMPLETE; |
| 223 transport_socket_handle_.reset(new ClientSocketHandle()); | 226 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 224 scoped_refptr<SOCKSSocketParams> socks_params = params_->socks_params(); | 227 scoped_refptr<SOCKSSocketParams> socks_params = params_->socks_params(); |
| 225 return transport_socket_handle_->Init(group_name(), socks_params, | 228 return transport_socket_handle_->Init(group_name(), socks_params, |
| 226 socks_params->destination().priority(), | 229 socks_params->destination().priority(), |
| 227 &callback_, socks_pool_, net_log()); | 230 &callback_old_, socks_pool_, net_log()); |
| 228 } | 231 } |
| 229 | 232 |
| 230 int SSLConnectJob::DoSOCKSConnectComplete(int result) { | 233 int SSLConnectJob::DoSOCKSConnectComplete(int result) { |
| 231 if (result == OK) | 234 if (result == OK) |
| 232 next_state_ = STATE_SSL_CONNECT; | 235 next_state_ = STATE_SSL_CONNECT; |
| 233 | 236 |
| 234 return result; | 237 return result; |
| 235 } | 238 } |
| 236 | 239 |
| 237 int SSLConnectJob::DoTunnelConnect() { | 240 int SSLConnectJob::DoTunnelConnect() { |
| 238 DCHECK(http_proxy_pool_); | 241 DCHECK(http_proxy_pool_); |
| 239 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; | 242 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; |
| 240 | 243 |
| 241 transport_socket_handle_.reset(new ClientSocketHandle()); | 244 transport_socket_handle_.reset(new ClientSocketHandle()); |
| 242 scoped_refptr<HttpProxySocketParams> http_proxy_params = | 245 scoped_refptr<HttpProxySocketParams> http_proxy_params = |
| 243 params_->http_proxy_params(); | 246 params_->http_proxy_params(); |
| 244 return transport_socket_handle_->Init( | 247 return transport_socket_handle_->Init( |
| 245 group_name(), http_proxy_params, | 248 group_name(), http_proxy_params, |
| 246 http_proxy_params->destination().priority(), &callback_, | 249 http_proxy_params->destination().priority(), &callback_old_, |
| 247 http_proxy_pool_, net_log()); | 250 http_proxy_pool_, net_log()); |
| 248 } | 251 } |
| 249 | 252 |
| 250 int SSLConnectJob::DoTunnelConnectComplete(int result) { | 253 int SSLConnectJob::DoTunnelConnectComplete(int result) { |
| 251 // Extract the information needed to prompt for appropriate proxy | 254 // Extract the information needed to prompt for appropriate proxy |
| 252 // authentication so that when ClientSocketPoolBaseHelper calls | 255 // authentication so that when ClientSocketPoolBaseHelper calls |
| 253 // |GetAdditionalErrorState|, we can easily set the state. | 256 // |GetAdditionalErrorState|, we can easily set the state. |
| 254 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 257 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 255 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); | 258 error_response_info_ = transport_socket_handle_->ssl_error_response_info(); |
| 256 } else if (result == ERR_PROXY_AUTH_REQUESTED || | 259 } else if (result == ERR_PROXY_AUTH_REQUESTED || |
| (...skipping 12 matching lines...) Expand all Loading... |
| 269 | 272 |
| 270 int SSLConnectJob::DoSSLConnect() { | 273 int SSLConnectJob::DoSSLConnect() { |
| 271 next_state_ = STATE_SSL_CONNECT_COMPLETE; | 274 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
| 272 // Reset the timeout to just the time allowed for the SSL handshake. | 275 // Reset the timeout to just the time allowed for the SSL handshake. |
| 273 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); | 276 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); |
| 274 ssl_connect_start_time_ = base::TimeTicks::Now(); | 277 ssl_connect_start_time_ = base::TimeTicks::Now(); |
| 275 | 278 |
| 276 ssl_socket_.reset(client_socket_factory_->CreateSSLClientSocket( | 279 ssl_socket_.reset(client_socket_factory_->CreateSSLClientSocket( |
| 277 transport_socket_handle_.release(), params_->host_and_port(), | 280 transport_socket_handle_.release(), params_->host_and_port(), |
| 278 params_->ssl_config(), ssl_host_info_.release(), context_)); | 281 params_->ssl_config(), ssl_host_info_.release(), context_)); |
| 279 return ssl_socket_->Connect(&callback_); | 282 return ssl_socket_->Connect(callback_); |
| 280 } | 283 } |
| 281 | 284 |
| 282 int SSLConnectJob::DoSSLConnectComplete(int result) { | 285 int SSLConnectJob::DoSSLConnectComplete(int result) { |
| 283 SSLClientSocket::NextProtoStatus status = | 286 SSLClientSocket::NextProtoStatus status = |
| 284 SSLClientSocket::kNextProtoUnsupported; | 287 SSLClientSocket::kNextProtoUnsupported; |
| 285 std::string proto; | 288 std::string proto; |
| 286 std::string server_protos; | 289 std::string server_protos; |
| 287 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket | 290 // GetNextProto will fail and and trigger a NOTREACHED if we pass in a socket |
| 288 // that hasn't had SSL_ImportFD called on it. If we get a certificate error | 291 // that hasn't had SSL_ImportFD called on it. If we get a certificate error |
| 289 // here, then we know that we called SSL_ImportFD. | 292 // here, then we know that we called SSL_ImportFD. |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 Flush(); | 616 Flush(); |
| 614 } | 617 } |
| 615 | 618 |
| 616 bool SSLClientSocketPool::CloseOneIdleConnection() { | 619 bool SSLClientSocketPool::CloseOneIdleConnection() { |
| 617 if (base_.CloseOneIdleSocket()) | 620 if (base_.CloseOneIdleSocket()) |
| 618 return true; | 621 return true; |
| 619 return base_.CloseOneIdleConnectionInLayeredPool(); | 622 return base_.CloseOneIdleConnectionInLayeredPool(); |
| 620 } | 623 } |
| 621 | 624 |
| 622 } // namespace net | 625 } // namespace net |
| OLD | NEW |