Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc

Issue 473723002: Update data reduction proxy statistics prefs less often on desktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tooManyWritesPatch
Patch Set: Addressed bengr comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc
index 09f5d2c43e7eccfa675c5a80a891d85f887d288c..f3bd2baec3a8a896eb0d17d3ed1a4b16a74bc83c 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc
@@ -93,7 +93,6 @@ DataReductionProxySettings::DataReductionProxySettings(
disabled_on_vpn_(false),
unreachable_(false),
prefs_(NULL),
- local_state_prefs_(NULL),
url_request_context_getter_(NULL),
configurator_(NULL) {
DCHECK(params);
@@ -123,14 +122,11 @@ void DataReductionProxySettings::InitPrefMembers() {
void DataReductionProxySettings::InitDataReductionProxySettings(
PrefService* prefs,
- PrefService* local_state_prefs,
net::URLRequestContextGetter* url_request_context_getter) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(prefs);
- DCHECK(local_state_prefs);
DCHECK(url_request_context_getter);
prefs_ = prefs;
- local_state_prefs_ = local_state_prefs;
url_request_context_getter_ = url_request_context_getter;
InitPrefMembers();
RecordDataReductionInit();
@@ -148,15 +144,18 @@ void DataReductionProxySettings::InitDataReductionProxySettings(
void DataReductionProxySettings::InitDataReductionProxySettings(
PrefService* prefs,
- PrefService* local_state_prefs,
net::URLRequestContextGetter* url_request_context_getter,
DataReductionProxyConfigurator* configurator) {
InitDataReductionProxySettings(prefs,
- local_state_prefs,
url_request_context_getter);
SetProxyConfigurator(configurator);
}
+void DataReductionProxySettings::SetDataReductionProxyStatisticsPrefs(
+ DataReductionProxyStatisticsPrefs* statistics_prefs) {
+ statistics_prefs_ = statistics_prefs;
+}
+
void DataReductionProxySettings::SetOnDataReductionEnabledCallback(
const base::Callback<void(bool)>& on_data_reduction_proxy_enabled) {
on_data_reduction_proxy_enabled_ = on_data_reduction_proxy_enabled;
@@ -208,9 +207,11 @@ void DataReductionProxySettings::SetDataReductionProxyAlternativeEnabled(
int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() {
DCHECK(thread_checker_.CalledOnValidThread());
- PrefService* local_state = GetLocalStatePrefs();
+ if (!statistics_prefs_) {
+ return 0;
bengr 2014/08/28 21:38:35 Why is this allowed?
megjablon 2014/08/30 01:10:04 Removed.
+ }
int64 last_update_internal =
- local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate);
+ statistics_prefs_->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate);
base::Time last_update = base::Time::FromInternalValue(last_update_internal);
return static_cast<int64>(last_update.ToJsTime());
}
@@ -305,11 +306,6 @@ PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() {
return prefs_;
}
-PrefService* DataReductionProxySettings::GetLocalStatePrefs() {
- DCHECK(thread_checker_.CalledOnValidThread());
- return local_state_prefs_;
-}
-
void DataReductionProxySettings::AddDefaultProxyBypassRules() {
// localhost
DCHECK(configurator_);
@@ -373,11 +369,12 @@ void DataReductionProxySettings::OnProxyAlternativeEnabledPrefChange() {
void DataReductionProxySettings::ResetDataReductionStatistics() {
DCHECK(thread_checker_.CalledOnValidThread());
- PrefService* prefs = GetLocalStatePrefs();
- if (!prefs)
+ if (!statistics_prefs_)
return;
- ListPrefUpdate original_update(prefs, prefs::kDailyHttpOriginalContentLength);
- ListPrefUpdate received_update(prefs, prefs::kDailyHttpReceivedContentLength);
+ base::ListValue* original_update =
+ statistics_prefs_->GetList(prefs::kDailyHttpOriginalContentLength);
+ base::ListValue* received_update =
+ statistics_prefs_->GetList(prefs::kDailyHttpReceivedContentLength);
original_update->Clear();
received_update->Clear();
for (size_t i = 0; i < kNumDaysInHistory; ++i) {
@@ -482,7 +479,10 @@ DataReductionProxySettings::ContentLengthList
DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) {
DCHECK(thread_checker_.CalledOnValidThread());
DataReductionProxySettings::ContentLengthList content_lengths;
- const base::ListValue* list_value = GetLocalStatePrefs()->GetList(pref_name);
+ if (!statistics_prefs_) {
+ return content_lengths;
+ }
+ const base::ListValue* list_value = statistics_prefs_->GetList(pref_name);
if (list_value->GetSize() == kNumDaysInHistory) {
for (size_t i = 0; i < kNumDaysInHistory; ++i) {
content_lengths.push_back(GetInt64PrefValue(*list_value, i));
@@ -498,8 +498,7 @@ void DataReductionProxySettings::GetContentLengths(
int64* last_update_time) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_LE(days, kNumDaysInHistory);
- PrefService* local_state = GetLocalStatePrefs();
- if (!local_state) {
+ if (!statistics_prefs_) {
*original_content_length = 0L;
*received_content_length = 0L;
*last_update_time = 0L;
@@ -507,9 +506,9 @@ void DataReductionProxySettings::GetContentLengths(
}
const base::ListValue* original_list =
- local_state->GetList(prefs::kDailyHttpOriginalContentLength);
+ statistics_prefs_->GetList(prefs::kDailyHttpOriginalContentLength);
const base::ListValue* received_list =
- local_state->GetList(prefs::kDailyHttpReceivedContentLength);
+ statistics_prefs_->GetList(prefs::kDailyHttpReceivedContentLength);
if (original_list->GetSize() != kNumDaysInHistory ||
received_list->GetSize() != kNumDaysInHistory) {
@@ -530,7 +529,7 @@ void DataReductionProxySettings::GetContentLengths(
*original_content_length = orig;
*received_content_length = recv;
*last_update_time =
- local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate);
+ statistics_prefs_->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate);
}
net::URLFetcher* DataReductionProxySettings::GetBaseURLFetcher(

Powered by Google App Engine
This is Rietveld 408576698