OLD | NEW |
---|---|
(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 namespace { | |
18 | |
19 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.
| |
20 | |
21 } | |
22 | |
23 namespace update_client { | |
24 | |
25 PersistedData::PersistedData(PrefService* pref_service) | |
26 : pref_service_(pref_service) { | |
27 } | |
28 | |
29 PersistedData::~PersistedData() { | |
30 DCHECK(thread_checker_.CalledOnValidThread()); | |
31 } | |
32 | |
33 int PersistedData::DateLastRollCall(const std::string& id) const { | |
34 DCHECK(thread_checker_.CalledOnValidThread()); | |
35 if (!pref_service_) | |
36 return -2; | |
Bernhard Bauer
2016/04/08 09:06:09
Make this a constant?
waffles
2016/04/08 19:11:01
Done.
| |
37 int dlrc = -2; | |
38 const base::DictionaryValue* dict = | |
39 pref_service_->GetDictionary(kPersistedDataPreference); | |
40 // 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.
| |
41 if (!dict->GetInteger("apps." + id + ".dlrc", &dlrc)) | |
42 return -2; | |
43 return dlrc; | |
44 } | |
45 | |
46 void PersistedData::SetDateLastRollCall( | |
47 const std::vector<std::string>& ids, int datenum) { | |
48 DCHECK(thread_checker_.CalledOnValidThread()); | |
49 if (!pref_service_ || datenum < 0) | |
50 return; | |
51 DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference); | |
52 for (auto id : ids) { | |
53 // We assume ids do not contain '.' characters. | |
54 update->SetInteger("apps." + id + ".dlrc", datenum); | |
55 } | |
56 } | |
57 | |
58 void RegisterPersistedDataPreferences(PrefRegistrySimple* registry) { | |
59 registry->RegisterDictionaryPref(kPersistedDataPreference); | |
60 } | |
61 | |
62 } // namespace update_client | |
OLD | NEW |