summaryrefslogtreecommitdiffstats
path: root/components/data_reduction_proxy
diff options
context:
space:
mode:
authormegjablon <megjablon@chromium.org>2015-06-11 13:01:55 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-11 20:03:08 +0000
commit3bd89f346aafe37062c393df77a17fc3a2312243 (patch)
treeb733476ca128551f7af973db36025b198595b2df /components/data_reduction_proxy
parent3d442d362ddec4594dc12983d88bdbe24f1c361c (diff)
downloadchromium_src-3bd89f346aafe37062c393df77a17fc3a2312243.zip
chromium_src-3bd89f346aafe37062c393df77a17fc3a2312243.tar.gz
chromium_src-3bd89f346aafe37062c393df77a17fc3a2312243.tar.bz2
Tri-state Data Reduction Proxy Lo-Fi flag
Make the Lo-Fi flag MULTI_VALUE_TYPE with modes always-on, cellular-only, and disabled. BUG=497437 Review URL: https://codereview.chromium.org/1159783005 Cr-Commit-Position: refs/heads/master@{#334021}
Diffstat (limited to 'components/data_reduction_proxy')
-rw-r--r--components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter_unittest.cc6
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc15
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc10
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc10
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc5
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc8
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc2
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc27
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_params.h10
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc11
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h5
11 files changed, 83 insertions, 26 deletions
diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter_unittest.cc b/components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter_unittest.cc
index 77f07da..cca2197 100644
--- a/components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter_unittest.cc
+++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter_unittest.cc
@@ -128,9 +128,9 @@ TEST_F(DataReductionProxyMessageFilterTest, TestOnDataReductionProxyStatus) {
bool is_data_reduction_proxy = false;
if (tests[i].lofi_on_through_switch) {
- base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
- command_line->AppendSwitch(
- data_reduction_proxy::switches::kEnableDataReductionProxyLoFi);
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kDataReductionProxyLoFi,
+ switches::kDataReductionProxyLoFiValueAlwaysOn);
}
EXPECT_CALL(*config(), IsDataReductionProxy(testing::_, nullptr))
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
index dd55a9e..2ffcf3a 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
@@ -21,6 +21,7 @@
#include "components/variations/variations_associated_data.h"
#include "net/base/host_port_pair.h"
#include "net/base/load_flags.h"
+#include "net/base/network_change_notifier.h"
#include "net/base/network_quality.h"
#include "net/base/network_quality_estimator.h"
#include "net/proxy/proxy_server.h"
@@ -205,6 +206,8 @@ DataReductionProxyConfig::DataReductionProxyConfig(
lofi_status_(LOFI_STATUS_TEMPORARILY_OFF) {
DCHECK(configurator);
DCHECK(event_creator);
+ if (DataReductionProxyParams::IsLoFiDisabledViaFlags())
+ SetLoFiModeOff();
// Constructed on the UI thread, but should be checked on the IO thread.
thread_checker_.DetachFromThread();
}
@@ -791,11 +794,21 @@ void DataReductionProxyConfig::UpdateLoFiStatusOnMainFrameRequest(
}
}
- if (DataReductionProxyParams::IsLoFiEnabledThroughSwitch()) {
+ if (DataReductionProxyParams::IsLoFiAlwaysOnViaFlags()) {
lofi_status_ = LOFI_STATUS_ACTIVE_FROM_FLAGS;
return;
}
+ if (DataReductionProxyParams::IsLoFiCellularOnlyViaFlags()) {
+ if (net::NetworkChangeNotifier::IsConnectionCellular(
+ net::NetworkChangeNotifier::GetConnectionType())) {
+ lofi_status_ = LOFI_STATUS_ACTIVE_FROM_FLAGS;
+ return;
+ }
+ lofi_status_ = LOFI_STATUS_TEMPORARILY_OFF;
+ return;
+ }
+
if (IsIncludedInLoFiControlFieldTrial()) {
lofi_status_ = IsNetworkQualityProhibitivelySlow(network_quality_estimator)
? LOFI_STATUS_ACTIVE_CONTROL
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
index 26f726d..b7c7cd1 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
@@ -1158,8 +1158,9 @@ TEST_F(DataReductionProxyConfigTest, LoFiOn) {
for (size_t i = 0; i < arraysize(tests); ++i) {
config()->ResetLoFiStatusForTest();
if (tests[i].lofi_switch_enabled) {
- base::CommandLine::ForCurrentProcess()->AppendSwitch(
- data_reduction_proxy::switches::kEnableDataReductionProxyLoFi);
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kDataReductionProxyLoFi,
+ switches::kDataReductionProxyLoFiValueAlwaysOn);
}
EXPECT_CALL(*config(), IsIncludedInLoFiEnabledFieldTrial())
@@ -1192,8 +1193,9 @@ TEST_F(DataReductionProxyConfigTest, LoFiStatusTransition) {
for (size_t i = 0; i < arraysize(tests); ++i) {
config()->ResetLoFiStatusForTest();
if (tests[i].lofi_switch_enabled) {
- base::CommandLine::ForCurrentProcess()->AppendSwitch(
- data_reduction_proxy::switches::kEnableDataReductionProxyLoFi);
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kDataReductionProxyLoFi,
+ switches::kDataReductionProxyLoFiValueAlwaysOn);
} else {
EXPECT_CALL(*config(), IsIncludedInLoFiEnabledFieldTrial())
.WillRepeatedly(testing::Return(true));
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
index c016af2..bc62ac1 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
@@ -226,8 +226,9 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) {
for (size_t i = 0; i < arraysize(tests); ++i) {
if (tests[i].lofi_switch_enabled) {
- base::CommandLine::ForCurrentProcess()->AppendSwitch(
- data_reduction_proxy::switches::kEnableDataReductionProxyLoFi);
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kDataReductionProxyLoFi,
+ switches::kDataReductionProxyLoFiValueAlwaysOn);
}
config()->SetIncludedInLoFiEnabledFieldTrial(tests[i].auto_lofi_enabled);
config()->SetNetworkProhibitivelySlow(tests[i].auto_lofi_enabled);
@@ -449,8 +450,9 @@ TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) {
config()->SetNetworkProhibitivelySlow(tests[i].auto_lofi_enabled);
if (tests[i].lofi_enabled_through_switch) {
- base::CommandLine::ForCurrentProcess()->AppendSwitch(
- data_reduction_proxy::switches::kEnableDataReductionProxyLoFi);
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kDataReductionProxyLoFi,
+ switches::kDataReductionProxyLoFiValueAlwaysOn);
}
config()->UpdateLoFiStatusOnMainFrameRequest(false, nullptr);
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc
index 4b26de7..a6b2f69 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc
@@ -293,8 +293,9 @@ TEST_F(DataReductionProxyRequestOptionsTest, LoFiOnThroughCommandLineSwitch) {
test_context_->config()->ResetLoFiStatusForTest();
// Add the LoFi command line switch.
- base::CommandLine::ForCurrentProcess()->AppendSwitch(
- data_reduction_proxy::switches::kEnableDataReductionProxyLoFi);
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kDataReductionProxyLoFi,
+ switches::kDataReductionProxyLoFiValueAlwaysOn);
SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(),
kClientStr, std::string(), std::string(), "low",
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc
index 3b47836..b0eb1993 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc
@@ -166,8 +166,12 @@ void DataReductionProxyService::InitializeLoFiPrefs() {
prefs_->SetInteger(prefs::kLoFiConsecutiveSessionDisables, 0);
prefs_->SetInteger(prefs::kLoFiImplicitOptOutVersion,
lo_fi_implicit_opt_out_version);
- } else if (prefs_->GetInteger(prefs::kLoFiConsecutiveSessionDisables) >=
- lo_fi_consecutive_session_disables) {
+ } else if (!DataReductionProxyParams::IsLoFiAlwaysOnViaFlags() &&
+ (prefs_->GetInteger(prefs::kLoFiConsecutiveSessionDisables) >=
+ lo_fi_consecutive_session_disables)) {
+ // If Lo-Fi isn't always on and and the number of
+ // |consecutive_session_disables| has been met, turn Lo-Fi off for this
+ // session.
SetLoFiModeOff();
} else if (prefs_->GetInteger(prefs::kLoFiLoadImagesPerSession) <
lo_fi_user_requests_for_images_per_session) {
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
index 8866869..b3353a9 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
@@ -196,7 +196,7 @@ void DataReductionProxySettings::SetLoFiShowImageRequested() {
}
void DataReductionProxySettings::IncrementLoFiUserRequestsForImages() {
- if (!prefs_)
+ if (!prefs_ || DataReductionProxyParams::IsLoFiAlwaysOnViaFlags())
return;
prefs_->SetInteger(prefs::kLoFiLoadImagesPerSession,
prefs_->GetInteger(prefs::kLoFiLoadImagesPerSession) + 1);
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc
index 24c108d..e16ae8e 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc
@@ -119,9 +119,30 @@ std::string DataReductionProxyParams::GetLoFiFieldTrialName() {
}
// static
-bool DataReductionProxyParams::IsLoFiEnabledThroughSwitch() {
- return base::CommandLine::ForCurrentProcess()->HasSwitch(
- data_reduction_proxy::switches::kEnableDataReductionProxyLoFi);
+bool DataReductionProxyParams::IsLoFiAlwaysOnViaFlags() {
+ const std::string& lo_fi_value =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ data_reduction_proxy::switches::kDataReductionProxyLoFi);
+ return lo_fi_value ==
+ data_reduction_proxy::switches::kDataReductionProxyLoFiValueAlwaysOn;
+}
+
+// static
+bool DataReductionProxyParams::IsLoFiCellularOnlyViaFlags() {
+ const std::string& lo_fi_value =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ data_reduction_proxy::switches::kDataReductionProxyLoFi);
+ return lo_fi_value == data_reduction_proxy::switches::
+ kDataReductionProxyLoFiValueCellularOnly;
+}
+
+// static
+bool DataReductionProxyParams::IsLoFiDisabledViaFlags() {
+ const std::string& lo_fi_value =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ data_reduction_proxy::switches::kDataReductionProxyLoFi);
+ return lo_fi_value ==
+ data_reduction_proxy::switches::kDataReductionProxyLoFiValueDisabled;
}
//static
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h
index b4ada80..6a975a2 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h
@@ -97,8 +97,16 @@ class DataReductionProxyParams : public DataReductionProxyConfigValues {
const char* build_fingerprint);
// Returns true if this client has the command line switch to enable Lo-Fi
+ // mode always on.
+ static bool IsLoFiAlwaysOnViaFlags();
+
+ // Returns true if this client has the command line switch to enable Lo-Fi
+ // mode only on cellular connections.
+ static bool IsLoFiCellularOnlyViaFlags();
+
+ // Returns true if this client has the command line switch to disable Lo-Fi
// mode.
- static bool IsLoFiEnabledThroughSwitch();
+ static bool IsLoFiDisabledViaFlags();
// Returns true if this client has the command line switch to show
// interstitials for data reduction proxy bypasses.
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc
index fabc575..a62fadf 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc
@@ -49,6 +49,13 @@ const char kDataReductionProxyWarmupURL[] = "data-reduction-proxy-warmup-url";
// The origin of the data reduction SSL proxy.
const char kDataReductionSSLProxy[] = "data-reduction-ssl-proxy";
+// The mode for Data Reduction Proxy Lo-Fi. The various modes are always-on,
+// cellular-only, and disabled.
+const char kDataReductionProxyLoFi[] = "data-reduction-proxy-lo-fi";
+const char kDataReductionProxyLoFiValueAlwaysOn[] = "always-on";
+const char kDataReductionProxyLoFiValueCellularOnly[] = "cellular-only";
+const char kDataReductionProxyLoFiValueDisabled[] = "disabled";
+
// Disables the origin of the data reduction proxy dev.
const char kDisableDataReductionProxyDev[] =
"disable-spdy-proxy-dev-auth-origin";
@@ -67,10 +74,6 @@ const char kEnableDataReductionProxy[] = "enable-spdy-proxy-auth";
// Enable the alternative data reduction proxy.
const char kEnableDataReductionProxyAlt[] = "enable-data-reduction-proxy-alt";
-// Enable Data Reduction Proxy Lo-Fi mode.
-const char kEnableDataReductionProxyLoFi[] =
- "enable-data-reduction-proxy-lo-fi";
-
// Enable the data reduction proxy bypass warning.
const char kEnableDataReductionProxyBypassWarning[] =
"enable-data-reduction-proxy-bypass-warning";
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h
index 27fe7c1..8be863d 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h
@@ -22,12 +22,15 @@ extern const char kDataReductionProxySecureProxyCheckURL[];
extern const char kDataReductionProxyStartSecureDisabled[];
extern const char kDataReductionProxyWarmupURL[];
extern const char kDataReductionSSLProxy[];
+extern const char kDataReductionProxyLoFi[];
+extern const char kDataReductionProxyLoFiValueAlwaysOn[];
+extern const char kDataReductionProxyLoFiValueCellularOnly[];
+extern const char kDataReductionProxyLoFiValueDisabled[];
extern const char kDisableDataReductionProxyDev[];
extern const char kEnableDataReductionProxyDev[];
extern const char kEnableDataReductionProxyCarrierTest[];
extern const char kEnableDataReductionProxy[];
extern const char kEnableDataReductionProxyAlt[];
-extern const char kEnableDataReductionProxyLoFi[];
extern const char kEnableDataReductionProxyBypassWarning[];
extern const char kClearDataReductionProxyDataSavings[];
extern const char kEnableDataReductionProxyConfigClient[];