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

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.cc

Issue 644883006: Pref to update daily content lengths with the latest values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add new include Created 6 years, 2 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/core/browser/data_reduction_proxy_statistics_prefs.cc
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 564438b2bde7a8416cf86d48951b210be1b4f0ab..e71bd294eb5a366193a0365693f4141b8f1f260f 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
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
+#include "base/prefs/pref_change_registrar.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/sequenced_task_runner.h"
@@ -24,15 +25,25 @@ DataReductionProxyStatisticsPrefs::DataReductionProxyStatisticsPrefs(
task_runner_(task_runner),
delay_(delay),
delayed_task_posted_(false),
- weak_factory_(this) {
+ weak_factory_(this),
+ pref_change_registrar_(new PrefChangeRegistrar()) {
DCHECK(prefs);
DCHECK_GE(delay.InMilliseconds(), 0);
Init();
}
-DataReductionProxyStatisticsPrefs::~DataReductionProxyStatisticsPrefs() {}
+DataReductionProxyStatisticsPrefs::~DataReductionProxyStatisticsPrefs() {
+ // This object is created on UI thread, but destroyed on IO thread. So no
+ // DCHECK on thread_checker_ here.
+}
+
+void DataReductionProxyStatisticsPrefs::ShutdownOnUIThread() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ pref_change_registrar_->RemoveAll();
+}
void DataReductionProxyStatisticsPrefs::Init() {
+ DCHECK(thread_checker_.CalledOnValidThread());
if (delay_ == base::TimeDelta())
return;
@@ -61,6 +72,20 @@ void DataReductionProxyStatisticsPrefs::Init() {
kDailyOriginalContentLengthViaDataReductionProxy);
InitListPref(data_reduction_proxy::prefs::
kDailyOriginalContentLengthWithDataReductionProxyEnabled);
+
+ pref_change_registrar_->Init(pref_service_);
+ pref_change_registrar_->Add(prefs::kUpdateDailyReceivedContentLengths,
+ base::Bind(&DataReductionProxyStatisticsPrefs::OnUpdateContentLengths,
+ weak_factory_.GetWeakPtr()));
+}
+
+void DataReductionProxyStatisticsPrefs::OnUpdateContentLengths() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!pref_service_->GetBoolean(prefs::kUpdateDailyReceivedContentLengths))
+ return;
+
+ WritePrefs();
+ pref_service_->SetBoolean(prefs::kUpdateDailyReceivedContentLengths, false);
}
void DataReductionProxyStatisticsPrefs::InitInt64Pref(const char* pref) {
@@ -103,6 +128,7 @@ base::ListValue* DataReductionProxyStatisticsPrefs::GetList(
}
void DataReductionProxyStatisticsPrefs::WritePrefs() {
+ DCHECK(thread_checker_.CalledOnValidThread());
if (delay_ == base::TimeDelta())
return;

Powered by Google App Engine
This is Rietveld 408576698