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 // TODO(erikwright): Remove in M40+. |
| 64 DictionaryPrefUpdate update(pref_service_, prefs::kProfilePreferenceHashes); |
| 65 update->RemovePath(kStoreVersionsDict, NULL); |
| 66 } |
63 | 67 |
64 // static | 68 // static |
65 void PrefServiceHashStoreContents::RegisterPrefs(PrefRegistrySimple* registry) { | 69 void PrefServiceHashStoreContents::RegisterPrefs(PrefRegistrySimple* registry) { |
66 // Register the top level dictionary to map profile names to dictionaries of | 70 // Register the top level dictionary to map profile names to dictionaries of |
67 // tracked preferences. | 71 // tracked preferences. |
68 registry->RegisterDictionaryPref(prefs::kProfilePreferenceHashes); | 72 registry->RegisterDictionaryPref(prefs::kProfilePreferenceHashes); |
69 } | 73 } |
70 | 74 |
71 // static | 75 // static |
72 void PrefServiceHashStoreContents::ResetAllPrefHashStores( | 76 void PrefServiceHashStoreContents::ResetAllPrefHashStores( |
73 PrefService* pref_service) { | 77 PrefService* pref_service) { |
74 pref_service->ClearPref(prefs::kProfilePreferenceHashes); | 78 pref_service->ClearPref(prefs::kProfilePreferenceHashes); |
75 } | 79 } |
76 | 80 |
77 std::string PrefServiceHashStoreContents::hash_store_id() const { | 81 std::string PrefServiceHashStoreContents::hash_store_id() const { |
78 return hash_store_id_; | 82 return hash_store_id_; |
79 } | 83 } |
80 | 84 |
81 void PrefServiceHashStoreContents::Reset() { | 85 void PrefServiceHashStoreContents::Reset() { |
82 DictionaryPrefUpdate update(pref_service_, prefs::kProfilePreferenceHashes); | 86 DictionaryPrefUpdate update(pref_service_, prefs::kProfilePreferenceHashes); |
83 | 87 |
84 update->RemoveWithoutPathExpansion(hash_store_id_, NULL); | 88 update->RemoveWithoutPathExpansion(hash_store_id_, NULL); |
85 | 89 |
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. | 90 // Remove this store's entry in the kHashOfHashesDict. |
92 base::DictionaryValue* hash_of_hashes_dict; | 91 base::DictionaryValue* hash_of_hashes_dict; |
93 if (update->GetDictionaryWithoutPathExpansion(kHashOfHashesDict, | 92 if (update->GetDictionaryWithoutPathExpansion(kHashOfHashesDict, |
94 &hash_of_hashes_dict)) { | 93 &hash_of_hashes_dict)) { |
95 hash_of_hashes_dict->RemoveWithoutPathExpansion(hash_store_id_, NULL); | 94 hash_of_hashes_dict->RemoveWithoutPathExpansion(hash_store_id_, NULL); |
| 95 if (hash_of_hashes_dict->empty()) |
| 96 update->RemovePath(kHashOfHashesDict, NULL); |
96 } | 97 } |
| 98 |
| 99 if (update->empty()) |
| 100 pref_service_->ClearPref(prefs::kProfilePreferenceHashes); |
97 } | 101 } |
98 | 102 |
99 bool PrefServiceHashStoreContents::IsInitialized() const { | 103 bool PrefServiceHashStoreContents::IsInitialized() const { |
100 const base::DictionaryValue* pref_hash_dicts = | 104 const base::DictionaryValue* pref_hash_dicts = |
101 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); | 105 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); |
102 return pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, | 106 return pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, |
103 NULL); | 107 NULL); |
104 } | 108 } |
105 | 109 |
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 { | 110 const base::DictionaryValue* PrefServiceHashStoreContents::GetContents() const { |
122 const base::DictionaryValue* pref_hash_dicts = | 111 const base::DictionaryValue* pref_hash_dicts = |
123 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); | 112 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); |
124 const base::DictionaryValue* hashes_dict = NULL; | 113 const base::DictionaryValue* hashes_dict = NULL; |
125 pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, | 114 pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, |
126 &hashes_dict); | 115 &hashes_dict); |
127 return hashes_dict; | 116 return hashes_dict; |
128 } | 117 } |
129 | 118 |
130 scoped_ptr<HashStoreContents::MutableDictionary> | 119 scoped_ptr<HashStoreContents::MutableDictionary> |
(...skipping 16 matching lines...) Expand all Loading... |
147 } | 136 } |
148 | 137 |
149 void PrefServiceHashStoreContents::SetSuperMac(const std::string& super_mac) { | 138 void PrefServiceHashStoreContents::SetSuperMac(const std::string& super_mac) { |
150 PrefServiceMutableDictionary(kHashOfHashesDict, pref_service_) | 139 PrefServiceMutableDictionary(kHashOfHashesDict, pref_service_) |
151 ->SetStringWithoutPathExpansion(hash_store_id_, super_mac); | 140 ->SetStringWithoutPathExpansion(hash_store_id_, super_mac); |
152 } | 141 } |
153 | 142 |
154 void PrefServiceHashStoreContents::CommitPendingWrite() { | 143 void PrefServiceHashStoreContents::CommitPendingWrite() { |
155 pref_service_->CommitPendingWrite(); | 144 pref_service_->CommitPendingWrite(); |
156 } | 145 } |
OLD | NEW |