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

Side by Side 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: format 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/update_client/persisted_data.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/macros.h"
11 #include "base/threading/thread_checker.h"
12 #include "base/values.h"
13 #include "components/prefs/pref_registry_simple.h"
14 #include "components/prefs/pref_service.h"
15 #include "components/prefs/scoped_user_pref_update.h"
16
17 const char kPersistedDataPreference[] = "updateclientdata";
18 const int kDateLastRollCallUnknown = -2;
19
20 namespace update_client {
21
22 PersistedData::PersistedData(PrefService* pref_service)
23 : pref_service_(pref_service) {}
24
25 PersistedData::~PersistedData() {
26 DCHECK(thread_checker_.CalledOnValidThread());
27 }
28
29 int PersistedData::GetDateLastRollCall(const std::string& id) const {
30 DCHECK(thread_checker_.CalledOnValidThread());
31 if (!pref_service_)
32 return kDateLastRollCallUnknown;
33 int dlrc = kDateLastRollCallUnknown;
34 const base::DictionaryValue* dict =
35 pref_service_->GetDictionary(kPersistedDataPreference);
36 // We assume ids do not contain '.' characters.
37 DCHECK(std::string::npos == id.find('.'));
Bernhard Bauer 2016/04/08 21:54:07 Nit: Use DCHECK_EQ for nicer error messages in cas
waffles 2016/04/08 22:00:49 Done.
38 if (!dict->GetInteger("apps." + id + ".dlrc", &dlrc))
39 return kDateLastRollCallUnknown;
40 return dlrc;
41 }
42
43 void PersistedData::SetDateLastRollCall(const std::vector<std::string>& ids,
44 int datenum) const {
45 DCHECK(thread_checker_.CalledOnValidThread());
46 if (!pref_service_ || datenum < 0)
47 return;
48 DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
49 for (auto id : ids) {
50 // We assume ids do not contain '.' characters.
51 DCHECK(std::string::npos == id.find('.'));
52 update->SetInteger("apps." + id + ".dlrc", datenum);
53 }
54 }
55
56 void PersistedData::RegisterPrefs(PrefRegistrySimple* registry) {
57 registry->RegisterDictionaryPref(kPersistedDataPreference);
58 }
59
60 } // namespace update_client
OLDNEW
« 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