| Index: chrome/browser/prefs/tracked/dictionary_hash_store_contents.cc
|
| diff --git a/chrome/browser/prefs/tracked/dictionary_hash_store_contents.cc b/chrome/browser/prefs/tracked/dictionary_hash_store_contents.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..be3101aa5e0bbf04f96b4fd1da777bda9f956e59
|
| --- /dev/null
|
| +++ b/chrome/browser/prefs/tracked/dictionary_hash_store_contents.cc
|
| @@ -0,0 +1,104 @@
|
| +// 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/dictionary_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"
|
| +#include "components/pref_registry/pref_registry_syncable.h"
|
| +
|
| +namespace {
|
| +
|
| +class SimpleMutableDictionary : public HashStoreContents::MutableDictionary {
|
| + public:
|
| + SimpleMutableDictionary(const std::string& key,
|
| + base::DictionaryValue* storage);
|
| +
|
| + // MutableDictionary implementation
|
| + virtual base::DictionaryValue* operator->() OVERRIDE;
|
| +
|
| + private:
|
| + const std::string key_;
|
| + base::DictionaryValue* storage_;
|
| +};
|
| +
|
| +SimpleMutableDictionary::SimpleMutableDictionary(const std::string& key,
|
| + base::DictionaryValue* storage)
|
| + : key_(key), storage_(storage) {
|
| +}
|
| +
|
| +base::DictionaryValue* SimpleMutableDictionary::operator->() {
|
| + base::DictionaryValue* mac_dictionary = NULL;
|
| +
|
| + if (!storage_->GetDictionary(key_, &mac_dictionary)) {
|
| + mac_dictionary = new base::DictionaryValue;
|
| + storage_->Set(key_, mac_dictionary);
|
| + }
|
| +
|
| + return mac_dictionary;
|
| +}
|
| +
|
| +const base::DictionaryValue* GetMacDictionary(
|
| + const base::DictionaryValue* storage) {
|
| + const base::DictionaryValue* mac_dictionary = NULL;
|
| + storage->GetDictionary(prefs::kProfilePreferenceHashes, &mac_dictionary);
|
| + return mac_dictionary;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +const char DictionaryHashStoreContents::kSuperMacPref[] = "super_mac";
|
| +
|
| +DictionaryHashStoreContents::DictionaryHashStoreContents(
|
| + base::DictionaryValue* storage)
|
| + : storage_(storage) {
|
| +}
|
| +
|
| +// static
|
| +void DictionaryHashStoreContents::RegisterProfilePrefs(
|
| + user_prefs::PrefRegistrySyncable* registry) {
|
| + registry->RegisterDictionaryPref(
|
| + prefs::kProfilePreferenceHashes,
|
| + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
|
| + registry->RegisterStringPref(
|
| + kSuperMacPref,
|
| + std::string(),
|
| + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
|
| +}
|
| +
|
| +std::string DictionaryHashStoreContents::hash_store_id() const {
|
| + return "";
|
| +}
|
| +
|
| +void DictionaryHashStoreContents::Reset() {
|
| + storage_->Remove(prefs::kProfilePreferenceHashes, NULL);
|
| +}
|
| +
|
| +bool DictionaryHashStoreContents::IsInitialized() const {
|
| + return storage_->GetDictionary(prefs::kProfilePreferenceHashes, NULL);
|
| +}
|
| +
|
| +const base::DictionaryValue* DictionaryHashStoreContents::GetContents() const {
|
| + return GetMacDictionary(storage_);
|
| +}
|
| +
|
| +scoped_ptr<HashStoreContents::MutableDictionary>
|
| +DictionaryHashStoreContents::GetMutableContents() {
|
| + return scoped_ptr<MutableDictionary>(
|
| + new SimpleMutableDictionary(prefs::kProfilePreferenceHashes, storage_));
|
| +}
|
| +
|
| +std::string DictionaryHashStoreContents::GetSuperMac() const {
|
| + std::string super_mac_string;
|
| + storage_->GetString(kSuperMacPref, &super_mac_string);
|
| + return super_mac_string;
|
| +}
|
| +
|
| +void DictionaryHashStoreContents::SetSuperMac(const std::string& super_mac) {
|
| + storage_->SetString(kSuperMacPref, super_mac);
|
| +}
|
|
|