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

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: Another test fix. 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
« no previous file with comments | « components/update_client/persisted_data.h ('k') | components/update_client/persisted_data_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0894dba0d0d333108d2ebcd4ef9ceb9b44ed910b
--- /dev/null
+++ b/components/update_client/persisted_data.cc
@@ -0,0 +1,60 @@
+// 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"
+
+const char kPersistedDataPreference[] = "updateclientdata";
+const int kDateLastRollCallUnknown = -2;
+
+namespace update_client {
+
+PersistedData::PersistedData(PrefService* pref_service)
+ : pref_service_(pref_service) {}
+
+PersistedData::~PersistedData() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+}
+
+int PersistedData::GetDateLastRollCall(const std::string& id) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!pref_service_)
+ return kDateLastRollCallUnknown;
+ int dlrc = kDateLastRollCallUnknown;
+ const base::DictionaryValue* dict =
+ pref_service_->GetDictionary(kPersistedDataPreference);
+ // We assume ids do not contain '.' characters.
+ DCHECK_EQ(std::string::npos, id.find('.'));
+ if (!dict->GetInteger("apps." + id + ".dlrc", &dlrc))
+ return kDateLastRollCallUnknown;
+ return dlrc;
+}
+
+void PersistedData::SetDateLastRollCall(const std::vector<std::string>& ids,
+ int datenum) const {
+ 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.
+ DCHECK_EQ(std::string::npos, id.find('.'));
+ update->SetInteger("apps." + id + ".dlrc", datenum);
+ }
+}
+
+void PersistedData::RegisterPrefs(PrefRegistrySimple* registry) {
+ registry->RegisterDictionaryPref(kPersistedDataPreference);
+}
+
+} // namespace update_client
« no previous file with comments | « components/update_client/persisted_data.h ('k') | components/update_client/persisted_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698