Skip to content

Commit

Permalink
(1) Chrome data compression proxy should use QUIC only if
Browse files Browse the repository at this point in the history
it is part of data compression QUIC field trial.

(2) If QUIC is disabled by command line switch or flag,
then QUIC should be disabled globally, including usage of
QUIC in data compression proxy.

(3) If Chrome is part of data compression QUIC field trial,
it does NOT enable QUIC for non-proxy URLs.

BUG=343579

Review URL: https://codereview.chromium.org/903213003

Cr-Commit-Position: refs/heads/master@{#317232}
  • Loading branch information
tbansal authored and Commit bot committed Feb 20, 2015
1 parent f406672 commit ed0aecc
Show file tree
Hide file tree
Showing 20 changed files with 217 additions and 19 deletions.
3 changes: 2 additions & 1 deletion android_webview/browser/aw_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ void AwBrowserContext::CreateUserPrefServiceIfNecessary() {
scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(),
GetRequestContext(),
GetAwURLRequestContext()->GetNetLog(),
data_reduction_proxy_io_data_->event_store());
data_reduction_proxy_io_data_->event_store(),
false /* disable QUIC for WebView */);
data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true);

SetDataReductionProxyEnabled(data_reduction_proxy_enabled_);
Expand Down
24 changes: 24 additions & 0 deletions chrome/browser/io_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/policy/core/common/policy_service.h"
#include "components/variations/variations_associated_data.h"
#include "content/public/browser/browser_thread.h"
Expand Down Expand Up @@ -1039,6 +1040,7 @@ void IOThread::InitializeNetworkSessionParamsFromGlobals(
&params->alternate_protocol_probability_threshold);

globals.enable_quic.CopyToIfSet(&params->enable_quic);
globals.enable_quic_for_proxies.CopyToIfSet(&params->enable_quic_for_proxies);
globals.quic_always_require_handshake_confirmation.CopyToIfSet(
&params->quic_always_require_handshake_confirmation);
globals.quic_disable_connection_pooling.CopyToIfSet(
Expand Down Expand Up @@ -1168,6 +1170,9 @@ void IOThread::ConfigureQuicGlobals(
IOThread::Globals* globals) {
bool enable_quic = ShouldEnableQuic(command_line, quic_trial_group);
globals->enable_quic.set(enable_quic);
bool enable_quic_for_proxies = ShouldEnableQuicForProxies(command_line,
quic_trial_group);
globals->enable_quic_for_proxies.set(enable_quic_for_proxies);
if (enable_quic) {
globals->quic_always_require_handshake_confirmation.set(
ShouldQuicAlwaysRequireHandshakeConfirmation(quic_trial_params));
Expand Down Expand Up @@ -1249,6 +1254,25 @@ bool IOThread::ShouldEnableQuic(const base::CommandLine& command_line,
quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName);
}

// static
bool IOThread::ShouldEnableQuicForProxies(const base::CommandLine& command_line,
base::StringPiece quic_trial_group) {
return ShouldEnableQuic(command_line, quic_trial_group) ||
ShouldEnableQuicForDataReductionProxy();
}

// static
bool IOThread::ShouldEnableQuicForDataReductionProxy() {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();

if (command_line.HasSwitch(switches::kDisableQuic))
return false;

return data_reduction_proxy::DataReductionProxyParams::
IsIncludedInQuicFieldTrial();
}

bool IOThread::ShouldEnableQuicPortSelection(
const base::CommandLine& command_line) {
if (command_line.HasSwitch(switches::kDisableQuicPortSelection))
Expand Down
11 changes: 11 additions & 0 deletions chrome/browser/io_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class IOThread : public content::BrowserThreadDelegate {
Optional<double> alternate_protocol_probability_threshold;

Optional<bool> enable_quic;
Optional<bool> enable_quic_for_proxies;
Optional<bool> enable_quic_port_selection;
Optional<bool> quic_always_require_handshake_confirmation;
Optional<bool> quic_disable_connection_pooling;
Expand Down Expand Up @@ -236,6 +237,10 @@ class IOThread : public content::BrowserThreadDelegate {

base::TimeTicks creation_time() const;

// Returns true if QUIC should be enabled for data reduction proxy, either as
// a result of a field trial or a command line flag.
static bool ShouldEnableQuicForDataReductionProxy();

private:
// Map from name to value for all parameters associate with a field trial.
typedef std::map<std::string, std::string> VariationParameters;
Expand Down Expand Up @@ -330,6 +335,12 @@ class IOThread : public content::BrowserThreadDelegate {
const base::CommandLine& command_line,
base::StringPiece quic_trial_group);

// Returns true if QUIC should be enabled for proxies, either as a result
// of a field trial or a command line flag.
static bool ShouldEnableQuicForProxies(
const base::CommandLine& command_line,
base::StringPiece quic_trial_group);

// Returns true if the selection of the ephemeral port in bind() should be
// performed by Chromium, and false if the OS should select the port. The OS
// option is used to prevent Windows from posting a security security warning
Expand Down
32 changes: 32 additions & 0 deletions chrome/browser/io_thread_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "chrome/browser/io_thread.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "net/http/http_network_session.h"
#include "net/http/http_server_properties_impl.h"
#include "net/quic/quic_protocol.h"
Expand All @@ -14,6 +16,16 @@ namespace test {

using ::testing::ElementsAre;

class BadEntropyProvider : public base::FieldTrial::EntropyProvider {
public:
~BadEntropyProvider() override {}

double GetEntropyForTrial(const std::string& trial_name,
uint32 randomization_seed) const override {
return 0.5;
}
};

class IOThreadPeer {
public:
static void ConfigureQuicGlobals(
Expand Down Expand Up @@ -114,6 +126,8 @@ TEST_F(IOThreadTest, DisableQuicByDefault) {
net::HttpNetworkSession::Params params;
InitializeNetworkSessionParams(&params);
EXPECT_FALSE(params.enable_quic);
EXPECT_FALSE(params.enable_quic_for_proxies);
EXPECT_FALSE(IOThread::ShouldEnableQuicForDataReductionProxy());
}

TEST_F(IOThreadTest, EnableQuicFromFieldTrialGroup) {
Expand All @@ -124,6 +138,7 @@ TEST_F(IOThreadTest, EnableQuicFromFieldTrialGroup) {
net::HttpNetworkSession::Params params;
InitializeNetworkSessionParams(&params);
EXPECT_TRUE(params.enable_quic);
EXPECT_TRUE(params.enable_quic_for_proxies);
EXPECT_EQ(1350u, params.quic_max_packet_length);
EXPECT_EQ(1.0, params.alternate_protocol_probability_threshold);
EXPECT_EQ(default_params.quic_supported_versions,
Expand All @@ -135,6 +150,21 @@ TEST_F(IOThreadTest, EnableQuicFromFieldTrialGroup) {
EXPECT_EQ(0.0f, params.quic_load_server_info_timeout_srtt_multiplier);
EXPECT_FALSE(params.quic_enable_truncated_connection_ids);
EXPECT_FALSE(params.quic_enable_connection_racing);
EXPECT_FALSE(IOThread::ShouldEnableQuicForDataReductionProxy());
}

TEST_F(IOThreadTest, EnableQuicFromQuicProxyFieldTrialGroup) {
base::FieldTrialList field_trial_list(new BadEntropyProvider());
base::FieldTrialList::CreateFieldTrial(
data_reduction_proxy::DataReductionProxyParams::GetQuicFieldTrialName(),
"Enabled");

ConfigureQuicGlobals();
net::HttpNetworkSession::Params params;
InitializeNetworkSessionParams(&params);
EXPECT_FALSE(params.enable_quic);
EXPECT_TRUE(params.enable_quic_for_proxies);
EXPECT_TRUE(IOThread::ShouldEnableQuicForDataReductionProxy());
}

TEST_F(IOThreadTest, EnableQuicFromCommandLine) {
Expand All @@ -144,6 +174,8 @@ TEST_F(IOThreadTest, EnableQuicFromCommandLine) {
net::HttpNetworkSession::Params params;
InitializeNetworkSessionParams(&params);
EXPECT_TRUE(params.enable_quic);
EXPECT_TRUE(params.enable_quic_for_proxies);
EXPECT_FALSE(IOThread::ShouldEnableQuicForDataReductionProxy());
}

TEST_F(IOThreadTest, EnablePacingFromCommandLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ void DataReductionProxyChromeSettings::InitDataReductionProxySettings(
data_reduction_proxy::DataReductionProxyIOData* io_data,
PrefService* profile_prefs,
PrefService* local_state_prefs,
net::URLRequestContextGetter* request_context) {
net::URLRequestContextGetter* request_context,
bool enable_quic) {
SetProxyConfigurator(io_data->configurator());
DataReductionProxySettings::InitDataReductionProxySettings(
profile_prefs,
io_data->PassStatisticsPrefs(),
request_context,
io_data->net_log(),
io_data->event_store());
io_data->event_store(),
enable_quic);
DataReductionProxySettings::SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial,
base::Unretained(this)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class DataReductionProxyChromeSettings
data_reduction_proxy::DataReductionProxyIOData* io_data,
PrefService* profile_prefs,
PrefService* local_state_prefs,
net::URLRequestContextGetter* request_context);
net::URLRequestContextGetter* request_context,
bool enable_quic);

// Gets the client type for the data reduction proxy.
static data_reduction_proxy::Client GetClient();
Expand Down
8 changes: 7 additions & 1 deletion chrome/browser/profiles/profile_impl_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,17 @@ void ProfileImplIOData::Handle::Init(
BrowserThread::GetMessageLoopProxyForThread(
BrowserThread::UI)).Pass());

// TODO(tbansal): Move this to IO thread once the data reduction proxy
// params are unified into a single object.
bool enable_quic_for_data_reduction_proxy =
IOThread::ShouldEnableQuicForDataReductionProxy();

DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile_)->
InitDataReductionProxySettings(io_data_->data_reduction_proxy_io_data(),
profile_->GetPrefs(),
g_browser_process->local_state(),
profile_->GetRequestContext());
profile_->GetRequestContext(),
enable_quic_for_data_reduction_proxy);
}

content::ResourceContext*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ void DataReductionProxySettings::InitDataReductionProxySettings(
scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
net::URLRequestContextGetter* url_request_context_getter,
net::NetLog* net_log,
DataReductionProxyEventStore* event_store) {
DataReductionProxyEventStore* event_store,
bool enable_quic) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(prefs);
DCHECK(!statistics_prefs_);
Expand All @@ -148,6 +149,8 @@ void DataReductionProxySettings::InitDataReductionProxySettings(
if (!params()->allowed())
return;

params()->EnableQuic(enable_quic);

AddDefaultProxyBypassRules();
net::NetworkChangeNotifier::AddIPAddressObserver(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class DataReductionProxySettings
scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
net::URLRequestContextGetter* url_request_context_getter,
net::NetLog* net_log,
DataReductionProxyEventStore* event_store);
DataReductionProxyEventStore* event_store,
bool enable_quic);

// Constructs statistics prefs. This should not be called if a valid
// statistics prefs is passed into the constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy(
scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(),
request_context.get(),
&net_log_,
event_store_.get());
event_store_.get(),
false);
settings_->SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxySettingsTestBase::
RegisterSyntheticFieldTrialCallback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/md5.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_simple_task_runner.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h"
Expand All @@ -31,6 +32,16 @@ namespace data_reduction_proxy {

class DataReductionProxyStatisticsPrefs;

class BadEntropyProvider : public base::FieldTrial::EntropyProvider {
public:
~BadEntropyProvider() override {}

double GetEntropyForTrial(const std::string& trial_name,
uint32 randomization_seed) const override {
return 0.5;
}
};

class DataReductionProxySettingsTest
: public ConcreteDataReductionProxySettingsTest<
DataReductionProxySettings> {
Expand Down Expand Up @@ -428,7 +439,8 @@ TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) {
scoped_ptr<DataReductionProxyStatisticsPrefs>(),
request_context.get(),
&net_log_,
event_store_.get());
event_store_.get(),
false);
settings_->SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxySettingsTestBase::
RegisterSyntheticFieldTrialCallback,
Expand All @@ -437,4 +449,57 @@ TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) {
base::MessageLoop::current()->RunUntilIdle();
}

TEST_F(DataReductionProxySettingsTest, CheckQUICFieldTrials) {
for (int i = 0; i < 2; ++i) {
bool enable_quic = i == 0;
// No call to |AddProxyToCommandLine()| was made, so the proxy feature
// should be unavailable.
base::MessageLoopForUI loop;
// Clear the command line. Setting flags can force the proxy to be allowed.
base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);

ResetSettings(false, false, false, false, false);
MockSettings* settings = static_cast<MockSettings*>(settings_.get());
EXPECT_FALSE(settings->params()->allowed());
EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE));

scoped_ptr<DataReductionProxyConfigurator> configurator(
new TestDataReductionProxyConfigurator(
scoped_refptr<base::TestSimpleTaskRunner>(
new base::TestSimpleTaskRunner()),
&net_log_, event_store_.get()));
settings_->SetProxyConfigurator(configurator.get());
scoped_refptr<net::TestURLRequestContextGetter> request_context =
new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());

settings_->InitDataReductionProxySettings(
&pref_service_,
scoped_ptr<DataReductionProxyStatisticsPrefs>(),
request_context.get(),
&net_log_,
event_store_.get(),
false);

base::FieldTrialList field_trial_list(new BadEntropyProvider());
if (enable_quic) {
base::FieldTrialList::CreateFieldTrial(
DataReductionProxyParams::GetQuicFieldTrialName(),
"Enabled");
} else {
base::FieldTrialList::CreateFieldTrial(
DataReductionProxyParams::GetQuicFieldTrialName(),
"Disabled");
}
settings_->params()->EnableQuic(enable_quic);

settings_->SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxySettingsTestBase::
RegisterSyntheticFieldTrialCallback,
base::Unretained(this)));

EXPECT_EQ(enable_quic,
settings->params()->origin().is_quic()) << i;
}
}

} // namespace data_reduction_proxy
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void DataReductionProxyTestContext::InitSettings() {
DataReductionProxyTestContext::SKIP_SETTINGS_INITIALIZATION);
settings_->InitDataReductionProxySettings(
&simple_pref_service_, CreateStatisticsPrefs(), request_context_.get(),
io_data_->net_log(), io_data_->event_store());
io_data_->net_log(), io_data_->event_store(), false);
io_data_->SetDataReductionProxyStatisticsPrefs(settings_->statistics_prefs());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ class DataReductionProxyUsageStatsEndToEndTest : public testing::Test {
settings()->InitDataReductionProxySettings(
test_context_->pref_service(), test_context_->CreateStatisticsPrefs(),
test_context_->request_context(), test_context_->net_log(),
test_context_->event_store());
test_context_->event_store(), false);
test_context_->io_data()->SetDataReductionProxyStatisticsPrefs(
settings()->statistics_prefs());

Expand Down
Loading

0 comments on commit ed0aecc

Please sign in to comment.