Chromium Code Reviews| Index: chrome/browser/prefs/pref_hash_store_impl.cc |
| diff --git a/chrome/browser/prefs/pref_hash_store_impl.cc b/chrome/browser/prefs/pref_hash_store_impl.cc |
| index 37a60241511547b6eb17df0b51244061615be814..011d1c75795bc613959c3b0c0c4e3737879f69d4 100644 |
| --- a/chrome/browser/prefs/pref_hash_store_impl.cc |
| +++ b/chrome/browser/prefs/pref_hash_store_impl.cc |
| @@ -68,3 +68,80 @@ void PrefHashStoreImpl::StoreHash( |
| child_dictionary->SetString( |
| path, pref_hash_calculator_.Calculate(path, new_value)); |
| } |
| + |
| +PrefHashStore::ValueState PrefHashStoreImpl::CheckSplitValue( |
| + const std::string& path, |
| + const base::DictionaryValue* initial_split_value, |
| + std::vector<std::string>* invalid_keys) const { |
| + DCHECK(invalid_keys && invalid_keys->empty()); |
| + |
| + bool has_hashes = HasPath(path); |
| + |
| + // Treat NULL and empty the same; otherwise we would need to store a hash |
| + // for the entire dictionary (or some other special beacon) to |
| + // differentiate these two cases which are really the same for |
| + // dictionaries. |
| + if (!initial_split_value || initial_split_value->empty()) |
| + return has_hashes ? CLEARED : UNCHANGED; |
| + |
| + if (!has_hashes) |
| + return UNKNOWN_VALUE; |
| + |
| + for (base::DictionaryValue::Iterator it(*initial_split_value); !it.IsAtEnd(); |
| + it.Advance()) { |
| + ValueState value_state = CheckValue(path + "." + it.key(), &it.value()); |
| + switch (value_state) { |
| + case CLEARED: // Falls through. |
|
erikwright (departed)
2013/12/17 02:22:50
Don't fall through, have a dedicated NOTREACHED fo
gab
2013/12/17 18:08:05
Done.
|
| + // CLEARED doesn't make sense as a NULL value would never be sampled |
| + // by the DictionaryValue::Iterator; in fact it is a known weakness of |
| + // this current algorithm to not detect the case where a single key is |
| + // cleared entirely from the dictionary pref. |
| + case MIGRATED: |
| + // Split tracked preferences were introduced after the migration started |
| + // so no migration is expected. |
| + NOTREACHED(); |
| + break; |
| + case UNCHANGED: |
| + break; |
| + case CHANGED: // Falls through. |
| + case UNKNOWN_VALUE: |
| + // Declare this value invalid, whether it was changed or never seen |
| + // before. |
| + invalid_keys->push_back(it.key()); |
| + break; |
| + } |
| + } |
| + return invalid_keys->empty() ? UNCHANGED : CHANGED; |
| +} |
| + |
| +void PrefHashStoreImpl::StoreSplitHash( |
| + const std::string& path, |
| + const base::DictionaryValue* split_value) { |
| + ClearPath(path); |
| + |
| + if (split_value) { |
| + for (base::DictionaryValue::Iterator it(*split_value); !it.IsAtEnd(); |
| + it.Advance()) { |
| + StoreHash(path + "." + it.key(), &it.value()); |
| + } |
| + } |
| +} |
| + |
| +void PrefHashStoreImpl::ClearPath(const std::string& path) { |
| + DictionaryPrefUpdate update(local_state_, prefs::kProfilePreferenceHashes); |
| + DictionaryValue* child_dictionary = NULL; |
| + |
| + if (update->GetDictionaryWithoutPathExpansion(hash_store_id_, |
| + &child_dictionary)) { |
| + child_dictionary->Remove(path, NULL); |
| + } |
| +} |
| + |
| +bool PrefHashStoreImpl::HasPath(const std::string& path) const { |
| + const base::DictionaryValue* pref_hash_dicts = |
| + local_state_->GetDictionary(prefs::kProfilePreferenceHashes); |
| + const base::DictionaryValue* hashed_prefs = NULL; |
| + pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, |
| + &hashed_prefs); |
| + return hashed_prefs && hashed_prefs->Get(path, NULL); |
| +} |