| Index: chrome/browser/prefs/tracked/pref_store_hash_store_contents.cc
|
| diff --git a/chrome/browser/prefs/tracked/pref_store_hash_store_contents.cc b/chrome/browser/prefs/tracked/pref_store_hash_store_contents.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6061bafddc3204adfc8e518fc4fd23d0d451d62d
|
| --- /dev/null
|
| +++ b/chrome/browser/prefs/tracked/pref_store_hash_store_contents.cc
|
| @@ -0,0 +1,117 @@
|
| +// Copyright (c) 2014 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 "chrome/browser/prefs/tracked/pref_store_hash_store_contents.h"
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/logging.h"
|
| +#include "base/prefs/persistent_pref_store.h"
|
| +#include "base/values.h"
|
| +#include "chrome/common/pref_names.h"
|
| +
|
| +namespace {
|
| +
|
| +class PrefStoreMutableDictionary : public HashStoreContents::MutableDictionary {
|
| + public:
|
| + PrefStoreMutableDictionary(const std::string& key,
|
| + WriteablePrefStore* pref_store);
|
| + virtual ~PrefStoreMutableDictionary();
|
| +
|
| + // MutableDictionary implementation
|
| + virtual base::DictionaryValue* operator->() OVERRIDE;
|
| +
|
| + private:
|
| + const std::string key_;
|
| + WriteablePrefStore* pref_store_;
|
| + scoped_ptr<base::DictionaryValue> mutable_dictionary_;
|
| +};
|
| +
|
| +PrefStoreMutableDictionary::PrefStoreMutableDictionary(
|
| + const std::string& key,
|
| + WriteablePrefStore* pref_store)
|
| + : key_(key), pref_store_(pref_store) {
|
| +}
|
| +
|
| +PrefStoreMutableDictionary::~PrefStoreMutableDictionary() {
|
| + pref_store_->ReportValueChanged(key_);
|
| +}
|
| +
|
| +base::DictionaryValue* PrefStoreMutableDictionary::operator->() {
|
| + base::DictionaryValue* mac_dictionary = NULL;
|
| + base::Value* mac_dictionary_value = NULL;
|
| +
|
| + if (pref_store_->GetMutableValue(key_, &mac_dictionary_value))
|
| + mac_dictionary_value->GetAsDictionary(&mac_dictionary);
|
| +
|
| + if (!mac_dictionary) {
|
| + mac_dictionary = new base::DictionaryValue;
|
| + pref_store_->SetValue(key_, mac_dictionary);
|
| + }
|
| +
|
| + return mac_dictionary;
|
| +}
|
| +
|
| +const base::DictionaryValue* GetMacDictionary(
|
| + const WriteablePrefStore* pref_store) {
|
| + const base::DictionaryValue* mac_dictionary = NULL;
|
| + const base::Value* mac_dictionary_value = NULL;
|
| + if (pref_store->GetValue(prefs::kProfilePreferenceHashes,
|
| + &mac_dictionary_value))
|
| + mac_dictionary_value->GetAsDictionary(&mac_dictionary);
|
| + return mac_dictionary;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +const char PrefStoreHashStoreContents::kSuperMacPref[] = "super_mac";
|
| +
|
| +PrefStoreHashStoreContents::PrefStoreHashStoreContents(
|
| + PersistentPrefStore* pref_store)
|
| + : pref_store_(pref_store), persistent_pref_store_(NULL) {
|
| +}
|
| +
|
| +PrefStoreHashStoreContents::PrefStoreHashStoreContents(
|
| + WriteablePrefStore* pref_store)
|
| + : pref_store_(pref_store), persistent_pref_store_(NULL) {
|
| +}
|
| +
|
| +std::string PrefStoreHashStoreContents::hash_store_id() const {
|
| + return "";
|
| +}
|
| +
|
| +void PrefStoreHashStoreContents::Reset() {
|
| + pref_store_->RemoveValue(prefs::kProfilePreferenceHashes);
|
| +}
|
| +
|
| +bool PrefStoreHashStoreContents::IsInitialized() const {
|
| + return pref_store_->GetValue(prefs::kProfilePreferenceHashes, NULL);
|
| +}
|
| +
|
| +const base::DictionaryValue* PrefStoreHashStoreContents::GetContents() const {
|
| + return GetMacDictionary(pref_store_);
|
| +}
|
| +
|
| +scoped_ptr<HashStoreContents::MutableDictionary>
|
| +PrefStoreHashStoreContents::GetMutableContents() {
|
| + return scoped_ptr<MutableDictionary>(new PrefStoreMutableDictionary(
|
| + prefs::kProfilePreferenceHashes, pref_store_));
|
| +}
|
| +
|
| +std::string PrefStoreHashStoreContents::GetSuperMac() const {
|
| + std::string super_mac_string;
|
| + const base::Value* super_mac_value = NULL;
|
| + if (pref_store_->GetValue(kSuperMacPref, &super_mac_value))
|
| + super_mac_value->GetAsString(&super_mac_string);
|
| + return super_mac_string;
|
| +}
|
| +
|
| +void PrefStoreHashStoreContents::SetSuperMac(const std::string& super_mac) {
|
| + pref_store_->SetValue(kSuperMacPref, new base::StringValue(super_mac));
|
| +}
|
| +
|
| +void PrefStoreHashStoreContents::CommitPendingWrite() {
|
| + if (persistent_pref_store_)
|
| + persistent_pref_store_->CommitPendingWrite();
|
| +}
|
|
|