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