| 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 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 { | 114 const base::DictionaryValue* PrefServiceHashStoreContents::GetContents() const { |
| 122 const base::DictionaryValue* pref_hash_dicts = | 115 const base::DictionaryValue* pref_hash_dicts = |
| 123 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); | 116 pref_service_->GetDictionary(prefs::kProfilePreferenceHashes); |
| 124 const base::DictionaryValue* hashes_dict = NULL; | 117 const base::DictionaryValue* hashes_dict = NULL; |
| 125 pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, | 118 pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, |
| 126 &hashes_dict); | 119 &hashes_dict); |
| 127 return hashes_dict; | 120 return hashes_dict; |
| 128 } | 121 } |
| 129 | 122 |
| 130 scoped_ptr<HashStoreContents::MutableDictionary> | 123 scoped_ptr<HashStoreContents::MutableDictionary> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 147 } | 140 } |
| 148 | 141 |
| 149 void PrefServiceHashStoreContents::SetSuperMac(const std::string& super_mac) { | 142 void PrefServiceHashStoreContents::SetSuperMac(const std::string& super_mac) { |
| 150 PrefServiceMutableDictionary(kHashOfHashesDict, pref_service_) | 143 PrefServiceMutableDictionary(kHashOfHashesDict, pref_service_) |
| 151 ->SetStringWithoutPathExpansion(hash_store_id_, super_mac); | 144 ->SetStringWithoutPathExpansion(hash_store_id_, super_mac); |
| 152 } | 145 } |
| 153 | 146 |
| 154 void PrefServiceHashStoreContents::CommitPendingWrite() { | 147 void PrefServiceHashStoreContents::CommitPendingWrite() { |
| 155 pref_service_->CommitPendingWrite(); | 148 pref_service_->CommitPendingWrite(); |
| 156 } | 149 } |
| OLD | NEW |