Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: net/http/http_proxy_client_socket_pool.cc

Issue 2932993002: Determine proxy connection timeout based on current network quality (Closed)
Patch Set: mmenke comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <map>
9 #include <string>
8 #include <utility> 10 #include <utility>
9 11
10 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
11 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
12 #include "base/time/time.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/metrics/field_trial_params.h"
16 #include "base/optional.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_util.h"
13 #include "base/values.h" 19 #include "base/values.h"
14 #include "net/base/load_flags.h" 20 #include "net/base/load_flags.h"
15 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
16 #include "net/base/proxy_delegate.h" 22 #include "net/base/proxy_delegate.h"
17 #include "net/http/http_network_session.h" 23 #include "net/http/http_network_session.h"
18 #include "net/http/http_proxy_client_socket_wrapper.h" 24 #include "net/http/http_proxy_client_socket_wrapper.h"
19 #include "net/log/net_log_source_type.h" 25 #include "net/log/net_log_source_type.h"
20 #include "net/log/net_log_with_source.h" 26 #include "net/log/net_log_with_source.h"
27 #include "net/nqe/network_quality_provider.h"
21 #include "net/socket/client_socket_factory.h" 28 #include "net/socket/client_socket_factory.h"
22 #include "net/socket/client_socket_handle.h" 29 #include "net/socket/client_socket_handle.h"
23 #include "net/socket/client_socket_pool_base.h" 30 #include "net/socket/client_socket_pool_base.h"
24 #include "net/socket/ssl_client_socket.h" 31 #include "net/socket/ssl_client_socket.h"
25 #include "net/socket/ssl_client_socket_pool.h" 32 #include "net/socket/ssl_client_socket_pool.h"
26 #include "net/socket/transport_client_socket_pool.h" 33 #include "net/socket/transport_client_socket_pool.h"
27 #include "net/spdy/chromium/spdy_proxy_client_socket.h" 34 #include "net/spdy/chromium/spdy_proxy_client_socket.h"
28 #include "net/spdy/chromium/spdy_session.h" 35 #include "net/spdy/chromium/spdy_session.h"
29 #include "net/spdy/chromium/spdy_session_pool.h" 36 #include "net/spdy/chromium/spdy_session_pool.h"
30 #include "net/spdy/chromium/spdy_stream.h" 37 #include "net/spdy/chromium/spdy_stream.h"
31 #include "net/ssl/ssl_cert_request_info.h" 38 #include "net/ssl/ssl_cert_request_info.h"
32 #include "url/gurl.h" 39 #include "url/gurl.h"
33 40
34 namespace net { 41 namespace net {
35 42
36 namespace { 43 namespace {
37 44
38 // HttpProxyConnectJobs will time out after this many seconds. Note this is on 45 // HttpProxyConnectJobs will time out after this many seconds. Note this is on
39 // top of the timeout for the transport socket. 46 // top of the timeout for the transport socket.
40 // TODO(kundaji): Proxy connect timeout should be independent of platform and be 47 // TODO(kundaji): Proxy connect timeout should be independent of platform and be
41 // based on proxy. Bug http://crbug.com/407446. 48 // based on proxy. Bug http://crbug.com/407446.
42 #if defined(OS_ANDROID) || defined(OS_IOS) 49 #if defined(OS_ANDROID) || defined(OS_IOS)
43 static const int kHttpProxyConnectJobTimeoutInSeconds = 10; 50 static const int kHttpProxyConnectJobTimeoutInSeconds = 10;
44 #else 51 #else
45 static const int kHttpProxyConnectJobTimeoutInSeconds = 30; 52 static const int kHttpProxyConnectJobTimeoutInSeconds = 30;
46 #endif 53 #endif
47 54
55 static const char kNetAdaptiveProxyConnectionTimeout[] =
56 "NetAdaptiveProxyConnectionTimeout";
57
58 bool IsInNetAdaptiveProxyConnectionTimeoutFieldTrial() {
59 // Field trial is enabled if the group name starts with "Enabled".
60 return base::FieldTrialList::FindFullName(kNetAdaptiveProxyConnectionTimeout)
61 .find("Enabled") == 0;
62 }
63
64 // Return the value of the parameter |param_name| for the field trial
65 // |kNetAdaptiveProxyConnectionTimeout|. If the value of the parameter is
66 // unavailable, then |default_value| is available.
67 int32_t GetInt32Param(const std::string& param_name, int32_t default_value) {
68 int32_t param;
69 if (!base::StringToInt(base::GetFieldTrialParamValue(
70 kNetAdaptiveProxyConnectionTimeout, param_name),
71 &param)) {
72 return default_value;
73 }
74 return param;
75 }
76
48 } // namespace 77 } // namespace
49 78
50 HttpProxySocketParams::HttpProxySocketParams( 79 HttpProxySocketParams::HttpProxySocketParams(
51 const scoped_refptr<TransportSocketParams>& transport_params, 80 const scoped_refptr<TransportSocketParams>& transport_params,
52 const scoped_refptr<SSLSocketParams>& ssl_params, 81 const scoped_refptr<SSLSocketParams>& ssl_params,
53 const std::string& user_agent, 82 const std::string& user_agent,
54 const HostPortPair& endpoint, 83 const HostPortPair& endpoint,
55 HttpAuthCache* http_auth_cache, 84 HttpAuthCache* http_auth_cache,
56 HttpAuthHandlerFactory* http_auth_handler_factory, 85 HttpAuthHandlerFactory* http_auth_handler_factory,
57 SpdySessionPool* spdy_session_pool, 86 SpdySessionPool* spdy_session_pool,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 184 }
156 185
157 HttpProxyClientSocketPool::HttpProxyConnectJobFactory:: 186 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::
158 HttpProxyConnectJobFactory(TransportClientSocketPool* transport_pool, 187 HttpProxyConnectJobFactory(TransportClientSocketPool* transport_pool,
159 SSLClientSocketPool* ssl_pool, 188 SSLClientSocketPool* ssl_pool,
160 NetworkQualityProvider* network_quality_provider, 189 NetworkQualityProvider* network_quality_provider,
161 NetLog* net_log) 190 NetLog* net_log)
162 : transport_pool_(transport_pool), 191 : transport_pool_(transport_pool),
163 ssl_pool_(ssl_pool), 192 ssl_pool_(ssl_pool),
164 network_quality_provider_(network_quality_provider), 193 network_quality_provider_(network_quality_provider),
165 net_log_(net_log) {} 194 transport_rtt_multiplier_(GetInt32Param("transport_rtt_multiplier", 5)),
195 min_proxy_connection_timeout_(base::TimeDelta::FromSeconds(
196 GetInt32Param("min_proxy_connection_timeout_seconds", 8))),
197 max_proxy_connection_timeout_(base::TimeDelta::FromSeconds(
198 GetInt32Param("max_proxy_connection_timeout_seconds", 60))),
199 net_log_(net_log) {
200 DCHECK_LT(0, transport_rtt_multiplier_);
201 DCHECK_LE(base::TimeDelta(), min_proxy_connection_timeout_);
202 DCHECK_LE(base::TimeDelta(), max_proxy_connection_timeout_);
203 DCHECK_LE(min_proxy_connection_timeout_, max_proxy_connection_timeout_);
204 }
166 205
167 std::unique_ptr<ConnectJob> 206 std::unique_ptr<ConnectJob>
168 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob( 207 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob(
169 const std::string& group_name, 208 const std::string& group_name,
170 const PoolBase::Request& request, 209 const PoolBase::Request& request,
171 ConnectJob::Delegate* delegate) const { 210 ConnectJob::Delegate* delegate) const {
172 return std::unique_ptr<ConnectJob>(new HttpProxyConnectJob( 211 return std::unique_ptr<ConnectJob>(new HttpProxyConnectJob(
173 group_name, request.priority(), request.respect_limits(), 212 group_name, request.priority(), request.respect_limits(),
174 request.params(), ConnectionTimeout(), transport_pool_, ssl_pool_, 213 request.params(), ConnectionTimeout(), transport_pool_, ssl_pool_,
175 delegate, net_log_)); 214 delegate, net_log_));
176 } 215 }
177 216
178 base::TimeDelta 217 base::TimeDelta
179 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::ConnectionTimeout( 218 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::ConnectionTimeout()
180 ) const { 219 const {
181 // TODO(tbansal): https://crbug.com/704339. Use |network_quality_provider_| 220 if (IsInNetAdaptiveProxyConnectionTimeoutFieldTrial() &&
182 // and field trial to determine the connection timeout. 221 network_quality_provider_) {
183 ALLOW_UNUSED_LOCAL(network_quality_provider_); 222 base::Optional<base::TimeDelta> transport_rtt_estimate =
223 network_quality_provider_->GetTransportRTT();
224 if (transport_rtt_estimate) {
225 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(
226 transport_rtt_multiplier_ *
227 transport_rtt_estimate.value().InMilliseconds());
228 // Ensure that connection timeout is between
229 // |min_proxy_connection_timeout_| and |max_proxy_connection_timeout_|.
230 if (timeout < min_proxy_connection_timeout_)
231 return min_proxy_connection_timeout_;
232 if (timeout > max_proxy_connection_timeout_)
233 return max_proxy_connection_timeout_;
234 return timeout;
235 }
236 }
184 237
185 // Return the default proxy connection timeout. 238 // Return the default proxy connection timeout.
186 base::TimeDelta max_pool_timeout = base::TimeDelta(); 239 base::TimeDelta max_pool_timeout = base::TimeDelta();
187 #if (!defined(OS_ANDROID) && !defined(OS_IOS)) 240 #if (!defined(OS_ANDROID) && !defined(OS_IOS))
188 if (transport_pool_) 241 if (transport_pool_)
189 max_pool_timeout = transport_pool_->ConnectionTimeout(); 242 max_pool_timeout = transport_pool_->ConnectionTimeout();
190 if (ssl_pool_) { 243 if (ssl_pool_) {
191 max_pool_timeout = 244 max_pool_timeout =
192 std::max(max_pool_timeout, ssl_pool_->ConnectionTimeout()); 245 std::max(max_pool_timeout, ssl_pool_->ConnectionTimeout());
193 } 246 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 base_.RemoveHigherLayeredPool(higher_pool); 389 base_.RemoveHigherLayeredPool(higher_pool);
337 } 390 }
338 391
339 bool HttpProxyClientSocketPool::CloseOneIdleConnection() { 392 bool HttpProxyClientSocketPool::CloseOneIdleConnection() {
340 if (base_.CloseOneIdleSocket()) 393 if (base_.CloseOneIdleSocket())
341 return true; 394 return true;
342 return base_.CloseOneIdleConnectionInHigherLayeredPool(); 395 return base_.CloseOneIdleConnectionInHigherLayeredPool();
343 } 396 }
344 397
345 } // namespace net 398 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_proxy_client_socket_pool.h ('k') | net/http/http_proxy_client_socket_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698