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

Unified Diff: components/update_client/persisted_data.cc

Issue 1861383004: Add module for counting date-last-roll-call and persisting those counts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ASAN Created 4 years, 8 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/update_client/persisted_data.cc
diff --git a/components/update_client/persisted_data.cc b/components/update_client/persisted_data.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ef0530eb67f2d5540fac26b76c3ce19f7c1400d8
--- /dev/null
+++ b/components/update_client/persisted_data.cc
@@ -0,0 +1,62 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/update_client/persisted_data.h"
+
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/threading/thread_checker.h"
+#include "base/values.h"
+#include "components/prefs/pref_registry_simple.h"
+#include "components/prefs/pref_service.h"
+#include "components/prefs/scoped_user_pref_update.h"
+
+namespace {
+
+const char kPersistedDataPreference[] = "updateclientdata";
Bernhard Bauer 2016/04/08 09:06:09 FWIW, the anonymous namespace isn't strictly neces
waffles 2016/04/08 19:11:01 Done.
+
+}
+
+namespace update_client {
+
+PersistedData::PersistedData(PrefService* pref_service)
+ : pref_service_(pref_service) {
+}
+
+PersistedData::~PersistedData() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+}
+
+int PersistedData::DateLastRollCall(const std::string& id) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!pref_service_)
+ return -2;
Bernhard Bauer 2016/04/08 09:06:09 Make this a constant?
waffles 2016/04/08 19:11:01 Done.
+ int dlrc = -2;
+ const base::DictionaryValue* dict =
+ pref_service_->GetDictionary(kPersistedDataPreference);
+ // We assume ids do not contain '.' characters.
Bernhard Bauer 2016/04/08 09:06:09 DCHECK that?
waffles 2016/04/08 19:11:01 Done.
+ if (!dict->GetInteger("apps." + id + ".dlrc", &dlrc))
+ return -2;
+ return dlrc;
+}
+
+void PersistedData::SetDateLastRollCall(
+ const std::vector<std::string>& ids, int datenum) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!pref_service_ || datenum < 0)
+ return;
+ DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
+ for (auto id : ids) {
+ // We assume ids do not contain '.' characters.
+ update->SetInteger("apps." + id + ".dlrc", datenum);
+ }
+}
+
+void RegisterPersistedDataPreferences(PrefRegistrySimple* registry) {
+ registry->RegisterDictionaryPref(kPersistedDataPreference);
+}
+
+} // namespace update_client

Powered by Google App Engine
This is Rietveld 408576698