summaryrefslogtreecommitdiffstats
path: root/components/data_reduction_proxy
diff options
context:
space:
mode:
authormegjablon <megjablon@chromium.org>2015-06-10 18:08:32 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-11 01:09:49 +0000
commit1cf12c7756816df0d2d3cbd1a0c29703baf198d2 (patch)
tree1b303e0dea1329e602008f077b2b1141790a7a46 /components/data_reduction_proxy
parentc7e26a99cd0a14df264e9b497f23b2dc3bbc0c27 (diff)
downloadchromium_src-1cf12c7756816df0d2d3cbd1a0c29703baf198d2.zip
chromium_src-1cf12c7756816df0d2d3cbd1a0c29703baf198d2.tar.gz
chromium_src-1cf12c7756816df0d2d3cbd1a0c29703baf198d2.tar.bz2
Lo-Fi implicit opt out
If a user requests 'Show images' for k pages in a session, disable LoFi for the remainder of that session. If LoFi is disabled for j consecutive sessions, disable LoFi "permanently". Where "permanently" is used loosely such that we could silently turn it back on using the implicit_opt_out_version number. BUG=485619 Review URL: https://codereview.chromium.org/1148683009 Cr-Commit-Position: refs/heads/master@{#333869}
Diffstat (limited to 'components/data_reduction_proxy')
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc5
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h3
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc4
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h3
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.cc6
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc56
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h8
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc18
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h13
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc114
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_params.cc15
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_params.h7
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.cc16
-rw-r--r--components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h3
14 files changed, 271 insertions, 0 deletions
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 aab7569..dd55a9e 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
@@ -752,6 +752,11 @@ void DataReductionProxyConfig::SecureProxyCheck(
fetcher_callback);
}
+void DataReductionProxyConfig::SetLoFiModeOff() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ lofi_status_ = LOFI_STATUS_OFF;
+}
+
void DataReductionProxyConfig::UpdateLoFiStatusOnMainFrameRequest(
bool user_temporarily_disabled_lofi,
const net::NetworkQualityEstimator* network_quality_estimator) {
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h
index b015f06..3c85e41 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h
@@ -234,6 +234,9 @@ class DataReductionProxyConfig
// Should be called on all URL requests (main frame and non main frame).
bool ShouldUseLoFiHeaderForRequests() const;
+ // Sets |lofi_status_| to LOFI_STATUS_OFF.
+ void SetLoFiModeOff();
+
// Updates |lofi_status_| based on the arguments provided and the current
// value of |lofi_status_|.
// |network_quality_estimator| may be NULL.
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
index 0c21098..f9b68cc 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
@@ -265,6 +265,10 @@ void DataReductionProxyIOData::SetDataReductionProxyConfiguration(
config_client_->ApplySerializedConfig(serialized_config);
}
+void DataReductionProxyIOData::SetLoFiModeOff() {
+ config_->SetLoFiModeOff();
+}
+
void DataReductionProxyIOData::UpdateContentLengths(
int64 received_content_length,
int64 original_content_length,
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h
index d63529f..6bfdee8 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h
@@ -88,6 +88,9 @@ class DataReductionProxyIOData : public DataReductionProxyEventStorageDelegate {
// Applies a serialized Data Reduction Proxy configuration.
void SetDataReductionProxyConfiguration(const std::string& serialized_config);
+ // Sets Lo-Fi mode off in |config_|.
+ void SetLoFiModeOff();
+
// Bridge methods to safely call to the UI thread objects.
void UpdateContentLengths(int64 received_content_length,
int64 original_content_length,
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.cc
index 5c2acf2..33d13a880 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.cc
@@ -59,6 +59,9 @@ void RegisterSyncableProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
prefs::kDailyOriginalContentLengthViaDataReductionProxy);
registry->RegisterListPref(prefs::kDailyContentLengthViaDataReductionProxy);
registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate, 0L);
+ registry->RegisterIntegerPref(prefs::kLoFiImplicitOptOutVersion, 0);
+ registry->RegisterIntegerPref(prefs::kLoFiLoadImagesPerSession, 0);
+ registry->RegisterIntegerPref(prefs::kLoFiConsecutiveSessionDisables, 0);
registry->RegisterInt64Pref(prefs::kSimulatedConfigRetrieveTime, 0L);
registry->RegisterStringPref(prefs::kDataReductionProxyConfig, std::string());
}
@@ -107,6 +110,9 @@ void RegisterPrefs(PrefRegistrySimple* registry) {
prefs::kDailyContentLengthViaDataReductionProxy);
registry->RegisterInt64Pref(
prefs::kDailyHttpContentLengthLastUpdateDate, 0L);
+ registry->RegisterIntegerPref(prefs::kLoFiImplicitOptOutVersion, 0);
+ registry->RegisterIntegerPref(prefs::kLoFiLoadImagesPerSession, 0);
+ registry->RegisterIntegerPref(prefs::kLoFiConsecutiveSessionDisables, 0);
registry->RegisterInt64Pref(prefs::kSimulatedConfigRetrieveTime, 0L);
registry->RegisterStringPref(prefs::kDataReductionProxyConfig, std::string());
}
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 8490a55..3b47836 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
@@ -13,6 +13,7 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service_observer.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
namespace data_reduction_proxy {
@@ -57,6 +58,8 @@ void DataReductionProxyService::SetIOData(
io_data_, config_value));
}
}
+
+ InitializeLoFiPrefs();
}
void DataReductionProxyService::Shutdown() {
@@ -125,6 +128,59 @@ void DataReductionProxyService::SetLoFiModeActiveOnMainFrame(
settings_->SetLoFiModeActiveOnMainFrame(lo_fi_mode_active);
}
+void DataReductionProxyService::SetLoFiModeOff() {
+ DCHECK(CalledOnValidThread());
+ if (io_task_runner_->BelongsToCurrentThread()) {
+ io_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&DataReductionProxyIOData::SetLoFiModeOff, io_data_));
+ return;
+ }
+ io_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&DataReductionProxyIOData::SetLoFiModeOff, io_data_));
+}
+
+void DataReductionProxyService::InitializeLoFiPrefs() {
+ DCHECK(CalledOnValidThread());
+ if (prefs_) {
+ int lo_fi_user_requests_for_images_per_session =
+ DataReductionProxyParams::GetFieldTrialParameterAsInteger(
+ DataReductionProxyParams::GetLoFiFieldTrialName(),
+ "load_images_requests_per_session", 3);
+
+ int lo_fi_implicit_opt_out_version =
+ DataReductionProxyParams::GetFieldTrialParameterAsInteger(
+ DataReductionProxyParams::GetLoFiFieldTrialName(),
+ "implicit_opt_out_version", 0);
+
+ int lo_fi_consecutive_session_disables =
+ DataReductionProxyParams::GetFieldTrialParameterAsInteger(
+ DataReductionProxyParams::GetLoFiFieldTrialName(),
+ "consecutive_session_disables", 3);
+
+ if (prefs_->GetInteger(prefs::kLoFiImplicitOptOutVersion) <
+ lo_fi_implicit_opt_out_version) {
+ // We have a new implicit opt out version, reset the consecutive session
+ // disables count so that Lo-Fi can be enabled again.
+ 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) {
+ SetLoFiModeOff();
+ } else if (prefs_->GetInteger(prefs::kLoFiLoadImagesPerSession) <
+ lo_fi_user_requests_for_images_per_session) {
+ // If the last session didn't have
+ // |lo_fi_user_requests_for_images_per_session| and the number of
+ // |consecutive_session_disables| hasn't been met, reset the consecutive
+ // sessions count.
+ prefs_->SetInteger(prefs::kLoFiConsecutiveSessionDisables, 0);
+ }
+ prefs_->SetInteger(prefs::kLoFiLoadImagesPerSession, 0);
+ }
+}
+
void DataReductionProxyService::SetInt64Pref(const std::string& pref_path,
int64 value) {
if (prefs_)
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h
index 9ef540e..b4eff3b 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h
@@ -5,6 +5,8 @@
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVICE_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVICE_H_
+#include <string>
+
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
@@ -95,6 +97,12 @@ class DataReductionProxyService
// DataReductionProxySettings.
void SetLoFiModeActiveOnMainFrame(bool lo_fi_mode_active);
+ // Sets Lo-Fi mode off on the IO thread.
+ void SetLoFiModeOff();
+
+ // Initializes the Lo-Fi implicit opt out prefs.
+ void InitializeLoFiPrefs();
+
// Stores an int64 value in |prefs_|.
void SetInt64Pref(const std::string& pref_path, int64 value);
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 a53b660..8866869 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
@@ -40,6 +40,10 @@ DataReductionProxySettings::DataReductionProxySettings()
lo_fi_show_image_requested_(false),
prefs_(NULL),
config_(nullptr) {
+ lo_fi_user_requests_for_images_per_session_ =
+ DataReductionProxyParams::GetFieldTrialParameterAsInteger(
+ DataReductionProxyParams::GetLoFiFieldTrialName(),
+ "load_images_requests_per_session", 3);
}
DataReductionProxySettings::~DataReductionProxySettings() {
@@ -191,6 +195,20 @@ void DataReductionProxySettings::SetLoFiShowImageRequested() {
lo_fi_show_image_requested_ = true;
}
+void DataReductionProxySettings::IncrementLoFiUserRequestsForImages() {
+ if (!prefs_)
+ return;
+ prefs_->SetInteger(prefs::kLoFiLoadImagesPerSession,
+ prefs_->GetInteger(prefs::kLoFiLoadImagesPerSession) + 1);
+ if (prefs_->GetInteger(prefs::kLoFiLoadImagesPerSession) >=
+ lo_fi_user_requests_for_images_per_session_) {
+ data_reduction_proxy_service_->SetLoFiModeOff();
+ prefs_->SetInteger(
+ prefs::kLoFiConsecutiveSessionDisables,
+ prefs_->GetInteger(prefs::kLoFiConsecutiveSessionDisables) + 1);
+ }
+}
+
void DataReductionProxySettings::RegisterDataReductionProxyFieldTrial() {
register_synthetic_field_trial_.Run(
"SyntheticDataReductionProxySetting",
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h
index 8e65315..29ff6be 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h
@@ -115,6 +115,11 @@ class DataReductionProxySettings : public DataReductionProxyServiceObserver {
// context menu request has been made since the last main frame request.
void SetLoFiShowImageRequested();
+ // Counts the number of requests to reload the page with images from the Lo-Fi
+ // snackbar. If the user requests the page with images a certain number of
+ // times, then Lo-Fi is disabled for the session.
+ void IncrementLoFiUserRequestsForImages();
+
// Returns the time in microseconds that the last update was made to the
// daily original and received content lengths.
int64 GetDataReductionLastUpdateTime();
@@ -217,6 +222,10 @@ class DataReductionProxySettings : public DataReductionProxyServiceObserver {
TestInitDataReductionProxyOff);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
CheckInitMetricsWhenNotAllowed);
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
+ TestLoFiImplicitOptOutClicksPerSession);
+ FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
+ TestLoFiImplicitOptOutConsecutiveSessions);
// Override of DataReductionProxyService::Observer.
void OnServiceInitialized() override;
@@ -265,6 +274,10 @@ class DataReductionProxySettings : public DataReductionProxyServiceObserver {
// last main frame request.
bool lo_fi_show_image_requested_;
+ // The number of requests to reload the page with images from the Lo-Fi
+ // snackbar until Lo-Fi is disabled.
+ int lo_fi_user_requests_for_images_per_session_;
+
BooleanPrefMember spdy_proxy_auth_enabled_;
BooleanPrefMember data_reduction_proxy_alternative_enabled_;
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
index 8c9d34e..2779bfc 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
@@ -336,6 +336,120 @@ TEST_F(DataReductionProxySettingsTest, TestEnableLoFiSyntheticTrial) {
CheckDataReductionProxyLoFiSyntheticTrial(false);
}
+TEST_F(DataReductionProxySettingsTest, TestLoFiImplicitOptOutClicksPerSession) {
+ test_context_->config()->ResetLoFiStatusForTest();
+ EXPECT_EQ(0, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiLoadImagesPerSession));
+ EXPECT_EQ(LoFiStatus::LOFI_STATUS_TEMPORARILY_OFF,
+ test_context_->config()->GetLoFiStatus());
+
+ // Click "Show images" |lo_fi_user_requests_for_images_per_session_| times.
+ for (int i = 1; i <= settings_->lo_fi_user_requests_for_images_per_session_;
+ ++i) {
+ settings_->IncrementLoFiUserRequestsForImages();
+ EXPECT_EQ(i, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiLoadImagesPerSession));
+ }
+
+ test_context_->RunUntilIdle();
+ EXPECT_EQ(1, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiConsecutiveSessionDisables));
+ EXPECT_EQ(LoFiStatus::LOFI_STATUS_OFF,
+ test_context_->config()->GetLoFiStatus());
+
+ // Reset the opt out pref values and config Lo-Fi status as if we're starting
+ // a new session.
+ test_context_->config()->ResetLoFiStatusForTest();
+ settings_->data_reduction_proxy_service_->InitializeLoFiPrefs();
+ EXPECT_EQ(0, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiLoadImagesPerSession));
+ EXPECT_EQ(LoFiStatus::LOFI_STATUS_TEMPORARILY_OFF,
+ test_context_->config()->GetLoFiStatus());
+
+ // Have a session that doesn't have
+ // |lo_fi_user_requests_for_images_per_session_| so
+ // kLoFiConsecutiveSessionDisables resets.
+ for (int i = 1;
+ i <= settings_->lo_fi_user_requests_for_images_per_session_ - 1; ++i) {
+ settings_->IncrementLoFiUserRequestsForImages();
+ EXPECT_EQ(i, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiLoadImagesPerSession));
+ }
+
+ test_context_->RunUntilIdle();
+ // Still should have only one consecutive session disable and Lo-Fi status
+ // shouldn't have been set to off.
+ EXPECT_EQ(1, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiConsecutiveSessionDisables));
+ EXPECT_EQ(LoFiStatus::LOFI_STATUS_TEMPORARILY_OFF,
+ test_context_->config()->GetLoFiStatus());
+
+ // Start a new session. The consecutive session count should now be reset to
+ // zero.
+ test_context_->config()->ResetLoFiStatusForTest();
+ settings_->data_reduction_proxy_service_->InitializeLoFiPrefs();
+ EXPECT_EQ(0, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiConsecutiveSessionDisables));
+}
+
+TEST_F(DataReductionProxySettingsTest,
+ TestLoFiImplicitOptOutConsecutiveSessions) {
+ test_context_->config()->ResetLoFiStatusForTest();
+ EXPECT_EQ(0, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiLoadImagesPerSession));
+ EXPECT_EQ(0, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiConsecutiveSessionDisables));
+ EXPECT_EQ(LoFiStatus::LOFI_STATUS_TEMPORARILY_OFF,
+ test_context_->config()->GetLoFiStatus());
+
+ // Disable Lo-Fi for 3 consecutive sessions.
+ for (int i = 1; i <= 3; ++i) {
+ // Start a new session.
+ test_context_->config()->ResetLoFiStatusForTest();
+ settings_->data_reduction_proxy_service_->InitializeLoFiPrefs();
+ EXPECT_EQ(LoFiStatus::LOFI_STATUS_TEMPORARILY_OFF,
+ test_context_->config()->GetLoFiStatus());
+
+ // Click "Show images" |lo_fi_user_requests_for_images_per_session_| times
+ // for each session.
+ for (int j = 1; j <= settings_->lo_fi_user_requests_for_images_per_session_;
+ ++j) {
+ settings_->IncrementLoFiUserRequestsForImages();
+ EXPECT_EQ(j, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiLoadImagesPerSession));
+ }
+
+ test_context_->RunUntilIdle();
+ EXPECT_EQ(i, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiConsecutiveSessionDisables));
+ EXPECT_EQ(LoFiStatus::LOFI_STATUS_OFF,
+ test_context_->config()->GetLoFiStatus());
+ }
+
+ // Start a new session. Lo-Fi should be set off.
+ test_context_->config()->ResetLoFiStatusForTest();
+ settings_->data_reduction_proxy_service_->InitializeLoFiPrefs();
+ test_context_->RunUntilIdle();
+ EXPECT_EQ(3, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiConsecutiveSessionDisables));
+ EXPECT_EQ(LoFiStatus::LOFI_STATUS_OFF,
+ test_context_->config()->GetLoFiStatus());
+
+ // Set the implicit opt out version to -1 so that the default value of zero
+ // will be an increase and the opt out status will be reset.
+ test_context_->pref_service()->SetInteger(prefs::kLoFiImplicitOptOutVersion,
+ -1);
+
+ // Start a new session. Lo-Fi should be set on again.
+ test_context_->config()->ResetLoFiStatusForTest();
+ settings_->data_reduction_proxy_service_->InitializeLoFiPrefs();
+ test_context_->RunUntilIdle();
+ EXPECT_EQ(0, test_context_->pref_service()->GetInteger(
+ prefs::kLoFiConsecutiveSessionDisables));
+ EXPECT_EQ(LoFiStatus::LOFI_STATUS_TEMPORARILY_OFF,
+ test_context_->config()->GetLoFiStatus());
+}
+
TEST_F(DataReductionProxySettingsTest, TestGetDailyContentLengths) {
ContentLengthList result =
settings_->GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength);
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 8893fcb..24c108d 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
@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/field_trial.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/values.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_client_config_parser.h"
@@ -211,6 +212,20 @@ bool DataReductionProxyParams::ShouldUseSecureProxyByDefault() {
return true;
}
+// static
+int DataReductionProxyParams::GetFieldTrialParameterAsInteger(
+ const std::string& group,
+ const std::string& param_name,
+ int default_value) {
+ std::string param_value =
+ variations::GetVariationParamValue(group, param_name);
+ int value;
+ if (param_value.empty() || !base::StringToInt(param_value, &value))
+ return default_value;
+
+ return value;
+}
+
void DataReductionProxyParams::EnableQuic(bool enable) {
quic_enabled_ = enable;
DCHECK(!quic_enabled_ || IsIncludedInQuicFieldTrial());
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 05e2fe1..b4ada80 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
@@ -136,6 +136,13 @@ class DataReductionProxyParams : public DataReductionProxyConfigValues {
// secure proxy check fails.
static bool ShouldUseSecureProxyByDefault();
+ // Retrieves the int stored in |param_name| from the field trial group
+ // |group|. If the value is not present or cannot be parsed returns
+ // |default_value|.
+ static int GetFieldTrialParameterAsInteger(const std::string& group,
+ const std::string& param_name,
+ int default_value);
+
// Constructs configuration parameters. If |kAllowed|, then the standard
// data reduction proxy configuration is allowed to be used. If
// |kfallbackAllowed| a fallback proxy can be used if the primary proxy is
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.cc
index 5164895..46d1f0d5 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.cc
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.cc
@@ -91,6 +91,22 @@ const char kHttpReceivedContentLength[] = "http_received_content_length";
// received over the network.
const char kHttpOriginalContentLength[] = "http_original_content_length";
+// An integer pref that contains the Lo-Fi version for the implicit opt-out
+// rules. Any time this value is incremented via Finch,
+// kLoFiConsecutiveSessionDisables is reset to zero.
+const char kLoFiImplicitOptOutVersion[] =
+ "data_reduction_lo_fi.implicit_opt_out_version";
+
+// An integer pref that contains the number of times that "Load images" has been
+// requested on the Lo-Fi snackbar for the current session.
+const char kLoFiLoadImagesPerSession[] =
+ "data_reduction_lo_fi.load_images_requests_per_session";
+
+// An integer pref that contains the number of consecutive sessions that LoFi
+// has been disabled.
+const char kLoFiConsecutiveSessionDisables[] =
+ "data_reduction_lo_fi.consecutive_session_disables";
+
// Pref to store the retrieval time of the last simulated Data Reduction Proxy
// configuration. This is part of an experiment to see how many bytes are lost
// if the Data Reduction Proxy is not used due to configuration being expired
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h b/components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h
index 72116b5..df10c80 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h
@@ -29,6 +29,9 @@ extern const char kDataReductionProxyAltEnabled[];
extern const char kDataReductionProxyWasEnabledBefore[];
extern const char kHttpOriginalContentLength[];
extern const char kHttpReceivedContentLength[];
+extern const char kLoFiImplicitOptOutVersion[];
+extern const char kLoFiLoadImagesPerSession[];
+extern const char kLoFiConsecutiveSessionDisables[];
extern const char kSimulatedConfigRetrieveTime[];
extern const char kStatisticsPrefsMigrated[];
extern const char kUpdateDailyReceivedContentLengths[];