OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/prefs/pref_hash_store_impl.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/prefs/pref_registry_simple.h" | |
9 #include "base/prefs/pref_service.h" | |
10 #include "base/prefs/scoped_user_pref_update.h" | |
11 #include "base/values.h" | |
12 #include "chrome/common/pref_names.h" | |
13 | |
14 PrefHashStoreImpl::PrefHashStoreImpl(const PrefHashCalculator& hash_calculator, | |
15 PrefService* local_state, | |
16 const std::string& hash_store_id) | |
17 : local_state_(local_state), | |
18 hash_store_id_(hash_store_id), | |
19 pref_hash_calculator_(hash_calculator) {} | |
20 | |
21 // static | |
22 void PrefHashStoreImpl::RegisterPrefs(PrefRegistrySimple* registry) { | |
23 // Register the top level dictionary to map profile names to dictionaries of | |
24 // tracked preferences. | |
25 registry->RegisterDictionaryPref(prefs::kProfilePreferenceHashes); | |
26 } | |
27 | |
28 PrefHashStore::ValueState PrefHashStoreImpl::CheckValue( | |
29 const std::string& path, const base::Value* initial_value) { | |
30 const base::DictionaryValue* pref_hash_dicts = | |
31 local_state_->GetDictionary(prefs::kProfilePreferenceHashes); | |
32 const base::DictionaryValue* hashed_prefs = NULL; | |
33 pref_hash_dicts->GetDictionaryWithoutPathExpansion(hash_store_id_, | |
34 &hashed_prefs); | |
35 | |
36 std::string last_hash; | |
37 if (!hashed_prefs || !hashed_prefs->GetString(path, &last_hash)) | |
38 return PrefHashStore::UNKNOWN_VALUE; | |
39 | |
40 PrefHashCalculator::ValidationResult validation_result = | |
41 pref_hash_calculator_.Validate(path, initial_value, last_hash); | |
42 switch (validation_result) { | |
43 case PrefHashCalculator::VALID: | |
44 return PrefHashStore::UNCHANGED; | |
45 case PrefHashCalculator::VALID_LEGACY: | |
46 return PrefHashStore::MIGRATED; | |
47 case PrefHashCalculator::INVALID: | |
48 return initial_value ? PrefHashStore::CHANGED : PrefHashStore::CLEARED; | |
49 default: | |
gab
2013/12/06 17:23:38
Remove the default block; you're already handling
erikwright (departed)
2013/12/06 19:00:47
It's impossible for the compiler to assert that th
gab
2013/12/06 23:22:38
We clarified this offline already, but for the sak
erikwright (departed)
2013/12/09 17:59:40
Done.
| |
50 NOTREACHED() << "Unexpected PrefHashCalculator::ValidationResult: " | |
51 << validation_result; | |
52 return PrefHashStore::UNKNOWN_VALUE; | |
53 } | |
54 } | |
55 | |
56 void PrefHashStoreImpl::StoreValue( | |
57 const std::string& path, const base::Value* new_value) { | |
58 DictionaryPrefUpdate update(local_state_, prefs::kProfilePreferenceHashes); | |
59 DictionaryValue* child_dictionary = NULL; | |
60 | |
61 // Get the dictionary corresponding to the profile name, | |
62 // which may have a '.' | |
gab
2013/12/06 17:23:38
Feels like more of this comment can fit on the fir
| |
63 if (!update->GetDictionaryWithoutPathExpansion(hash_store_id_, | |
64 &child_dictionary)) { | |
65 child_dictionary = new DictionaryValue; | |
66 update->SetWithoutPathExpansion(hash_store_id_, child_dictionary); | |
67 } | |
68 | |
69 child_dictionary->SetString( | |
70 path, pref_hash_calculator_.Calculate(path, new_value)); | |
71 } | |
OLD | NEW |