| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 return hash_store_id_; | 78 return hash_store_id_; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void PrefServiceHashStoreContents::Reset() { | 81 void PrefServiceHashStoreContents::Reset() { |
| 82 DictionaryPrefUpdate update(pref_service_, prefs::kProfilePreferenceHashes); | 82 DictionaryPrefUpdate update(pref_service_, prefs::kProfilePreferenceHashes); |
| 83 | 83 |
| 84 update->RemoveWithoutPathExpansion(hash_store_id_, NULL); | 84 update->RemoveWithoutPathExpansion(hash_store_id_, NULL); |
| 85 | 85 |
| 86 // Remove this store's entry in the kStoreVersionsDict. | 86 // Remove this store's entry in the kStoreVersionsDict. |
| 87 base::DictionaryValue* version_dict; | 87 base::DictionaryValue* version_dict; |
| 88 if (update->GetDictionary(kStoreVersionsDict, &version_dict)) | 88 if (update->GetDictionary(kStoreVersionsDict, &version_dict)) { |
| 89 version_dict->RemoveWithoutPathExpansion(hash_store_id_, NULL); | 89 version_dict->RemoveWithoutPathExpansion(hash_store_id_, NULL); |
| 90 if (version_dict->empty()) |
| 91 update->RemovePath(kStoreVersionsDict, NULL); |
| 92 } |
| 90 | 93 |
| 91 // Remove this store's entry in the kHashOfHashesDict. | 94 // Remove this store's entry in the kHashOfHashesDict. |
| 92 base::DictionaryValue* hash_of_hashes_dict; | 95 base::DictionaryValue* hash_of_hashes_dict; |
| 93 if (update->GetDictionaryWithoutPathExpansion(kHashOfHashesDict, | 96 if (update->GetDictionaryWithoutPathExpansion(kHashOfHashesDict, |
| 94 &hash_of_hashes_dict)) { | 97 &hash_of_hashes_dict)) { |
| 95 hash_of_hashes_dict->RemoveWithoutPathExpansion(hash_store_id_, NULL); | 98 hash_of_hashes_dict->RemoveWithoutPathExpansion(hash_store_id_, NULL); |
| 99 if (hash_of_hashes_dict->empty()) |
| 100 update->RemovePath(kHashOfHashesDict, NULL); |
| 96 } | 101 } |
| 102 |
| 103 if (update->empty()) |
| 104 pref_service_->ClearPref(prefs::kProfilePreferenceHashes); |
| 97 } | 105 } |
| 98 | 106 |
| 99 bool PrefServiceHashStoreContents::IsInitialized() const { | 107 bool PrefServiceHashStoreContents::IsInitialized() const { |
| 100 const base::DictionaryValue* pref_hash_dicts = | 108 const base::DictionaryValue* pref_hash_dicts = |
| 101 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); | 109 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); |
| 102 return pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, | 110 return pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, |
| 103 NULL); | 111 NULL); |
| 104 } | 112 } |
| 105 | 113 |
| 106 const base::DictionaryValue* PrefServiceHashStoreContents::GetContents() const { | 114 const base::DictionaryValue* PrefServiceHashStoreContents::GetContents() const { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 132 } | 140 } |
| 133 | 141 |
| 134 void PrefServiceHashStoreContents::SetSuperMac(const std::string& super_mac) { | 142 void PrefServiceHashStoreContents::SetSuperMac(const std::string& super_mac) { |
| 135 PrefServiceMutableDictionary(kHashOfHashesDict, pref_service_) | 143 PrefServiceMutableDictionary(kHashOfHashesDict, pref_service_) |
| 136 ->SetStringWithoutPathExpansion(hash_store_id_, super_mac); | 144 ->SetStringWithoutPathExpansion(hash_store_id_, super_mac); |
| 137 } | 145 } |
| 138 | 146 |
| 139 void PrefServiceHashStoreContents::CommitPendingWrite() { | 147 void PrefServiceHashStoreContents::CommitPendingWrite() { |
| 140 pref_service_->CommitPendingWrite(); | 148 pref_service_->CommitPendingWrite(); |
| 141 } | 149 } |
| OLD | NEW |