Commit 7450edf9 authored by tbansal's avatar tbansal Committed by Commit bot

Cleanup the preconnect to proxy code and Job controller code

(1) Add a boolean |restrict_to_one_preconnect_for_proxies| to network
session params. This allows us to run multiple experiments using a single
field trial. Next CL will add the variation param
|race_preconnects_to_proxies| to experiment with racing the alternative
and main jobs for proxy preconnects.

(2) Remove an extra parameter in
HttpStreamFactoryImpl::Job::Delegate::OnStreamReady() method.

BUG=667471,671291
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_cronet_tester

Review-Url: https://codereview.chromium.org/2600943002
Cr-Commit-Position: refs/heads/master@{#440893}
parent 3298aed7
...@@ -396,6 +396,14 @@ void ConfigureQuicParams(base::StringPiece quic_trial_group, ...@@ -396,6 +396,14 @@ void ConfigureQuicParams(base::StringPiece quic_trial_group,
} }
} }
void ConfigureOptimizePreconnectsToProxiesParams(
const std::map<std::string, std::string>& proxy_preconnects_trial_params,
net::HttpNetworkSession::Params* params) {
params->restrict_to_one_preconnect_for_proxies =
GetVariationParam(proxy_preconnects_trial_params,
"restrict_to_one_preconnect_for_proxies") == "true";
}
} // anonymous namespace } // anonymous namespace
namespace network_session_configurator { namespace network_session_configurator {
...@@ -436,6 +444,12 @@ void ParseFieldTrials(bool is_quic_force_disabled, ...@@ -436,6 +444,12 @@ void ParseFieldTrials(bool is_quic_force_disabled,
const std::string tfo_trial_group = const std::string tfo_trial_group =
base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName); base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName);
ConfigureTCPFastOpenParams(tfo_trial_group, params); ConfigureTCPFastOpenParams(tfo_trial_group, params);
std::map<std::string, std::string> proxy_preconnects_trial_params;
variations::GetVariationParams("NetProxyPreconnects",
&proxy_preconnects_trial_params);
ConfigureOptimizePreconnectsToProxiesParams(proxy_preconnects_trial_params,
params);
} }
} // namespace network_session_configurator } // namespace network_session_configurator
...@@ -155,7 +155,8 @@ HttpNetworkSession::Params::Params() ...@@ -155,7 +155,8 @@ HttpNetworkSession::Params::Params()
quic_do_not_fragment(false), quic_do_not_fragment(false),
proxy_delegate(NULL), proxy_delegate(NULL),
enable_token_binding(false), enable_token_binding(false),
http_09_on_non_default_ports_enabled(false) { http_09_on_non_default_ports_enabled(false),
restrict_to_one_preconnect_for_proxies(false) {
quic_supported_versions.push_back(QUIC_VERSION_35); quic_supported_versions.push_back(QUIC_VERSION_35);
} }
......
...@@ -203,6 +203,10 @@ class NET_EXPORT HttpNetworkSession ...@@ -203,6 +203,10 @@ class NET_EXPORT HttpNetworkSession
// Enable HTTP/0.9 for HTTP/HTTPS on ports other than the default one for // Enable HTTP/0.9 for HTTP/HTTPS on ports other than the default one for
// each protocol. // each protocol.
bool http_09_on_non_default_ports_enabled; bool http_09_on_non_default_ports_enabled;
// If true, only one pending preconnect is allowed to proxies that support
// request priorities.
bool restrict_to_one_preconnect_for_proxies;
}; };
enum SocketPoolType { enum SocketPoolType {
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
...@@ -89,23 +88,13 @@ class DefaultJobFactory : public HttpStreamFactoryImpl::JobFactory { ...@@ -89,23 +88,13 @@ class DefaultJobFactory : public HttpStreamFactoryImpl::JobFactory {
} }
}; };
// Returns true if only one preconnect to proxy servers is allowed via field
// trial.
bool AllowOnlyOnePreconnectToProxyServers() {
return base::StartsWith(base::FieldTrialList::FindFullName(
"NetAllowOnlyOnePreconnectToProxyServers"),
"Enabled", base::CompareCase::INSENSITIVE_ASCII);
}
} // anonymous namespace } // anonymous namespace
HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session,
bool for_websockets) bool for_websockets)
: session_(session), : session_(session),
job_factory_(new DefaultJobFactory()), job_factory_(new DefaultJobFactory()),
for_websockets_(for_websockets), for_websockets_(for_websockets) {}
allow_only_one_preconnect_to_proxy_servers_(
AllowOnlyOnePreconnectToProxyServers()) {}
HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { HttpStreamFactoryImpl::~HttpStreamFactoryImpl() {
DCHECK(request_map_.empty()); DCHECK(request_map_.empty());
...@@ -261,7 +250,7 @@ bool HttpStreamFactoryImpl::OnInitConnection(const JobController& controller, ...@@ -261,7 +250,7 @@ bool HttpStreamFactoryImpl::OnInitConnection(const JobController& controller,
return false; return false;
} }
if (!allow_only_one_preconnect_to_proxy_servers_ || if (!session_->params().restrict_to_one_preconnect_for_proxies ||
!ProxyServerSupportsPriorities(proxy_info)) { !ProxyServerSupportsPriorities(proxy_info)) {
return false; return false;
} }
......
...@@ -168,10 +168,6 @@ class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : public HttpStreamFactory { ...@@ -168,10 +168,6 @@ class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : public HttpStreamFactory {
const bool for_websockets_; const bool for_websockets_;
// True if only one preconnect is allowed to proxy servers that support
// request priorities.
const bool allow_only_one_preconnect_to_proxy_servers_;
DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl); DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImpl);
}; };
......
...@@ -386,7 +386,7 @@ void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { ...@@ -386,7 +386,7 @@ void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() {
MaybeCopyConnectionAttemptsFromSocketOrHandle(); MaybeCopyConnectionAttemptsFromSocketOrHandle();
delegate_->OnStreamReady(this, server_ssl_config_, proxy_info_); delegate_->OnStreamReady(this, server_ssl_config_);
// |this| may be deleted after this call. // |this| may be deleted after this call.
} }
......
...@@ -51,9 +51,7 @@ class HttpStreamFactoryImpl::Job { ...@@ -51,9 +51,7 @@ class HttpStreamFactoryImpl::Job {
virtual ~Delegate() {} virtual ~Delegate() {}
// Invoked when |job| has an HttpStream ready. // Invoked when |job| has an HttpStream ready.
virtual void OnStreamReady(Job* job, virtual void OnStreamReady(Job* job, const SSLConfig& used_ssl_config) = 0;
const SSLConfig& used_ssl_config,
const ProxyInfo& used_proxy_info) = 0;
// Invoked when |job| has a BidirectionalStream ready. // Invoked when |job| has a BidirectionalStream ready.
virtual void OnBidirectionalStreamImplReady( virtual void OnBidirectionalStreamImplReady(
......
...@@ -172,12 +172,8 @@ void HttpStreamFactoryImpl::JobController::SetPriority( ...@@ -172,12 +172,8 @@ void HttpStreamFactoryImpl::JobController::SetPriority(
void HttpStreamFactoryImpl::JobController::OnStreamReady( void HttpStreamFactoryImpl::JobController::OnStreamReady(
Job* job, Job* job,
const SSLConfig& used_ssl_config, const SSLConfig& used_ssl_config) {
const ProxyInfo& used_proxy_info) {
DCHECK(job); DCHECK(job);
// TODO(tbansal): Remove |used_proxy_info| from the method arguments.
DCHECK(job->proxy_info().is_empty() == used_proxy_info.is_empty() ||
job->proxy_info().proxy_server() == used_proxy_info.proxy_server());
factory_->OnStreamReady(job->proxy_info()); factory_->OnStreamReady(job->proxy_info());
...@@ -197,7 +193,7 @@ void HttpStreamFactoryImpl::JobController::OnStreamReady( ...@@ -197,7 +193,7 @@ void HttpStreamFactoryImpl::JobController::OnStreamReady(
DCHECK(!factory_->for_websockets_); DCHECK(!factory_->for_websockets_);
DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, request_->stream_type()); DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, request_->stream_type());
OnJobSucceeded(job); OnJobSucceeded(job);
request_->OnStreamReady(used_ssl_config, used_proxy_info, stream.release()); request_->OnStreamReady(used_ssl_config, job->proxy_info(), stream.release());
} }
void HttpStreamFactoryImpl::JobController::OnBidirectionalStreamImplReady( void HttpStreamFactoryImpl::JobController::OnBidirectionalStreamImplReady(
......
...@@ -69,9 +69,7 @@ class HttpStreamFactoryImpl::JobController ...@@ -69,9 +69,7 @@ class HttpStreamFactoryImpl::JobController
// From HttpStreamFactoryImpl::Job::Delegate. // From HttpStreamFactoryImpl::Job::Delegate.
// Invoked when |job| has an HttpStream ready. // Invoked when |job| has an HttpStream ready.
void OnStreamReady(Job* job, void OnStreamReady(Job* job, const SSLConfig& used_ssl_config) override;
const SSLConfig& used_ssl_config,
const ProxyInfo& used_proxy_info) override;
// Invoked when |job| has a BidirectionalStream ready. // Invoked when |job| has a BidirectionalStream ready.
void OnBidirectionalStreamImplReady( void OnBidirectionalStreamImplReady(
......
...@@ -239,8 +239,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest, ...@@ -239,8 +239,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest,
EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
.WillOnce(Invoke(DeleteHttpStreamPointer)); .WillOnce(Invoke(DeleteHttpStreamPointer));
job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig());
ProxyInfo());
} }
// Test we cancel Jobs correctly when the Request is explicitly canceled // Test we cancel Jobs correctly when the Request is explicitly canceled
...@@ -358,8 +357,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest, ...@@ -358,8 +357,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest,
EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
.WillOnce(Invoke(DeleteHttpStreamPointer)); .WillOnce(Invoke(DeleteHttpStreamPointer));
job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig());
ProxyInfo());
// JobController shouldn't report the status of second job as request // JobController shouldn't report the status of second job as request
// is already successfully served. // is already successfully served.
...@@ -413,8 +411,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest, ...@@ -413,8 +411,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest,
EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
.WillOnce(Invoke(DeleteHttpStreamPointer)); .WillOnce(Invoke(DeleteHttpStreamPointer));
job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig());
ProxyInfo());
VerifyBrokenAlternateProtocolMapping(request_info, false); VerifyBrokenAlternateProtocolMapping(request_info, false);
} }
...@@ -458,8 +455,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest, ...@@ -458,8 +455,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest,
EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
.WillOnce(Invoke(DeleteHttpStreamPointer)); .WillOnce(Invoke(DeleteHttpStreamPointer));
job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig());
ProxyInfo());
VerifyBrokenAlternateProtocolMapping(request_info, true); VerifyBrokenAlternateProtocolMapping(request_info, true);
} }
...@@ -509,8 +505,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { ...@@ -509,8 +505,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) {
EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
.WillOnce(Invoke(DeleteHttpStreamPointer)); .WillOnce(Invoke(DeleteHttpStreamPointer));
job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig());
ProxyInfo());
} }
TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) {
...@@ -935,8 +930,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest, ...@@ -935,8 +930,7 @@ TEST_F(HttpStreamFactoryImplJobControllerTest,
EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
.WillOnce(Invoke(DeleteHttpStreamPointer)); .WillOnce(Invoke(DeleteHttpStreamPointer));
job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig());
job_factory_.main_job()->proxy_info());
// JobController shouldn't report the status of alternative server job as // JobController shouldn't report the status of alternative server job as
// request is already successfully served. // request is already successfully served.
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/field_trial.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/histogram_tester.h" #include "base/test/histogram_tester.h"
#include "net/base/port_util.h" #include "net/base/port_util.h"
...@@ -1218,13 +1217,9 @@ TEST_F(HttpStreamFactoryTest, QuicDisablePreConnectIfZeroRtt) { ...@@ -1218,13 +1217,9 @@ TEST_F(HttpStreamFactoryTest, QuicDisablePreConnectIfZeroRtt) {
} }
} }
// Verify that the proxy delegate can disable preconnect jobs to only the proxy // Verify that only one preconnect job succeeds to a proxy server that supports
// servers that support request priorities. // request priorities.
TEST_F(HttpStreamFactoryTest, ProxyDelegateDisablesPreconnect) { TEST_F(HttpStreamFactoryTest, OnlyOnePreconnectToProxyServer) {
base::FieldTrialList field_trial_list(nullptr);
base::FieldTrialList::CreateFieldTrial(
"NetAllowOnlyOnePreconnectToProxyServers", "Enabled");
for (bool set_http_server_properties : {false, true}) { for (bool set_http_server_properties : {false, true}) {
for (int num_streams = 1; num_streams < 3; ++num_streams) { for (int num_streams = 1; num_streams < 3; ++num_streams) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
...@@ -1245,6 +1240,7 @@ TEST_F(HttpStreamFactoryTest, ProxyDelegateDisablesPreconnect) { ...@@ -1245,6 +1240,7 @@ TEST_F(HttpStreamFactoryTest, ProxyDelegateDisablesPreconnect) {
params.enable_quic = true; params.enable_quic = true;
params.proxy_service = proxy_service.get(); params.proxy_service = proxy_service.get();
params.http_server_properties = &http_server_properties; params.http_server_properties = &http_server_properties;
ASSERT_TRUE(params.restrict_to_one_preconnect_for_proxies);
std::unique_ptr<HttpNetworkSession> session( std::unique_ptr<HttpNetworkSession> session(
new HttpNetworkSession(params)); new HttpNetworkSession(params));
...@@ -1610,10 +1606,6 @@ TEST_F(HttpStreamFactoryTest, RequestHttpStreamOverProxy) { ...@@ -1610,10 +1606,6 @@ TEST_F(HttpStreamFactoryTest, RequestHttpStreamOverProxy) {
// Verifies that once a stream has been created to a proxy server (that supports // Verifies that once a stream has been created to a proxy server (that supports
// request priorities) the next preconnect job can again open new sockets. // request priorities) the next preconnect job can again open new sockets.
TEST_F(HttpStreamFactoryTest, RequestHttpStreamOverProxyWithPreconnects) { TEST_F(HttpStreamFactoryTest, RequestHttpStreamOverProxyWithPreconnects) {
base::FieldTrialList field_trial_list(nullptr);
base::FieldTrialList::CreateFieldTrial(
"NetAllowOnlyOnePreconnectToProxyServers", "Enabled");
SpdySessionDependencies session_deps( SpdySessionDependencies session_deps(
ProxyService::CreateFixed("https://myproxy.org:443")); ProxyService::CreateFixed("https://myproxy.org:443"));
......
...@@ -402,6 +402,7 @@ HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams( ...@@ -402,6 +402,7 @@ HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams(
params.net_log = session_deps->net_log; params.net_log = session_deps->net_log;
params.http_09_on_non_default_ports_enabled = params.http_09_on_non_default_ports_enabled =
session_deps->http_09_on_non_default_ports_enabled; session_deps->http_09_on_non_default_ports_enabled;
params.restrict_to_one_preconnect_for_proxies = true;
return params; return params;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment