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 "components/pref_registry/pref_registry_syncable.h" | |
12 | |
13 namespace { | |
14 | |
15 // static | |
16 const char kPreferenceMACs[] = "macs"; | |
gab
2014/06/17 02:00:06
Put both "macs" and "super_mac" under the same JSO
erikwright (departed)
2014/06/17 19:07:23
Done.
| |
17 | |
18 // static | |
gab
2014/06/17 02:00:06
Remove "// static" here and above.
erikwright (departed)
2014/06/17 19:07:24
Done.
| |
19 const char kSuperMACPref[] = "super_mac"; | |
20 | |
21 class MutablePreferenceMacDictionary | |
22 : public HashStoreContents::MutableDictionary { | |
23 public: | |
24 explicit MutablePreferenceMacDictionary(base::DictionaryValue* storage); | |
25 | |
26 // MutableDictionary implementation | |
27 virtual base::DictionaryValue* operator->() OVERRIDE; | |
28 | |
29 private: | |
30 base::DictionaryValue* storage_; | |
31 DISALLOW_COPY_AND_ASSIGN(MutablePreferenceMacDictionary); | |
gab
2014/06/17 02:00:05
I think the Chromium style is to have an empty lin
erikwright (departed)
2014/06/17 19:07:24
Done.
| |
32 }; | |
33 | |
34 MutablePreferenceMacDictionary::MutablePreferenceMacDictionary( | |
35 base::DictionaryValue* storage) | |
36 : storage_(storage) { | |
37 } | |
38 | |
39 base::DictionaryValue* MutablePreferenceMacDictionary::operator->() { | |
40 base::DictionaryValue* mac_dictionary = NULL; | |
41 | |
42 if (!storage_->GetDictionary(kPreferenceMACs, &mac_dictionary)) { | |
43 mac_dictionary = new base::DictionaryValue; | |
44 storage_->Set(kPreferenceMACs, mac_dictionary); | |
45 } | |
46 | |
47 return mac_dictionary; | |
48 } | |
49 | |
50 } // namespace | |
51 | |
52 DictionaryHashStoreContents::DictionaryHashStoreContents( | |
53 base::DictionaryValue* storage) | |
54 : storage_(storage) { | |
55 } | |
56 | |
57 // static | |
58 void DictionaryHashStoreContents::RegisterProfilePrefs( | |
59 user_prefs::PrefRegistrySyncable* registry) { | |
60 registry->RegisterDictionaryPref( | |
61 kPreferenceMACs, | |
62 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
63 registry->RegisterStringPref( | |
64 kSuperMACPref, | |
65 std::string(), | |
66 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
67 } | |
68 | |
69 std::string DictionaryHashStoreContents::hash_store_id() const { | |
70 return ""; | |
71 } | |
72 | |
73 void DictionaryHashStoreContents::Reset() { | |
74 storage_->Remove(kPreferenceMACs, NULL); | |
75 } | |
76 | |
77 bool DictionaryHashStoreContents::IsInitialized() const { | |
78 return storage_->GetDictionary(kPreferenceMACs, NULL); | |
79 } | |
80 | |
81 const base::DictionaryValue* DictionaryHashStoreContents::GetContents() const { | |
82 const base::DictionaryValue* mac_dictionary = NULL; | |
83 storage_->GetDictionary(kPreferenceMACs, &mac_dictionary); | |
84 return mac_dictionary; | |
85 } | |
86 | |
87 scoped_ptr<HashStoreContents::MutableDictionary> | |
88 DictionaryHashStoreContents::GetMutableContents() { | |
89 return scoped_ptr<MutableDictionary>( | |
90 new MutablePreferenceMacDictionary(storage_)); | |
91 } | |
92 | |
93 std::string DictionaryHashStoreContents::GetSuperMac() const { | |
94 std::string super_mac_string; | |
95 storage_->GetString(kSuperMACPref, &super_mac_string); | |
96 return super_mac_string; | |
97 } | |
98 | |
99 void DictionaryHashStoreContents::SetSuperMac(const std::string& super_mac) { | |
100 storage_->SetString(kSuperMACPref, super_mac); | |
101 } | |
OLD | NEW |