| 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/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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 ssl_params_(ssl_params), | 44 ssl_params_(ssl_params), |
| 45 spdy_session_pool_(spdy_session_pool), | 45 spdy_session_pool_(spdy_session_pool), |
| 46 user_agent_(user_agent), | 46 user_agent_(user_agent), |
| 47 endpoint_(endpoint), | 47 endpoint_(endpoint), |
| 48 http_auth_cache_(tunnel ? http_auth_cache : NULL), | 48 http_auth_cache_(tunnel ? http_auth_cache : NULL), |
| 49 http_auth_handler_factory_(tunnel ? http_auth_handler_factory : NULL), | 49 http_auth_handler_factory_(tunnel ? http_auth_handler_factory : NULL), |
| 50 tunnel_(tunnel), | 50 tunnel_(tunnel), |
| 51 proxy_delegate_(proxy_delegate) { | 51 proxy_delegate_(proxy_delegate) { |
| 52 DCHECK((transport_params.get() == NULL && ssl_params.get() != NULL) || | 52 DCHECK((transport_params.get() == NULL && ssl_params.get() != NULL) || |
| 53 (transport_params.get() != NULL && ssl_params.get() == NULL)); | 53 (transport_params.get() != NULL && ssl_params.get() == NULL)); |
| 54 if (transport_params_.get()) { | |
| 55 ignore_limits_ = transport_params->ignore_limits(); | |
| 56 } else { | |
| 57 ignore_limits_ = ssl_params->ignore_limits(); | |
| 58 } | |
| 59 } | 54 } |
| 60 | 55 |
| 61 const HostResolver::RequestInfo& HttpProxySocketParams::destination() const { | 56 const HostResolver::RequestInfo& HttpProxySocketParams::destination() const { |
| 62 if (transport_params_.get() == NULL) { | 57 if (transport_params_.get() == NULL) { |
| 63 return ssl_params_->GetDirectConnectionParams()->destination(); | 58 return ssl_params_->GetDirectConnectionParams()->destination(); |
| 64 } else { | 59 } else { |
| 65 return transport_params_->destination(); | 60 return transport_params_->destination(); |
| 66 } | 61 } |
| 67 } | 62 } |
| 68 | 63 |
| 69 HttpProxySocketParams::~HttpProxySocketParams() {} | 64 HttpProxySocketParams::~HttpProxySocketParams() {} |
| 70 | 65 |
| 71 // HttpProxyConnectJobs will time out after this many seconds. Note this is on | 66 // HttpProxyConnectJobs will time out after this many seconds. Note this is on |
| 72 // top of the timeout for the transport socket. | 67 // top of the timeout for the transport socket. |
| 73 // TODO(kundaji): Proxy connect timeout should be independent of platform and be | 68 // TODO(kundaji): Proxy connect timeout should be independent of platform and be |
| 74 // based on proxy. Bug http://crbug.com/407446. | 69 // based on proxy. Bug http://crbug.com/407446. |
| 75 #if defined(OS_ANDROID) || defined(OS_IOS) | 70 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 76 static const int kHttpProxyConnectJobTimeoutInSeconds = 10; | 71 static const int kHttpProxyConnectJobTimeoutInSeconds = 10; |
| 77 #else | 72 #else |
| 78 static const int kHttpProxyConnectJobTimeoutInSeconds = 30; | 73 static const int kHttpProxyConnectJobTimeoutInSeconds = 30; |
| 79 #endif | 74 #endif |
| 80 | 75 |
| 81 HttpProxyConnectJob::HttpProxyConnectJob( | 76 HttpProxyConnectJob::HttpProxyConnectJob( |
| 82 const std::string& group_name, | 77 const std::string& group_name, |
| 83 RequestPriority priority, | 78 RequestPriority priority, |
| 79 ClientSocketPool::IgnoreLimits ignore_limits, |
| 84 const scoped_refptr<HttpProxySocketParams>& params, | 80 const scoped_refptr<HttpProxySocketParams>& params, |
| 85 const base::TimeDelta& timeout_duration, | 81 const base::TimeDelta& timeout_duration, |
| 86 TransportClientSocketPool* transport_pool, | 82 TransportClientSocketPool* transport_pool, |
| 87 SSLClientSocketPool* ssl_pool, | 83 SSLClientSocketPool* ssl_pool, |
| 88 Delegate* delegate, | 84 Delegate* delegate, |
| 89 NetLog* net_log) | 85 NetLog* net_log) |
| 90 : ConnectJob(group_name, | 86 : ConnectJob(group_name, |
| 91 base::TimeDelta() /* The socket takes care of timeouts */, | 87 base::TimeDelta() /* The socket takes care of timeouts */, |
| 92 priority, | 88 priority, |
| 89 ignore_limits, |
| 93 delegate, | 90 delegate, |
| 94 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 91 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 95 client_socket_(new HttpProxyClientSocketWrapper( | 92 client_socket_(new HttpProxyClientSocketWrapper( |
| 96 group_name, | 93 group_name, |
| 97 priority, | 94 priority, |
| 95 ignore_limits, |
| 98 timeout_duration, | 96 timeout_duration, |
| 99 base::TimeDelta::FromSeconds(kHttpProxyConnectJobTimeoutInSeconds), | 97 base::TimeDelta::FromSeconds(kHttpProxyConnectJobTimeoutInSeconds), |
| 100 transport_pool, | 98 transport_pool, |
| 101 ssl_pool, | 99 ssl_pool, |
| 102 params->transport_params(), | 100 params->transport_params(), |
| 103 params->ssl_params(), | 101 params->ssl_params(), |
| 104 params->user_agent(), | 102 params->user_agent(), |
| 105 params->endpoint(), | 103 params->endpoint(), |
| 106 params->http_auth_cache(), | 104 params->http_auth_cache(), |
| 107 params->http_auth_handler_factory(), | 105 params->http_auth_handler_factory(), |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 timeout_ = max_pool_timeout + | 168 timeout_ = max_pool_timeout + |
| 171 base::TimeDelta::FromSeconds(kHttpProxyConnectJobTimeoutInSeconds); | 169 base::TimeDelta::FromSeconds(kHttpProxyConnectJobTimeoutInSeconds); |
| 172 } | 170 } |
| 173 | 171 |
| 174 | 172 |
| 175 scoped_ptr<ConnectJob> | 173 scoped_ptr<ConnectJob> |
| 176 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob( | 174 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob( |
| 177 const std::string& group_name, | 175 const std::string& group_name, |
| 178 const PoolBase::Request& request, | 176 const PoolBase::Request& request, |
| 179 ConnectJob::Delegate* delegate) const { | 177 ConnectJob::Delegate* delegate) const { |
| 180 return scoped_ptr<ConnectJob>(new HttpProxyConnectJob(group_name, | 178 return scoped_ptr<ConnectJob>(new HttpProxyConnectJob( |
| 181 request.priority(), | 179 group_name, request.priority(), request.ignore_limits(), request.params(), |
| 182 request.params(), | 180 ConnectionTimeout(), transport_pool_, ssl_pool_, delegate, net_log_)); |
| 183 ConnectionTimeout(), | |
| 184 transport_pool_, | |
| 185 ssl_pool_, | |
| 186 delegate, | |
| 187 net_log_)); | |
| 188 } | 181 } |
| 189 | 182 |
| 190 base::TimeDelta | 183 base::TimeDelta |
| 191 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::ConnectionTimeout( | 184 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::ConnectionTimeout( |
| 192 ) const { | 185 ) const { |
| 193 return timeout_; | 186 return timeout_; |
| 194 } | 187 } |
| 195 | 188 |
| 196 HttpProxyClientSocketPool::HttpProxyClientSocketPool( | 189 HttpProxyClientSocketPool::HttpProxyClientSocketPool( |
| 197 int max_sockets, | 190 int max_sockets, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 210 // We should always have a |transport_pool_| except in unit tests. | 203 // We should always have a |transport_pool_| except in unit tests. |
| 211 if (transport_pool_) | 204 if (transport_pool_) |
| 212 base_.AddLowerLayeredPool(transport_pool_); | 205 base_.AddLowerLayeredPool(transport_pool_); |
| 213 if (ssl_pool_) | 206 if (ssl_pool_) |
| 214 base_.AddLowerLayeredPool(ssl_pool_); | 207 base_.AddLowerLayeredPool(ssl_pool_); |
| 215 } | 208 } |
| 216 | 209 |
| 217 HttpProxyClientSocketPool::~HttpProxyClientSocketPool() { | 210 HttpProxyClientSocketPool::~HttpProxyClientSocketPool() { |
| 218 } | 211 } |
| 219 | 212 |
| 220 int HttpProxyClientSocketPool::RequestSocket( | 213 int HttpProxyClientSocketPool::RequestSocket(const std::string& group_name, |
| 221 const std::string& group_name, const void* socket_params, | 214 const void* socket_params, |
| 222 RequestPriority priority, ClientSocketHandle* handle, | 215 RequestPriority priority, |
| 223 const CompletionCallback& callback, const BoundNetLog& net_log) { | 216 IgnoreLimits ignore_limits, |
| 217 ClientSocketHandle* handle, |
| 218 const CompletionCallback& callback, |
| 219 const BoundNetLog& net_log) { |
| 224 const scoped_refptr<HttpProxySocketParams>* casted_socket_params = | 220 const scoped_refptr<HttpProxySocketParams>* casted_socket_params = |
| 225 static_cast<const scoped_refptr<HttpProxySocketParams>*>(socket_params); | 221 static_cast<const scoped_refptr<HttpProxySocketParams>*>(socket_params); |
| 226 | 222 |
| 227 return base_.RequestSocket(group_name, *casted_socket_params, priority, | 223 return base_.RequestSocket(group_name, *casted_socket_params, priority, |
| 228 handle, callback, net_log); | 224 ignore_limits, handle, callback, net_log); |
| 229 } | 225 } |
| 230 | 226 |
| 231 void HttpProxyClientSocketPool::RequestSockets( | 227 void HttpProxyClientSocketPool::RequestSockets( |
| 232 const std::string& group_name, | 228 const std::string& group_name, |
| 233 const void* params, | 229 const void* params, |
| 234 int num_sockets, | 230 int num_sockets, |
| 235 const BoundNetLog& net_log) { | 231 const BoundNetLog& net_log) { |
| 236 const scoped_refptr<HttpProxySocketParams>* casted_params = | 232 const scoped_refptr<HttpProxySocketParams>* casted_params = |
| 237 static_cast<const scoped_refptr<HttpProxySocketParams>*>(params); | 233 static_cast<const scoped_refptr<HttpProxySocketParams>*>(params); |
| 238 | 234 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 base_.RemoveHigherLayeredPool(higher_pool); | 309 base_.RemoveHigherLayeredPool(higher_pool); |
| 314 } | 310 } |
| 315 | 311 |
| 316 bool HttpProxyClientSocketPool::CloseOneIdleConnection() { | 312 bool HttpProxyClientSocketPool::CloseOneIdleConnection() { |
| 317 if (base_.CloseOneIdleSocket()) | 313 if (base_.CloseOneIdleSocket()) |
| 318 return true; | 314 return true; |
| 319 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 315 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
| 320 } | 316 } |
| 321 | 317 |
| 322 } // namespace net | 318 } // namespace net |
| OLD | NEW |