Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Unified Diff: chrome/browser/prefs/tracked/pref_store_hash_store_contents.cc

Issue 324493002: Move preference MACs to the protected preference stores. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to CR comments. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f3ae20ed891ab6baba4bc8dcf327c7bc077cfe12
--- /dev/null
+++ b/chrome/browser/prefs/tracked/pref_store_hash_store_contents.cc
@@ -0,0 +1,130 @@
+// 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"
+#include "components/pref_registry/pref_registry_syncable.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) {
+}
+
+// static
+void PrefStoreHashStoreContents::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 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();
+}

Powered by Google App Engine
This is Rietveld 408576698