OLD | NEW |
---|---|
(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/dictionary_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 SimpleMutableDictionary : public HashStoreContents::MutableDictionary { | |
17 public: | |
18 SimpleMutableDictionary(const std::string& key, | |
19 base::DictionaryValue* storage); | |
20 | |
21 // MutableDictionary implementation | |
22 virtual base::DictionaryValue* operator->() OVERRIDE; | |
23 | |
24 private: | |
25 const std::string key_; | |
26 base::DictionaryValue* storage_; | |
27 }; | |
28 | |
29 SimpleMutableDictionary::SimpleMutableDictionary(const std::string& key, | |
gab
2014/06/13 01:57:43
This is only used for the kProfilePreferenceHashes
erikwright (departed)
2014/06/16 20:51:27
The flexibility was a remnant from a previous inca
| |
30 base::DictionaryValue* storage) | |
31 : key_(key), storage_(storage) { | |
32 } | |
33 | |
34 base::DictionaryValue* SimpleMutableDictionary::operator->() { | |
35 base::DictionaryValue* mac_dictionary = NULL; | |
36 | |
37 if (!storage_->GetDictionary(key_, &mac_dictionary)) { | |
38 mac_dictionary = new base::DictionaryValue; | |
39 storage_->Set(key_, mac_dictionary); | |
40 } | |
41 | |
42 return mac_dictionary; | |
43 } | |
44 | |
45 const base::DictionaryValue* GetMacDictionary( | |
46 const base::DictionaryValue* storage) { | |
gab
2014/06/13 01:57:43
Since this method needs access to the only member
erikwright (departed)
2014/06/16 20:51:27
Done.
| |
47 const base::DictionaryValue* mac_dictionary = NULL; | |
48 storage->GetDictionary(prefs::kProfilePreferenceHashes, &mac_dictionary); | |
49 return mac_dictionary; | |
50 } | |
51 | |
52 } // namespace | |
53 | |
54 // static | |
55 const char DictionaryHashStoreContents::kSuperMacPref[] = "super_mac"; | |
56 | |
57 DictionaryHashStoreContents::DictionaryHashStoreContents( | |
58 base::DictionaryValue* storage) | |
59 : storage_(storage) { | |
60 } | |
61 | |
62 // static | |
63 void DictionaryHashStoreContents::RegisterProfilePrefs( | |
64 user_prefs::PrefRegistrySyncable* registry) { | |
65 registry->RegisterDictionaryPref( | |
66 prefs::kProfilePreferenceHashes, | |
gab
2014/06/13 01:57:43
In fact, how about using a new pref altogether, e.
erikwright (departed)
2014/06/16 20:51:27
Done.
| |
67 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
68 registry->RegisterStringPref( | |
69 kSuperMacPref, | |
70 std::string(), | |
71 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
72 } | |
73 | |
74 std::string DictionaryHashStoreContents::hash_store_id() const { | |
75 return ""; | |
76 } | |
77 | |
78 void DictionaryHashStoreContents::Reset() { | |
79 storage_->Remove(prefs::kProfilePreferenceHashes, NULL); | |
80 } | |
81 | |
82 bool DictionaryHashStoreContents::IsInitialized() const { | |
83 return storage_->GetDictionary(prefs::kProfilePreferenceHashes, NULL); | |
84 } | |
85 | |
86 const base::DictionaryValue* DictionaryHashStoreContents::GetContents() const { | |
87 return GetMacDictionary(storage_); | |
88 } | |
89 | |
90 scoped_ptr<HashStoreContents::MutableDictionary> | |
91 DictionaryHashStoreContents::GetMutableContents() { | |
92 return scoped_ptr<MutableDictionary>( | |
93 new SimpleMutableDictionary(prefs::kProfilePreferenceHashes, storage_)); | |
94 } | |
95 | |
96 std::string DictionaryHashStoreContents::GetSuperMac() const { | |
97 std::string super_mac_string; | |
98 storage_->GetString(kSuperMacPref, &super_mac_string); | |
99 return super_mac_string; | |
100 } | |
101 | |
102 void DictionaryHashStoreContents::SetSuperMac(const std::string& super_mac) { | |
103 storage_->SetString(kSuperMacPref, super_mac); | |
104 } | |
OLD | NEW |