Commit 16895a08 authored by kundaji's avatar kundaji Committed by Commit bot

Do not disable Data Reduction Proxy on VPN.

This behavior is behind the "DataReductionProxyUseDataSaverOnVPN"
Finch trial, so Data Saver will not be disabled only for users who are part of this trial.

BUG=462497

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

Cr-Commit-Position: refs/heads/master@{#330635}
parent 05f18777
......@@ -536,7 +536,7 @@ void DataReductionProxyConfig::OnIPAddressChanged() {
if (enabled_by_user_) {
DCHECK(config_values_->allowed());
RecordNetworkChangeEvent(IP_CHANGED);
if (DisableIfVPN())
if (MaybeDisableIfVPN())
return;
if (alternative_enabled_by_user_ &&
!config_values_->alternative_fallback_allowed()) {
......@@ -613,12 +613,15 @@ void DataReductionProxyConfig::GetNetworkList(
net::GetNetworkList(interfaces, policy);
}
bool DataReductionProxyConfig::DisableIfVPN() {
bool DataReductionProxyConfig::MaybeDisableIfVPN() {
if (DataReductionProxyParams::IsIncludedInUseDataSaverOnVPNFieldTrial()) {
return false;
}
net::NetworkInterfaceList network_interfaces;
GetNetworkList(&network_interfaces, 0);
// VPNs use a "tun" interface, so the presence of a "tun" interface indicates
// a VPN is in use.
// TODO(kundaji): Verify this works on Windows.
// a VPN is in use. This logic only works on Android and Linux platforms.
// Data Saver will not be disabled on any other platform on VPN.
const std::string vpn_interface_name_prefix = "tun";
for (size_t i = 0; i < network_interfaces.size(); ++i) {
std::string interface_name = network_interfaces[i].name;
......
......@@ -243,6 +243,10 @@ class DataReductionProxyConfig
AreProxiesBypassed);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest,
AreProxiesBypassedRetryDelay);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest,
TestMaybeDisableIfVPNTrialDisabled);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest,
TestMaybeDisableIfVPNTrialEnabled);
// NetworkChangeNotifier::IPAddressObserver:
void OnIPAddressChanged() override;
......@@ -268,9 +272,10 @@ class DataReductionProxyConfig
// Adds the default proxy bypass rules for the Data Reduction Proxy.
void AddDefaultProxyBypassRules();
// Disables use of the Data Reduction Proxy on VPNs. Returns true if the
// Data Reduction Proxy has been disabled.
bool DisableIfVPN();
// Disables use of the Data Reduction Proxy on VPNs if client is not in the
// DataReductionProxyUseDataSaverOnVPN field trial and a TUN network interface
// is being used. Returns true if the Data Reduction Proxy has been disabled.
bool MaybeDisableIfVPN();
// Checks if all configured data reduction proxies are in the retry map.
// Returns true if the request is bypassed by all configured data reduction
......
......@@ -148,6 +148,26 @@ class DataReductionProxyConfigTest : public testing::Test {
scoped_ptr<TestDataReductionProxyParams> expected_params_;
};
TEST_F(DataReductionProxyConfigTest, TestMaybeDisableIfVPNTrialDisabled) {
// Simulate a VPN connection.
config()->interfaces()->clear();
config()->interfaces()->push_back(net::NetworkInterface(
"tun0", /* network interface name */
"tun0", /* network interface friendly name */
0, /* interface index */
net::NetworkChangeNotifier::CONNECTION_WIFI, net::IPAddressNumber(),
0, /* network prefix */
net::IP_ADDRESS_ATTRIBUTE_NONE /* ip address attribute */
));
EXPECT_TRUE(config()->MaybeDisableIfVPN());
}
TEST_F(DataReductionProxyConfigTest, TestMaybeDisableIfVPNTrialEnabled) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
"force-fieldtrials", "DataReductionProxyUseDataSaverOnVPN/Enabled");
EXPECT_FALSE(config()->MaybeDisableIfVPN());
}
TEST_F(DataReductionProxyConfigTest, TestUpdateConfigurator) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kDataReductionProxyAlt, params()->DefaultAltOrigin());
......
......@@ -130,6 +130,12 @@ std::string DataReductionProxyParams::GetQuicFieldTrialName() {
return kQuicFieldTrial;
}
// static
bool DataReductionProxyParams::IsIncludedInUseDataSaverOnVPNFieldTrial() {
return FieldTrialList::FindFullName("DataReductionProxyUseDataSaverOnVPN") ==
kEnabled;
}
// static
bool DataReductionProxyParams::IsConfigClientEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
......
......@@ -114,6 +114,10 @@ class DataReductionProxyParams : public DataReductionProxyConfigValues {
static std::string GetQuicFieldTrialName();
// Returns true if this client is part of a field trial that allows Data Saver
// to be used on VPN.
static bool IsIncludedInUseDataSaverOnVPNFieldTrial();
// Returns true if the Data Reduction Proxy config client should be used.
static bool IsConfigClientEnabled();
......
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