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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014 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 "chrome/browser/prefs/tracked/pref_store_hash_store_contents.h"
6
7 #include "base/callback.h"
8 #include "base/logging.h"
9 #include "base/prefs/persistent_pref_store.h"
10 #include "base/values.h"
11 #include "chrome/common/pref_names.h"
12 #include "components/pref_registry/pref_registry_syncable.h"
13
14 namespace {
15
16 class PrefStoreMutableDictionary : public HashStoreContents::MutableDictionary {
17 public:
18 PrefStoreMutableDictionary(const std::string& key,
19 WriteablePrefStore* pref_store);
20 virtual ~PrefStoreMutableDictionary();
21
22 // MutableDictionary implementation
23 virtual base::DictionaryValue* operator->() OVERRIDE;
24
25 private:
26 const std::string key_;
27 WriteablePrefStore* pref_store_;
28 scoped_ptr<base::DictionaryValue> mutable_dictionary_;
29 };
30
31 PrefStoreMutableDictionary::PrefStoreMutableDictionary(
32 const std::string& key,
33 WriteablePrefStore* pref_store)
34 : key_(key), pref_store_(pref_store) {
35 }
36
37 PrefStoreMutableDictionary::~PrefStoreMutableDictionary() {
38 pref_store_->ReportValueChanged(key_);
39 }
40
41 base::DictionaryValue* PrefStoreMutableDictionary::operator->() {
42 base::DictionaryValue* mac_dictionary = NULL;
43 base::Value* mac_dictionary_value = NULL;
44
45 if (pref_store_->GetMutableValue(key_, &mac_dictionary_value))
46 mac_dictionary_value->GetAsDictionary(&mac_dictionary);
47
48 if (!mac_dictionary) {
49 mac_dictionary = new base::DictionaryValue;
50 pref_store_->SetValue(key_, mac_dictionary);
51 }
52
53 return mac_dictionary;
54 }
55
56 const base::DictionaryValue* GetMacDictionary(
57 const WriteablePrefStore* pref_store) {
58 const base::DictionaryValue* mac_dictionary = NULL;
59 const base::Value* mac_dictionary_value = NULL;
60 if (pref_store->GetValue(prefs::kProfilePreferenceHashes,
61 &mac_dictionary_value))
62 mac_dictionary_value->GetAsDictionary(&mac_dictionary);
63 return mac_dictionary;
64 }
65
66 } // namespace
67
68 // static
69 const char PrefStoreHashStoreContents::kSuperMacPref[] = "super_mac";
70
71 PrefStoreHashStoreContents::PrefStoreHashStoreContents(
72 PersistentPrefStore* pref_store)
73 : pref_store_(pref_store), persistent_pref_store_(NULL) {
74 }
75
76 PrefStoreHashStoreContents::PrefStoreHashStoreContents(
77 WriteablePrefStore* pref_store)
78 : pref_store_(pref_store), persistent_pref_store_(NULL) {
79 }
80
81 // static
82 void PrefStoreHashStoreContents::RegisterProfilePrefs(
83 user_prefs::PrefRegistrySyncable* registry) {
84 registry->RegisterDictionaryPref(
85 prefs::kProfilePreferenceHashes,
86 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
87 registry->RegisterStringPref(
88 kSuperMacPref,
89 std::string(),
90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
91 }
92
93 std::string PrefStoreHashStoreContents::hash_store_id() const {
94 return "";
95 }
96
97 void PrefStoreHashStoreContents::Reset() {
98 pref_store_->RemoveValue(prefs::kProfilePreferenceHashes);
99 }
100
101 bool PrefStoreHashStoreContents::IsInitialized() const {
102 return pref_store_->GetValue(prefs::kProfilePreferenceHashes, NULL);
103 }
104
105 const base::DictionaryValue* PrefStoreHashStoreContents::GetContents() const {
106 return GetMacDictionary(pref_store_);
107 }
108
109 scoped_ptr<HashStoreContents::MutableDictionary>
110 PrefStoreHashStoreContents::GetMutableContents() {
111 return scoped_ptr<MutableDictionary>(new PrefStoreMutableDictionary(
112 prefs::kProfilePreferenceHashes, pref_store_));
113 }
114
115 std::string PrefStoreHashStoreContents::GetSuperMac() const {
116 std::string super_mac_string;
117 const base::Value* super_mac_value = NULL;
118 if (pref_store_->GetValue(kSuperMacPref, &super_mac_value))
119 super_mac_value->GetAsString(&super_mac_string);
120 return super_mac_string;
121 }
122
123 void PrefStoreHashStoreContents::SetSuperMac(const std::string& super_mac) {
124 pref_store_->SetValue(kSuperMacPref, new base::StringValue(super_mac));
125 }
126
127 void PrefStoreHashStoreContents::CommitPendingWrite() {
128 if (persistent_pref_store_)
129 persistent_pref_store_->CommitPendingWrite();
130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698