| 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";
|
| +
|
| +}
|
| +
|
| +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;
|
| + int dlrc = -2;
|
| + const base::DictionaryValue* dict =
|
| + pref_service_->GetDictionary(kPersistedDataPreference);
|
| + // We assume ids do not contain '.' characters.
|
| + 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
|
|
|