diff options
Diffstat (limited to 'components/data_reduction_proxy')
5 files changed, 81 insertions, 1 deletions
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.cc index 57247f6..281cd96 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.cc @@ -5,6 +5,7 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h" #include "base/bind.h" +#include "base/command_line.h" #include "base/location.h" #include "base/logging.h" #include "base/prefs/pref_change_registrar.h" @@ -14,6 +15,7 @@ #include "base/strings/string_number_conversions.h" #include "base/time/time.h" #include "base/values.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h" namespace data_reduction_proxy { @@ -70,6 +72,11 @@ void DataReductionProxyStatisticsPrefs::Init() { InitListPref(data_reduction_proxy::prefs:: kDailyOriginalContentLengthWithDataReductionProxyEnabled); + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + data_reduction_proxy::switches::kClearDataReductionProxyDataSavings)) { + ClearDataSavingStatistics(); + } + pref_change_registrar_->Init(pref_service_); pref_change_registrar_->Add(prefs::kUpdateDailyReceivedContentLengths, base::Bind(&DataReductionProxyStatisticsPrefs::OnUpdateContentLengths, @@ -199,6 +206,32 @@ int64 DataReductionProxyStatisticsPrefs::GetListPrefInt64Value( return value; } +void DataReductionProxyStatisticsPrefs::ClearDataSavingStatistics() { + list_pref_map_.get(data_reduction_proxy::prefs:: + kDailyContentLengthHttpsWithDataReductionProxyEnabled)->Clear(); + list_pref_map_.get(data_reduction_proxy::prefs:: + kDailyContentLengthLongBypassWithDataReductionProxyEnabled)->Clear(); + list_pref_map_.get(data_reduction_proxy::prefs:: + kDailyContentLengthShortBypassWithDataReductionProxyEnabled)->Clear(); + list_pref_map_.get(data_reduction_proxy::prefs:: + kDailyContentLengthUnknownWithDataReductionProxyEnabled)->Clear(); + list_pref_map_.get( + data_reduction_proxy::prefs::kDailyContentLengthViaDataReductionProxy)-> + Clear(); + list_pref_map_.get(data_reduction_proxy::prefs:: + kDailyContentLengthWithDataReductionProxyEnabled)->Clear(); + list_pref_map_.get(data_reduction_proxy::prefs:: + kDailyHttpOriginalContentLength)->Clear(); + list_pref_map_.get(data_reduction_proxy::prefs:: + kDailyHttpReceivedContentLength)->Clear(); + list_pref_map_.get(data_reduction_proxy::prefs:: + kDailyOriginalContentLengthViaDataReductionProxy)->Clear(); + list_pref_map_.get(data_reduction_proxy::prefs:: + kDailyOriginalContentLengthWithDataReductionProxyEnabled)->Clear(); + + WritePrefs(); +} + base::WeakPtr<DataReductionProxyStatisticsPrefs> DataReductionProxyStatisticsPrefs::GetWeakPtr() { return weak_factory_.GetWeakPtr(); diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h index 7c5070b..2da0361 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h @@ -98,6 +98,9 @@ private: // index. int64 GetListPrefInt64Value(const base::ListValue& list_update, size_t index); + // Clears all data saving statistics. + void ClearDataSavingStatistics(); + PrefService* pref_service_; scoped_refptr<base::SequencedTaskRunner> task_runner_; const base::TimeDelta delay_; diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs_unittest.cc index ba72593..004e96b5 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs_unittest.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/command_line.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/pref_registry_simple.h" #include "base/prefs/testing_pref_service.h" @@ -12,6 +13,7 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h" #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h" +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -221,4 +223,42 @@ TEST_F(DataReductionProxyStatisticsPrefsTest, VerifyPrefs(dict); } +TEST_F(DataReductionProxyStatisticsPrefsTest, + ClearPrefsOnRestartEnabled) { + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + command_line->AppendSwitch( + data_reduction_proxy::switches::kClearDataReductionProxyDataSavings); + + base::ListValue list_value; + list_value.Insert(0, new base::StringValue(base::Int64ToString(1234))); + simple_pref_service_.Set(prefs::kDailyHttpOriginalContentLength, list_value); + + statistics_prefs_.reset(new DataReductionProxyStatisticsPrefs( + &simple_pref_service_, + task_runner_, + base::TimeDelta::FromMinutes(kWriteDelayMinutes))); + + const base::ListValue* value = simple_pref_service_.GetList( + prefs::kDailyHttpOriginalContentLength); + EXPECT_EQ(0u, value->GetSize()); +} + +TEST_F(DataReductionProxyStatisticsPrefsTest, + ClearPrefsOnRestartDisabled) { + base::ListValue list_value; + list_value.Insert(0, new base::StringValue(base::Int64ToString(1234))); + simple_pref_service_.Set(prefs::kDailyHttpOriginalContentLength, list_value); + + statistics_prefs_.reset(new DataReductionProxyStatisticsPrefs( + &simple_pref_service_, + task_runner_, + base::TimeDelta::FromMinutes(kWriteDelayMinutes))); + + const base::ListValue* value = simple_pref_service_.GetList( + prefs::kDailyHttpOriginalContentLength); + std::string string_value; + value->GetString(0, &string_value); + EXPECT_EQ("1234", string_value); +} + } // namespace data_reduction_proxy 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 7f3e03a..bab8af0 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 @@ -66,5 +66,9 @@ const char kEnableDataReductionProxyLoFi[] = const char kEnableDataReductionProxyBypassWarning[] = "enable-data-reduction-proxy-bypass-warning"; +// Clear data savings on Chrome startup. +const char kClearDataReductionProxyDataSavings[] = + "clear-data-reduction-proxy-data-savings"; + } // namespace switches } // namespace data_reduction_proxy 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 87d09fa..cd6d08d 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 @@ -27,7 +27,7 @@ extern const char kEnableDataReductionProxy[]; extern const char kEnableDataReductionProxyAlt[]; extern const char kEnableDataReductionProxyLoFi[]; extern const char kEnableDataReductionProxyBypassWarning[]; - +extern const char kClearDataReductionProxyDataSavings[]; } // namespace switches } // namespace data_reduction_proxy |