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 const char kPreferenceMACs[] = "protection.macs"; | |
16 const char kSuperMACPref[] = "protection.super_mac"; | |
17 | |
18 class MutablePreferenceMacDictionary | |
19 : public HashStoreContents::MutableDictionary { | |
20 public: | |
21 explicit MutablePreferenceMacDictionary(base::DictionaryValue* storage); | |
22 | |
23 // MutableDictionary implementation | |
24 base::DictionaryValue* operator->() override; | |
25 | |
26 private: | |
27 base::DictionaryValue* storage_; | |
28 | |
29 DISALLOW_COPY_AND_ASSIGN(MutablePreferenceMacDictionary); | |
30 }; | |
31 | |
32 MutablePreferenceMacDictionary::MutablePreferenceMacDictionary( | |
33 base::DictionaryValue* storage) | |
34 : storage_(storage) { | |
35 } | |
36 | |
37 base::DictionaryValue* MutablePreferenceMacDictionary::operator->() { | |
38 base::DictionaryValue* mac_dictionary = NULL; | |
39 | |
40 if (!storage_->GetDictionary(kPreferenceMACs, &mac_dictionary)) { | |
41 mac_dictionary = new base::DictionaryValue; | |
42 storage_->Set(kPreferenceMACs, mac_dictionary); | |
43 } | |
44 | |
45 return mac_dictionary; | |
46 } | |
47 | |
48 } // namespace | |
49 | |
50 DictionaryHashStoreContents::DictionaryHashStoreContents( | |
51 base::DictionaryValue* storage) | |
52 : storage_(storage) { | |
53 } | |
54 | |
55 // static | |
56 void DictionaryHashStoreContents::RegisterProfilePrefs( | |
57 user_prefs::PrefRegistrySyncable* registry) { | |
58 registry->RegisterDictionaryPref(kPreferenceMACs); | |
59 registry->RegisterStringPref(kSuperMACPref, std::string()); | |
60 } | |
61 | |
62 std::string DictionaryHashStoreContents::hash_store_id() const { | |
63 return ""; | |
64 } | |
65 | |
66 void DictionaryHashStoreContents::Reset() { | |
67 storage_->Remove(kPreferenceMACs, NULL); | |
68 } | |
69 | |
70 bool DictionaryHashStoreContents::IsInitialized() const { | |
71 return storage_->GetDictionary(kPreferenceMACs, NULL); | |
72 } | |
73 | |
74 const base::DictionaryValue* DictionaryHashStoreContents::GetContents() const { | |
75 const base::DictionaryValue* mac_dictionary = NULL; | |
76 storage_->GetDictionary(kPreferenceMACs, &mac_dictionary); | |
77 return mac_dictionary; | |
78 } | |
79 | |
80 scoped_ptr<HashStoreContents::MutableDictionary> | |
81 DictionaryHashStoreContents::GetMutableContents() { | |
82 return scoped_ptr<MutableDictionary>( | |
83 new MutablePreferenceMacDictionary(storage_)); | |
84 } | |
85 | |
86 std::string DictionaryHashStoreContents::GetSuperMac() const { | |
87 std::string super_mac_string; | |
88 storage_->GetString(kSuperMACPref, &super_mac_string); | |
89 return super_mac_string; | |
90 } | |
91 | |
92 void DictionaryHashStoreContents::SetSuperMac(const std::string& super_mac) { | |
93 storage_->SetString(kSuperMACPref, super_mac); | |
94 } | |
OLD | NEW |