OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" | 5 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" |
6 | 6 |
7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 // static | 52 // static |
53 const char PrefServiceHashStoreContents::kHashOfHashesDict[] = "hash_of_hashes"; | 53 const char PrefServiceHashStoreContents::kHashOfHashesDict[] = "hash_of_hashes"; |
54 | 54 |
55 // static | 55 // static |
56 const char PrefServiceHashStoreContents::kStoreVersionsDict[] = | 56 const char PrefServiceHashStoreContents::kStoreVersionsDict[] = |
57 "store_versions"; | 57 "store_versions"; |
58 | 58 |
59 PrefServiceHashStoreContents::PrefServiceHashStoreContents( | 59 PrefServiceHashStoreContents::PrefServiceHashStoreContents( |
60 const std::string& hash_store_id, | 60 const std::string& hash_store_id, |
61 PrefService* pref_service) | 61 PrefService* pref_service) |
62 : hash_store_id_(hash_store_id), pref_service_(pref_service) {} | 62 : hash_store_id_(hash_store_id), pref_service_(pref_service) { |
63 DictionaryPrefUpdate update(pref_service_, prefs::kProfilePreferenceHashes); | |
gab
2014/06/11 21:39:29
Add:
// TODO(erikwright): Remove kStoreVersionsDic
| |
64 update->RemovePath(kStoreVersionsDict, NULL); | |
65 } | |
63 | 66 |
64 // static | 67 // static |
65 void PrefServiceHashStoreContents::RegisterPrefs(PrefRegistrySimple* registry) { | 68 void PrefServiceHashStoreContents::RegisterPrefs(PrefRegistrySimple* registry) { |
66 // Register the top level dictionary to map profile names to dictionaries of | 69 // Register the top level dictionary to map profile names to dictionaries of |
67 // tracked preferences. | 70 // tracked preferences. |
68 registry->RegisterDictionaryPref(prefs::kProfilePreferenceHashes); | 71 registry->RegisterDictionaryPref(prefs::kProfilePreferenceHashes); |
69 } | 72 } |
70 | 73 |
71 // static | 74 // static |
72 void PrefServiceHashStoreContents::ResetAllPrefHashStores( | 75 void PrefServiceHashStoreContents::ResetAllPrefHashStores( |
73 PrefService* pref_service) { | 76 PrefService* pref_service) { |
74 pref_service->ClearPref(prefs::kProfilePreferenceHashes); | 77 pref_service->ClearPref(prefs::kProfilePreferenceHashes); |
75 } | 78 } |
76 | 79 |
77 std::string PrefServiceHashStoreContents::hash_store_id() const { | 80 std::string PrefServiceHashStoreContents::hash_store_id() const { |
78 return hash_store_id_; | 81 return hash_store_id_; |
79 } | 82 } |
80 | 83 |
81 void PrefServiceHashStoreContents::Reset() { | 84 void PrefServiceHashStoreContents::Reset() { |
82 DictionaryPrefUpdate update(pref_service_, prefs::kProfilePreferenceHashes); | 85 DictionaryPrefUpdate update(pref_service_, prefs::kProfilePreferenceHashes); |
83 | 86 |
84 update->RemoveWithoutPathExpansion(hash_store_id_, NULL); | 87 update->RemoveWithoutPathExpansion(hash_store_id_, NULL); |
85 | 88 |
86 // Remove this store's entry in the kStoreVersionsDict. | |
87 base::DictionaryValue* version_dict; | |
88 if (update->GetDictionary(kStoreVersionsDict, &version_dict)) | |
89 version_dict->RemoveWithoutPathExpansion(hash_store_id_, NULL); | |
90 | |
91 // Remove this store's entry in the kHashOfHashesDict. | 89 // Remove this store's entry in the kHashOfHashesDict. |
92 base::DictionaryValue* hash_of_hashes_dict; | 90 base::DictionaryValue* hash_of_hashes_dict; |
93 if (update->GetDictionaryWithoutPathExpansion(kHashOfHashesDict, | 91 if (update->GetDictionaryWithoutPathExpansion(kHashOfHashesDict, |
94 &hash_of_hashes_dict)) { | 92 &hash_of_hashes_dict)) { |
95 hash_of_hashes_dict->RemoveWithoutPathExpansion(hash_store_id_, NULL); | 93 hash_of_hashes_dict->RemoveWithoutPathExpansion(hash_store_id_, NULL); |
96 } | 94 } |
97 } | 95 } |
98 | 96 |
99 bool PrefServiceHashStoreContents::IsInitialized() const { | 97 bool PrefServiceHashStoreContents::IsInitialized() const { |
100 const base::DictionaryValue* pref_hash_dicts = | 98 const base::DictionaryValue* pref_hash_dicts = |
101 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); | 99 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); |
102 return pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, | 100 return pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, |
103 NULL); | 101 NULL); |
104 } | 102 } |
105 | 103 |
106 bool PrefServiceHashStoreContents::GetVersion(int* version) const { | |
107 DCHECK(version); | |
108 const base::DictionaryValue* pref_hash_data = | |
109 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); | |
110 | |
111 const base::DictionaryValue* version_dict; | |
112 return pref_hash_data->GetDictionary(kStoreVersionsDict, &version_dict) && | |
113 version_dict->GetIntegerWithoutPathExpansion(hash_store_id_, version); | |
114 } | |
115 | |
116 void PrefServiceHashStoreContents::SetVersion(int version) { | |
117 PrefServiceMutableDictionary(kStoreVersionsDict, pref_service_) | |
118 ->SetIntegerWithoutPathExpansion(hash_store_id_, version); | |
119 } | |
120 | |
121 const base::DictionaryValue* PrefServiceHashStoreContents::GetContents() const { | 104 const base::DictionaryValue* PrefServiceHashStoreContents::GetContents() const { |
122 const base::DictionaryValue* pref_hash_dicts = | 105 const base::DictionaryValue* pref_hash_dicts = |
123 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); | 106 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); |
124 const base::DictionaryValue* hashes_dict = NULL; | 107 const base::DictionaryValue* hashes_dict = NULL; |
125 pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, | 108 pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, |
126 &hashes_dict); | 109 &hashes_dict); |
127 return hashes_dict; | 110 return hashes_dict; |
128 } | 111 } |
129 | 112 |
130 scoped_ptr<HashStoreContents::MutableDictionary> | 113 scoped_ptr<HashStoreContents::MutableDictionary> |
(...skipping 16 matching lines...) Expand all Loading... | |
147 } | 130 } |
148 | 131 |
149 void PrefServiceHashStoreContents::SetSuperMac(const std::string& super_mac) { | 132 void PrefServiceHashStoreContents::SetSuperMac(const std::string& super_mac) { |
150 PrefServiceMutableDictionary(kHashOfHashesDict, pref_service_) | 133 PrefServiceMutableDictionary(kHashOfHashesDict, pref_service_) |
151 ->SetStringWithoutPathExpansion(hash_store_id_, super_mac); | 134 ->SetStringWithoutPathExpansion(hash_store_id_, super_mac); |
152 } | 135 } |
153 | 136 |
154 void PrefServiceHashStoreContents::CommitPendingWrite() { | 137 void PrefServiceHashStoreContents::CommitPendingWrite() { |
155 pref_service_->CommitPendingWrite(); | 138 pref_service_->CommitPendingWrite(); |
156 } | 139 } |
OLD | NEW |