OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/prefs/tracked/tracked_split_preference.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/values.h" | |
11 #include "chrome/browser/prefs/pref_hash_store.h" | |
12 | |
13 TrackedSplitPreference::TrackedSplitPreference( | |
14 const std::string& pref_path, | |
15 size_t reporting_id, | |
16 size_t reporting_ids_count, | |
17 PrefHashFilter::EnforcementLevel enforcement_level, | |
18 PrefHashStore* pref_hash_store) | |
19 : pref_path_(pref_path), pref_hash_store_(pref_hash_store), | |
erikwright (departed)
2014/01/30 15:32:18
Initialize in declaration order.
gab
2014/01/30 15:57:18
Done.
| |
20 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level) { | |
21 } | |
22 | |
23 void TrackedSplitPreference::OnNewValue(const base::Value* value) const { | |
24 const base::DictionaryValue* dict_value = NULL; | |
25 if (value && !value->GetAsDictionary(&dict_value)) { | |
26 NOTREACHED(); | |
27 return; | |
28 } | |
29 pref_hash_store_->StoreSplitHash(pref_path_, dict_value); | |
30 } | |
31 | |
32 void TrackedSplitPreference::EnforceAndReport( | |
33 base::DictionaryValue* pref_store_contents) const { | |
34 base::DictionaryValue* dict_value = NULL; | |
35 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) && | |
36 pref_store_contents->Get(pref_path_, NULL)) { | |
37 // There should be a dictionary or nothing at |pref_path_|. | |
38 NOTREACHED(); | |
39 return; | |
40 } | |
41 | |
42 std::vector<std::string> invalid_keys; | |
43 PrefHashStore::ValueState value_state = | |
44 pref_hash_store_->CheckSplitValue(pref_path_, dict_value, &invalid_keys); | |
45 | |
46 if (value_state == PrefHashStore::CHANGED) | |
47 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size()); | |
48 | |
49 helper_.ReportValidationResult(value_state); | |
50 | |
51 TrackedPreferenceHelper::ResetAction reset_action = | |
52 helper_.GetAction(value_state); | |
53 helper_.ReportAction(reset_action); | |
54 | |
55 if (reset_action == TrackedPreferenceHelper::DO_RESET) { | |
56 if (value_state == PrefHashStore::CHANGED) { | |
57 DCHECK(!invalid_keys.empty()); | |
58 | |
59 for (std::vector<std::string>::const_iterator it = | |
60 invalid_keys.begin(); it != invalid_keys.end(); ++it) { | |
61 dict_value->Remove(*it, NULL); | |
62 } | |
63 } else { | |
64 pref_store_contents->RemovePath(pref_path_, NULL); | |
65 } | |
66 } | |
67 | |
68 if (value_state != PrefHashStore::UNCHANGED) { | |
69 // Store the hash for the new value (whether it was reset or not). | |
70 const base::DictionaryValue* new_dict_value = NULL; | |
71 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); | |
72 pref_hash_store_->StoreSplitHash(pref_path_, new_dict_value); | |
73 } | |
74 } | |
OLD | NEW |