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

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: ps 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),
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", 20))),
mmenke 2017/06/13 19:52:00 This default max timeout seems way too low. Note
tbansal1 2017/06/13 23:02:48 Changed it to 60 seconds. Eventually, this will be
165 net_log_(net_log) {} 199 net_log_(net_log) {}
166 200
167 std::unique_ptr<ConnectJob> 201 std::unique_ptr<ConnectJob>
168 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob( 202 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob(
169 const std::string& group_name, 203 const std::string& group_name,
170 const PoolBase::Request& request, 204 const PoolBase::Request& request,
171 ConnectJob::Delegate* delegate) const { 205 ConnectJob::Delegate* delegate) const {
172 return std::unique_ptr<ConnectJob>(new HttpProxyConnectJob( 206 return std::unique_ptr<ConnectJob>(new HttpProxyConnectJob(
173 group_name, request.priority(), request.respect_limits(), 207 group_name, request.priority(), request.respect_limits(),
174 request.params(), ConnectionTimeout(), transport_pool_, ssl_pool_, 208 request.params(), ConnectionTimeout(), transport_pool_, ssl_pool_,
175 delegate, net_log_)); 209 delegate, net_log_));
176 } 210 }
177 211
178 base::TimeDelta 212 base::TimeDelta
179 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::ConnectionTimeout( 213 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::ConnectionTimeout()
180 ) const { 214 const {
181 // TODO(tbansal): https://crbug.com/704339. Use |network_quality_provider_| 215 if (IsInNetAdaptiveProxyConnectionTimeoutFieldTrial() &&
182 // and field trial to determine the connection timeout. 216 network_quality_provider_) {
183 ALLOW_UNUSED_LOCAL(network_quality_provider_); 217 base::Optional<base::TimeDelta> transport_rtt_estimate =
218 network_quality_provider_->GetTransportRTT();
219 if (transport_rtt_estimate) {
220 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(
221 transport_rtt_multiplier_ *
222 transport_rtt_estimate.value().InMilliseconds());
223 // Ensure that connection timeout is between
224 // |min_proxy_connection_timeout_| and |max_proxy_connection_timeout_|.
225 if (timeout < min_proxy_connection_timeout_)
226 return min_proxy_connection_timeout_;
227 if (timeout > max_proxy_connection_timeout_)
228 return max_proxy_connection_timeout_;
229 return timeout;
230 }
231 }
184 232
185 // Return the default proxy connection timeout. 233 // Return the default proxy connection timeout.
186 base::TimeDelta max_pool_timeout = base::TimeDelta(); 234 base::TimeDelta max_pool_timeout = base::TimeDelta();
187 #if (!defined(OS_ANDROID) && !defined(OS_IOS)) 235 #if (!defined(OS_ANDROID) && !defined(OS_IOS))
188 if (transport_pool_) 236 if (transport_pool_)
189 max_pool_timeout = transport_pool_->ConnectionTimeout(); 237 max_pool_timeout = transport_pool_->ConnectionTimeout();
190 if (ssl_pool_) { 238 if (ssl_pool_) {
191 max_pool_timeout = 239 max_pool_timeout =
192 std::max(max_pool_timeout, ssl_pool_->ConnectionTimeout()); 240 std::max(max_pool_timeout, ssl_pool_->ConnectionTimeout());
193 } 241 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 base_.RemoveHigherLayeredPool(higher_pool); 384 base_.RemoveHigherLayeredPool(higher_pool);
337 } 385 }
338 386
339 bool HttpProxyClientSocketPool::CloseOneIdleConnection() { 387 bool HttpProxyClientSocketPool::CloseOneIdleConnection() {
340 if (base_.CloseOneIdleSocket()) 388 if (base_.CloseOneIdleSocket())
341 return true; 389 return true;
342 return base_.CloseOneIdleConnectionInHigherLayeredPool(); 390 return base_.CloseOneIdleConnectionInHigherLayeredPool();
343 } 391 }
344 392
345 } // namespace net 393 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698