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 14 matching lines...) Expand all Loading... | |
25 #include "net/socket/transport_client_socket_pool.h" | 25 #include "net/socket/transport_client_socket_pool.h" |
26 #include "net/spdy/chromium/spdy_proxy_client_socket.h" | 26 #include "net/spdy/chromium/spdy_proxy_client_socket.h" |
27 #include "net/spdy/chromium/spdy_session.h" | 27 #include "net/spdy/chromium/spdy_session.h" |
28 #include "net/spdy/chromium/spdy_session_pool.h" | 28 #include "net/spdy/chromium/spdy_session_pool.h" |
29 #include "net/spdy/chromium/spdy_stream.h" | 29 #include "net/spdy/chromium/spdy_stream.h" |
30 #include "net/ssl/ssl_cert_request_info.h" | 30 #include "net/ssl/ssl_cert_request_info.h" |
31 #include "url/gurl.h" | 31 #include "url/gurl.h" |
32 | 32 |
33 namespace net { | 33 namespace net { |
34 | 34 |
35 namespace { | |
36 | |
37 // HttpProxyConnectJobs will time out after this many seconds. Note this is on | |
38 // top of the timeout for the transport socket. | |
39 // TODO(kundaji): Proxy connect timeout should be independent of platform and be | |
40 // based on proxy. Bug http://crbug.com/407446. | |
41 #if defined(OS_ANDROID) || defined(OS_IOS) | |
42 static const int kHttpProxyConnectJobTimeoutInSeconds = 10; | |
43 #else | |
44 static const int kHttpProxyConnectJobTimeoutInSeconds = 30; | |
45 #endif | |
46 | |
47 // Returns the default proxy connection timeout. | |
48 base::TimeDelta GetDefaultProxyConnectionTimeout( | |
49 TransportClientSocketPool* transport_pool, | |
50 SSLClientSocketPool* ssl_pool) { | |
51 base::TimeDelta max_pool_timeout = base::TimeDelta(); | |
52 | |
53 #if (!defined(OS_ANDROID) && !defined(OS_IOS)) | |
54 if (transport_pool) | |
55 max_pool_timeout = transport_pool->ConnectionTimeout(); | |
56 if (ssl_pool) { | |
57 max_pool_timeout = | |
58 std::max(max_pool_timeout, ssl_pool->ConnectionTimeout()); | |
59 } | |
60 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | |
61 | |
62 return max_pool_timeout + | |
63 base::TimeDelta::FromSeconds(kHttpProxyConnectJobTimeoutInSeconds); | |
64 } | |
65 | |
66 } // namespace | |
67 | |
35 HttpProxySocketParams::HttpProxySocketParams( | 68 HttpProxySocketParams::HttpProxySocketParams( |
36 const scoped_refptr<TransportSocketParams>& transport_params, | 69 const scoped_refptr<TransportSocketParams>& transport_params, |
37 const scoped_refptr<SSLSocketParams>& ssl_params, | 70 const scoped_refptr<SSLSocketParams>& ssl_params, |
38 const std::string& user_agent, | 71 const std::string& user_agent, |
39 const HostPortPair& endpoint, | 72 const HostPortPair& endpoint, |
40 HttpAuthCache* http_auth_cache, | 73 HttpAuthCache* http_auth_cache, |
41 HttpAuthHandlerFactory* http_auth_handler_factory, | 74 HttpAuthHandlerFactory* http_auth_handler_factory, |
42 SpdySessionPool* spdy_session_pool, | 75 SpdySessionPool* spdy_session_pool, |
43 bool tunnel, | 76 bool tunnel, |
44 ProxyDelegate* proxy_delegate) | 77 ProxyDelegate* proxy_delegate) |
(...skipping 13 matching lines...) Expand all Loading... | |
58 const HostResolver::RequestInfo& HttpProxySocketParams::destination() const { | 91 const HostResolver::RequestInfo& HttpProxySocketParams::destination() const { |
59 if (transport_params_.get() == NULL) { | 92 if (transport_params_.get() == NULL) { |
60 return ssl_params_->GetDirectConnectionParams()->destination(); | 93 return ssl_params_->GetDirectConnectionParams()->destination(); |
61 } else { | 94 } else { |
62 return transport_params_->destination(); | 95 return transport_params_->destination(); |
63 } | 96 } |
64 } | 97 } |
65 | 98 |
66 HttpProxySocketParams::~HttpProxySocketParams() {} | 99 HttpProxySocketParams::~HttpProxySocketParams() {} |
67 | 100 |
68 // HttpProxyConnectJobs will time out after this many seconds. Note this is on | |
69 // top of the timeout for the transport socket. | |
70 // TODO(kundaji): Proxy connect timeout should be independent of platform and be | |
71 // based on proxy. Bug http://crbug.com/407446. | |
72 #if defined(OS_ANDROID) || defined(OS_IOS) | |
73 static const int kHttpProxyConnectJobTimeoutInSeconds = 10; | |
74 #else | |
75 static const int kHttpProxyConnectJobTimeoutInSeconds = 30; | |
76 #endif | |
77 | |
78 HttpProxyConnectJob::HttpProxyConnectJob( | 101 HttpProxyConnectJob::HttpProxyConnectJob( |
79 const std::string& group_name, | 102 const std::string& group_name, |
80 RequestPriority priority, | 103 RequestPriority priority, |
81 ClientSocketPool::RespectLimits respect_limits, | 104 ClientSocketPool::RespectLimits respect_limits, |
82 const scoped_refptr<HttpProxySocketParams>& params, | 105 const scoped_refptr<HttpProxySocketParams>& params, |
83 const base::TimeDelta& timeout_duration, | 106 const base::TimeDelta& timeout_duration, |
84 TransportClientSocketPool* transport_pool, | 107 TransportClientSocketPool* transport_pool, |
85 SSLClientSocketPool* ssl_pool, | 108 SSLClientSocketPool* ssl_pool, |
86 Delegate* delegate, | 109 Delegate* delegate, |
87 NetLog* net_log) | 110 NetLog* net_log) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) | 165 if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) |
143 error_response_info_ = client_socket_->GetAdditionalErrorState(); | 166 error_response_info_ = client_socket_->GetAdditionalErrorState(); |
144 | 167 |
145 if (result == OK || result == ERR_PROXY_AUTH_REQUESTED || | 168 if (result == OK || result == ERR_PROXY_AUTH_REQUESTED || |
146 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { | 169 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { |
147 SetSocket(std::move(client_socket_)); | 170 SetSocket(std::move(client_socket_)); |
148 } | 171 } |
149 return result; | 172 return result; |
150 } | 173 } |
151 | 174 |
152 HttpProxyClientSocketPool:: | 175 HttpProxyClientSocketPool::HttpProxyConnectJobFactory:: |
153 HttpProxyConnectJobFactory::HttpProxyConnectJobFactory( | 176 HttpProxyConnectJobFactory(TransportClientSocketPool* transport_pool, |
154 TransportClientSocketPool* transport_pool, | 177 SSLClientSocketPool* ssl_pool, |
155 SSLClientSocketPool* ssl_pool, | 178 NetworkQualityProvider* network_quality_provider, |
156 NetLog* net_log) | 179 NetLog* net_log) |
157 : transport_pool_(transport_pool), | 180 : transport_pool_(transport_pool), |
158 ssl_pool_(ssl_pool), | 181 ssl_pool_(ssl_pool), |
159 net_log_(net_log) { | 182 network_quality_provider_(network_quality_provider), |
160 base::TimeDelta max_pool_timeout = base::TimeDelta(); | 183 net_log_(net_log) {} |
161 | |
162 // TODO(kundaji): Proxy connect timeout should be independent of platform and be | |
163 // based on proxy. Bug http://crbug.com/407446. | |
164 #if (defined(OS_ANDROID) || defined(OS_IOS)) | |
165 #else | |
166 if (transport_pool_) | |
167 max_pool_timeout = transport_pool_->ConnectionTimeout(); | |
168 if (ssl_pool_) | |
169 max_pool_timeout = std::max(max_pool_timeout, | |
170 ssl_pool_->ConnectionTimeout()); | |
171 #endif | |
172 timeout_ = max_pool_timeout + | |
173 base::TimeDelta::FromSeconds(kHttpProxyConnectJobTimeoutInSeconds); | |
174 } | |
175 | 184 |
176 std::unique_ptr<ConnectJob> | 185 std::unique_ptr<ConnectJob> |
177 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob( | 186 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob( |
178 const std::string& group_name, | 187 const std::string& group_name, |
179 const PoolBase::Request& request, | 188 const PoolBase::Request& request, |
180 ConnectJob::Delegate* delegate) const { | 189 ConnectJob::Delegate* delegate) const { |
181 return std::unique_ptr<ConnectJob>(new HttpProxyConnectJob( | 190 return std::unique_ptr<ConnectJob>(new HttpProxyConnectJob( |
182 group_name, request.priority(), request.respect_limits(), | 191 group_name, request.priority(), request.respect_limits(), |
183 request.params(), ConnectionTimeout(), transport_pool_, ssl_pool_, | 192 request.params(), ConnectionTimeout(), transport_pool_, ssl_pool_, |
184 delegate, net_log_)); | 193 delegate, net_log_)); |
185 } | 194 } |
186 | 195 |
187 base::TimeDelta | 196 base::TimeDelta |
188 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::ConnectionTimeout( | 197 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::ConnectionTimeout( |
189 ) const { | 198 ) const { |
190 return timeout_; | 199 // TODO(tbansal): https://crbug.com/704339. Use |network_quality_provider_| |
200 // and field trial to determine the connection timeout. | |
201 // Silence unused variable warning. | |
mmenke
2017/06/08 17:53:02
Could we just pass it in to GetDefaultProxyConnect
tbansal1
2017/06/08 19:59:14
Ok, then I am keeping everything here, and removin
mmenke
2017/06/08 20:02:10
SGTM.
| |
202 (void)network_quality_provider_; | |
203 return GetDefaultProxyConnectionTimeout(transport_pool_, ssl_pool_); | |
191 } | 204 } |
192 | 205 |
193 HttpProxyClientSocketPool::HttpProxyClientSocketPool( | 206 HttpProxyClientSocketPool::HttpProxyClientSocketPool( |
194 int max_sockets, | 207 int max_sockets, |
195 int max_sockets_per_group, | 208 int max_sockets_per_group, |
196 TransportClientSocketPool* transport_pool, | 209 TransportClientSocketPool* transport_pool, |
197 SSLClientSocketPool* ssl_pool, | 210 SSLClientSocketPool* ssl_pool, |
211 NetworkQualityProvider* network_quality_provider, | |
198 NetLog* net_log) | 212 NetLog* net_log) |
199 : transport_pool_(transport_pool), | 213 : transport_pool_(transport_pool), |
200 ssl_pool_(ssl_pool), | 214 ssl_pool_(ssl_pool), |
201 base_(this, | 215 base_(this, |
202 max_sockets, | 216 max_sockets, |
203 max_sockets_per_group, | 217 max_sockets_per_group, |
204 ClientSocketPool::unused_idle_socket_timeout(), | 218 ClientSocketPool::unused_idle_socket_timeout(), |
205 ClientSocketPool::used_idle_socket_timeout(), | 219 ClientSocketPool::used_idle_socket_timeout(), |
206 new HttpProxyConnectJobFactory(transport_pool, ssl_pool, net_log)) { | 220 new HttpProxyConnectJobFactory(transport_pool, |
221 ssl_pool, | |
222 network_quality_provider, | |
223 net_log)) { | |
207 // We should always have a |transport_pool_| except in unit tests. | 224 // We should always have a |transport_pool_| except in unit tests. |
208 if (transport_pool_) | 225 if (transport_pool_) |
209 base_.AddLowerLayeredPool(transport_pool_); | 226 base_.AddLowerLayeredPool(transport_pool_); |
210 if (ssl_pool_) | 227 if (ssl_pool_) |
211 base_.AddLowerLayeredPool(ssl_pool_); | 228 base_.AddLowerLayeredPool(ssl_pool_); |
212 } | 229 } |
213 | 230 |
214 HttpProxyClientSocketPool::~HttpProxyClientSocketPool() { | 231 HttpProxyClientSocketPool::~HttpProxyClientSocketPool() { |
215 } | 232 } |
216 | 233 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 base_.RemoveHigherLayeredPool(higher_pool); | 342 base_.RemoveHigherLayeredPool(higher_pool); |
326 } | 343 } |
327 | 344 |
328 bool HttpProxyClientSocketPool::CloseOneIdleConnection() { | 345 bool HttpProxyClientSocketPool::CloseOneIdleConnection() { |
329 if (base_.CloseOneIdleSocket()) | 346 if (base_.CloseOneIdleSocket()) |
330 return true; | 347 return true; |
331 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 348 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
332 } | 349 } |
333 | 350 |
334 } // namespace net | 351 } // namespace net |
OLD | NEW |