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 "components/user_prefs/tracked/tracked_split_preference.h" | 5 #include "components/user_prefs/tracked/tracked_split_preference.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 const base::DictionaryValue* dict_value = NULL; | 33 const base::DictionaryValue* dict_value = NULL; |
34 if (value && !value->GetAsDictionary(&dict_value)) { | 34 if (value && !value->GetAsDictionary(&dict_value)) { |
35 NOTREACHED(); | 35 NOTREACHED(); |
36 return; | 36 return; |
37 } | 37 } |
38 transaction->StoreSplitHash(pref_path_, dict_value); | 38 transaction->StoreSplitHash(pref_path_, dict_value); |
39 } | 39 } |
40 | 40 |
41 bool TrackedSplitPreference::EnforceAndReport( | 41 bool TrackedSplitPreference::EnforceAndReport( |
42 base::DictionaryValue* pref_store_contents, | 42 base::DictionaryValue* pref_store_contents, |
43 PrefHashStoreTransaction* transaction) const { | 43 PrefHashStoreTransaction* transaction, |
44 PrefHashStoreTransaction* registry_transaction) const { | |
44 base::DictionaryValue* dict_value = NULL; | 45 base::DictionaryValue* dict_value = NULL; |
45 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) && | 46 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) && |
46 pref_store_contents->Get(pref_path_, NULL)) { | 47 pref_store_contents->Get(pref_path_, NULL)) { |
47 // There should be a dictionary or nothing at |pref_path_|. | 48 // There should be a dictionary or nothing at |pref_path_|. |
48 NOTREACHED(); | 49 NOTREACHED(); |
49 return false; | 50 return false; |
50 } | 51 } |
51 | 52 |
52 std::vector<std::string> invalid_keys; | 53 std::vector<std::string> invalid_keys; |
53 PrefHashStoreTransaction::ValueState value_state = | 54 PrefHashStoreTransaction::ValueState value_state = |
54 transaction->CheckSplitValue(pref_path_, dict_value, &invalid_keys); | 55 transaction->CheckSplitValue(pref_path_, dict_value, &invalid_keys); |
55 | 56 |
56 if (value_state == PrefHashStoreTransaction::CHANGED) | 57 if (value_state == PrefHashStoreTransaction::CHANGED) |
57 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size()); | 58 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size()); |
58 | 59 |
59 helper_.ReportValidationResult(value_state); | 60 helper_.ReportValidationResult(value_state, transaction->GetStoreType()); |
60 | 61 |
61 TrackedPreferenceHelper::ResetAction reset_action = | 62 PrefHashStoreTransaction::ValueState registry_value_state = |
62 helper_.GetAction(value_state); | 63 PrefHashStoreTransaction::UNCHANGED; |
64 if (registry_transaction) { | |
65 std::vector<std::string> invalid_registry_keys; | |
66 registry_value_state = registry_transaction->CheckSplitValue( | |
67 pref_path_, dict_value, &invalid_registry_keys); | |
68 helper_.ReportValidationResult(registry_value_state, | |
69 registry_transaction->GetStoreType()); | |
70 | |
71 // TODO(proberge): Call delegate_->OnSplitPreferenceValidation. | |
72 } | |
73 | |
63 if (delegate_) { | 74 if (delegate_) { |
64 delegate_->OnSplitPreferenceValidation(pref_path_, dict_value, invalid_keys, | 75 delegate_->OnSplitPreferenceValidation(pref_path_, dict_value, invalid_keys, |
65 value_state, helper_.IsPersonal()); | 76 value_state, helper_.IsPersonal()); |
66 } | 77 } |
78 TrackedPreferenceHelper::ResetAction reset_action = | |
79 helper_.GetAction(value_state); | |
67 helper_.ReportAction(reset_action); | 80 helper_.ReportAction(reset_action); |
68 | 81 |
69 bool was_reset = false; | 82 bool was_reset = false; |
70 if (reset_action == TrackedPreferenceHelper::DO_RESET) { | 83 if (reset_action == TrackedPreferenceHelper::DO_RESET) { |
71 if (value_state == PrefHashStoreTransaction::CHANGED) { | 84 if (value_state == PrefHashStoreTransaction::CHANGED) { |
72 DCHECK(!invalid_keys.empty()); | 85 DCHECK(!invalid_keys.empty()); |
73 | 86 |
74 for (std::vector<std::string>::const_iterator it = invalid_keys.begin(); | 87 for (std::vector<std::string>::const_iterator it = invalid_keys.begin(); |
75 it != invalid_keys.end(); ++it) { | 88 it != invalid_keys.end(); ++it) { |
76 dict_value->Remove(*it, NULL); | 89 dict_value->Remove(*it, NULL); |
77 } | 90 } |
78 } else { | 91 } else { |
79 pref_store_contents->RemovePath(pref_path_, NULL); | 92 pref_store_contents->RemovePath(pref_path_, NULL); |
80 } | 93 } |
81 was_reset = true; | 94 was_reset = true; |
82 } | 95 } |
83 | 96 |
84 if (value_state != PrefHashStoreTransaction::UNCHANGED) { | 97 if (value_state != PrefHashStoreTransaction::UNCHANGED) { |
85 // Store the hash for the new value (whether it was reset or not). | 98 // Store the hash for the new value (whether it was reset or not). |
86 const base::DictionaryValue* new_dict_value = NULL; | 99 const base::DictionaryValue* new_dict_value = NULL; |
87 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); | 100 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); |
88 transaction->StoreSplitHash(pref_path_, new_dict_value); | 101 transaction->StoreSplitHash(pref_path_, new_dict_value); |
89 } | 102 } |
90 | 103 |
104 if (registry_transaction && | |
105 (value_state != PrefHashStoreTransaction::UNCHANGED || | |
gab
2016/08/03 18:19:36
ditto: |was_reset|
proberge
2016/08/04 00:13:47
Done.
| |
106 registry_value_state != PrefHashStoreTransaction::UNCHANGED)) { | |
107 const base::DictionaryValue* new_dict_value = NULL; | |
108 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); | |
109 transaction->StoreSplitHash(pref_path_, new_dict_value); | |
110 } | |
111 | |
91 return was_reset; | 112 return was_reset; |
92 } | 113 } |
OLD | NEW |