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 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_EQ(std::string::npos, id.find('.')); |
| 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_EQ(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 |
OLD | NEW |