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

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: Pull some stuff from Persistent to WriteablePrefStore. 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
13 namespace {
14
15 class PrefStoreMutableDictionary : public HashStoreContents::MutableDictionary {
16 public:
17 PrefStoreMutableDictionary(const std::string& key,
18 WriteablePrefStore* pref_store);
19 virtual ~PrefStoreMutableDictionary();
20
21 // MutableDictionary implementation
22 virtual base::DictionaryValue* operator->() OVERRIDE;
23
24 private:
25 const std::string key_;
26 WriteablePrefStore* pref_store_;
27 scoped_ptr<base::DictionaryValue> mutable_dictionary_;
28 };
29
30 PrefStoreMutableDictionary::PrefStoreMutableDictionary(
31 const std::string& key,
32 WriteablePrefStore* pref_store)
33 : key_(key), pref_store_(pref_store) {
34 }
35
36 PrefStoreMutableDictionary::~PrefStoreMutableDictionary() {
37 pref_store_->ReportValueChanged(key_);
38 }
39
40 base::DictionaryValue* PrefStoreMutableDictionary::operator->() {
41 base::DictionaryValue* mac_dictionary = NULL;
42 base::Value* mac_dictionary_value = NULL;
43
44 if (pref_store_->GetMutableValue(key_, &mac_dictionary_value))
45 mac_dictionary_value->GetAsDictionary(&mac_dictionary);
46
47 if (!mac_dictionary) {
48 mac_dictionary = new base::DictionaryValue;
49 pref_store_->SetValue(key_, mac_dictionary);
50 }
51
52 return mac_dictionary;
53 }
54
55 const base::DictionaryValue* GetMacDictionary(
56 const WriteablePrefStore* pref_store) {
57 const base::DictionaryValue* mac_dictionary = NULL;
58 const base::Value* mac_dictionary_value = NULL;
59 if (pref_store->GetValue(prefs::kProfilePreferenceHashes,
60 &mac_dictionary_value))
61 mac_dictionary_value->GetAsDictionary(&mac_dictionary);
62 return mac_dictionary;
63 }
64
65 } // namespace
66
67 // static
68 const char PrefStoreHashStoreContents::kSuperMacPref[] = "super_mac";
69
70 PrefStoreHashStoreContents::PrefStoreHashStoreContents(
71 PersistentPrefStore* pref_store)
72 : pref_store_(pref_store), persistent_pref_store_(NULL) {
73 }
74
75 PrefStoreHashStoreContents::PrefStoreHashStoreContents(
76 WriteablePrefStore* pref_store)
77 : pref_store_(pref_store), persistent_pref_store_(NULL) {
78 }
79
80 std::string PrefStoreHashStoreContents::hash_store_id() const {
81 return "";
82 }
83
84 void PrefStoreHashStoreContents::Reset() {
85 pref_store_->RemoveValue(prefs::kProfilePreferenceHashes);
86 }
87
88 bool PrefStoreHashStoreContents::IsInitialized() const {
89 return pref_store_->GetValue(prefs::kProfilePreferenceHashes, NULL);
90 }
91
92 const base::DictionaryValue* PrefStoreHashStoreContents::GetContents() const {
93 return GetMacDictionary(pref_store_);
94 }
95
96 scoped_ptr<HashStoreContents::MutableDictionary>
97 PrefStoreHashStoreContents::GetMutableContents() {
98 return scoped_ptr<MutableDictionary>(new PrefStoreMutableDictionary(
99 prefs::kProfilePreferenceHashes, pref_store_));
100 }
101
102 std::string PrefStoreHashStoreContents::GetSuperMac() const {
103 std::string super_mac_string;
104 const base::Value* super_mac_value = NULL;
105 if (pref_store_->GetValue(kSuperMacPref, &super_mac_value))
106 super_mac_value->GetAsString(&super_mac_string);
107 return super_mac_string;
108 }
109
110 void PrefStoreHashStoreContents::SetSuperMac(const std::string& super_mac) {
111 pref_store_->SetValue(kSuperMacPref, new base::StringValue(super_mac));
112 }
113
114 void PrefStoreHashStoreContents::CommitPendingWrite() {
115 if (persistent_pref_store_)
116 persistent_pref_store_->CommitPendingWrite();
117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698