| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/http/http_proxy_client_socket_pool.h" | 5 #include "net/http/http_proxy_client_socket_pool.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/http/http_network_session.h" | 13 #include "net/http/http_network_session.h" |
| 14 #include "net/http/http_proxy_client_socket.h" | 14 #include "net/http/http_proxy_client_socket.h" |
| 15 #include "net/socket/client_socket_factory.h" | 15 #include "net/socket/client_socket_factory.h" |
| 16 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
| 17 #include "net/socket/client_socket_pool_base.h" | 17 #include "net/socket/client_socket_pool_base.h" |
| 18 #include "net/socket/tcp_client_socket_pool.h" | 18 #include "net/socket/tcp_client_socket_pool.h" |
| 19 #include "net/socket/ssl_client_socket.h" |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| 22 HttpProxySocketParams::HttpProxySocketParams( | 23 HttpProxySocketParams::HttpProxySocketParams( |
| 23 const scoped_refptr<TCPSocketParams>& tcp_params, | 24 const scoped_refptr<TCPSocketParams>& tcp_params, |
| 24 const scoped_refptr<SSLSocketParams>& ssl_params, | 25 const scoped_refptr<SSLSocketParams>& ssl_params, |
| 25 const GURL& request_url, | 26 const GURL& request_url, |
| 26 const std::string& user_agent, | 27 const std::string& user_agent, |
| 27 HostPortPair endpoint, | 28 HostPortPair endpoint, |
| 28 scoped_refptr<HttpNetworkSession> session, | 29 scoped_refptr<HttpNetworkSession> session, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 const scoped_refptr<HostResolver>& host_resolver, | 61 const scoped_refptr<HostResolver>& host_resolver, |
| 61 Delegate* delegate, | 62 Delegate* delegate, |
| 62 NetLog* net_log) | 63 NetLog* net_log) |
| 63 : ConnectJob(group_name, timeout_duration, delegate, | 64 : ConnectJob(group_name, timeout_duration, delegate, |
| 64 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 65 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 65 params_(params), | 66 params_(params), |
| 66 tcp_pool_(tcp_pool), | 67 tcp_pool_(tcp_pool), |
| 67 ssl_pool_(ssl_pool), | 68 ssl_pool_(ssl_pool), |
| 68 resolver_(host_resolver), | 69 resolver_(host_resolver), |
| 69 ALLOW_THIS_IN_INITIALIZER_LIST( | 70 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 70 callback_(this, &HttpProxyConnectJob::OnIOComplete)) { | 71 callback_(this, &HttpProxyConnectJob::OnIOComplete)), |
| 72 using_spdy_(false) { |
| 71 } | 73 } |
| 72 | 74 |
| 73 HttpProxyConnectJob::~HttpProxyConnectJob() {} | 75 HttpProxyConnectJob::~HttpProxyConnectJob() {} |
| 74 | 76 |
| 75 LoadState HttpProxyConnectJob::GetLoadState() const { | 77 LoadState HttpProxyConnectJob::GetLoadState() const { |
| 76 switch (next_state_) { | 78 switch (next_state_) { |
| 77 case kStateTCPConnect: | 79 case kStateTCPConnect: |
| 78 case kStateTCPConnectComplete: | 80 case kStateTCPConnectComplete: |
| 79 case kStateSSLConnect: | 81 case kStateSSLConnect: |
| 80 case kStateSSLConnectComplete: | 82 case kStateSSLConnectComplete: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 int HttpProxyConnectJob::DoSSLConnectComplete(int result) { | 177 int HttpProxyConnectJob::DoSSLConnectComplete(int result) { |
| 176 if (IsCertificateError(result) && | 178 if (IsCertificateError(result) && |
| 177 params_->ssl_params()->load_flags() & LOAD_IGNORE_ALL_CERT_ERRORS) | 179 params_->ssl_params()->load_flags() & LOAD_IGNORE_ALL_CERT_ERRORS) |
| 178 result = OK; | 180 result = OK; |
| 179 if (result < 0) { | 181 if (result < 0) { |
| 180 if (transport_socket_handle_->socket()) | 182 if (transport_socket_handle_->socket()) |
| 181 transport_socket_handle_->socket()->Disconnect(); | 183 transport_socket_handle_->socket()->Disconnect(); |
| 182 return result; | 184 return result; |
| 183 } | 185 } |
| 184 | 186 |
| 187 SSLClientSocket* ssl = |
| 188 static_cast<SSLClientSocket*>(transport_socket_handle_->socket()); |
| 189 using_spdy_ = ssl->was_spdy_negotiated(); |
| 190 |
| 185 // Reset the timer to just the length of time allowed for HttpProxy handshake | 191 // Reset the timer to just the length of time allowed for HttpProxy handshake |
| 186 // so that a fast SSL connection plus a slow HttpProxy failure doesn't take | 192 // so that a fast SSL connection plus a slow HttpProxy failure doesn't take |
| 187 // longer to timeout than it should. | 193 // longer to timeout than it should. |
| 188 ResetTimer(base::TimeDelta::FromSeconds( | 194 ResetTimer(base::TimeDelta::FromSeconds( |
| 189 kHttpProxyConnectJobTimeoutInSeconds)); | 195 kHttpProxyConnectJobTimeoutInSeconds)); |
| 190 next_state_ = kStateHttpProxyConnect; | 196 next_state_ = kStateHttpProxyConnect; |
| 191 return result; | 197 return result; |
| 192 } | 198 } |
| 193 | 199 |
| 194 int HttpProxyConnectJob::DoHttpProxyConnect() { | 200 int HttpProxyConnectJob::DoHttpProxyConnect() { |
| 195 next_state_ = kStateHttpProxyConnectComplete; | 201 next_state_ = kStateHttpProxyConnectComplete; |
| 196 const HostResolver::RequestInfo& tcp_destination = params_->destination(); | 202 const HostResolver::RequestInfo& tcp_destination = params_->destination(); |
| 197 HostPortPair proxy_server(tcp_destination.hostname(), | 203 HostPortPair proxy_server(tcp_destination.hostname(), |
| 198 tcp_destination.port()); | 204 tcp_destination.port()); |
| 199 | 205 |
| 200 // Add a HttpProxy connection on top of the tcp socket. | 206 // Add a HttpProxy connection on top of the tcp socket. |
| 201 transport_socket_.reset( | 207 transport_socket_.reset( |
| 202 new HttpProxyClientSocket(transport_socket_handle_.release(), | 208 new HttpProxyClientSocket(transport_socket_handle_.release(), |
| 203 params_->request_url(), | 209 params_->request_url(), |
| 204 params_->user_agent(), | 210 params_->user_agent(), |
| 205 params_->endpoint(), | 211 params_->endpoint(), |
| 206 proxy_server, params_->session(), | 212 proxy_server, params_->session(), |
| 207 params_->tunnel())); | 213 params_->tunnel(), |
| 214 using_spdy_)); |
| 208 int result = transport_socket_->Connect(&callback_); | 215 int result = transport_socket_->Connect(&callback_); |
| 209 | 216 |
| 210 // Clear the circular reference to HttpNetworkSession (|params_| reference | 217 // Clear the circular reference to HttpNetworkSession (|params_| reference |
| 211 // HttpNetworkSession, which reference HttpProxyClientSocketPool, which | 218 // HttpNetworkSession, which reference HttpProxyClientSocketPool, which |
| 212 // references |this|) here because it is safe to do so now but not at other | 219 // references |this|) here because it is safe to do so now but not at other |
| 213 // points. This may cancel this ConnectJob. | 220 // points. This may cancel this ConnectJob. |
| 214 params_ = NULL; | 221 params_ = NULL; |
| 215 return result; | 222 return result; |
| 216 } | 223 } |
| 217 | 224 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 const std::string& group_name) const { | 313 const std::string& group_name) const { |
| 307 return base_.IdleSocketCountInGroup(group_name); | 314 return base_.IdleSocketCountInGroup(group_name); |
| 308 } | 315 } |
| 309 | 316 |
| 310 LoadState HttpProxyClientSocketPool::GetLoadState( | 317 LoadState HttpProxyClientSocketPool::GetLoadState( |
| 311 const std::string& group_name, const ClientSocketHandle* handle) const { | 318 const std::string& group_name, const ClientSocketHandle* handle) const { |
| 312 return base_.GetLoadState(group_name, handle); | 319 return base_.GetLoadState(group_name, handle); |
| 313 } | 320 } |
| 314 | 321 |
| 315 } // namespace net | 322 } // namespace net |
| OLD | NEW |