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/tracked_atomic_preference.h" | 5 #include "chrome/browser/prefs/tracked/tracked_atomic_preference.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/prefs/pref_hash_store_transaction.h" | 8 #include "chrome/browser/prefs/pref_hash_store_transaction.h" |
| 9 #include "chrome/browser/prefs/tracked/tracked_preference_validation_observer.h" |
9 | 10 |
10 TrackedAtomicPreference::TrackedAtomicPreference( | 11 TrackedAtomicPreference::TrackedAtomicPreference( |
11 const std::string& pref_path, | 12 const std::string& pref_path, |
12 size_t reporting_id, | 13 size_t reporting_id, |
13 size_t reporting_ids_count, | 14 size_t reporting_ids_count, |
14 PrefHashFilter::EnforcementLevel enforcement_level) | 15 PrefHashFilter::EnforcementLevel enforcement_level) |
15 : pref_path_(pref_path), | 16 : pref_path_(pref_path), |
16 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level) { | 17 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level) { |
17 } | 18 } |
18 | 19 |
19 void TrackedAtomicPreference::OnNewValue( | 20 void TrackedAtomicPreference::OnNewValue( |
20 const base::Value* value, | 21 const base::Value* value, |
21 PrefHashStoreTransaction* transaction) const { | 22 PrefHashStoreTransaction* transaction) const { |
22 transaction->StoreHash(pref_path_, value); | 23 transaction->StoreHash(pref_path_, value); |
23 } | 24 } |
24 | 25 |
25 bool TrackedAtomicPreference::EnforceAndReport( | 26 bool TrackedAtomicPreference::EnforceAndReport( |
26 base::DictionaryValue* pref_store_contents, | 27 base::DictionaryValue* pref_store_contents, |
27 PrefHashStoreTransaction* transaction) const { | 28 PrefHashStoreTransaction* transaction, |
| 29 TrackedPreferenceValidationObserver* observer) const { |
28 const base::Value* value = NULL; | 30 const base::Value* value = NULL; |
29 pref_store_contents->Get(pref_path_, &value); | 31 pref_store_contents->Get(pref_path_, &value); |
30 PrefHashStoreTransaction::ValueState value_state = | 32 PrefHashStoreTransaction::ValueState value_state = |
31 transaction->CheckValue(pref_path_, value); | 33 transaction->CheckValue(pref_path_, value); |
32 | 34 |
33 helper_.ReportValidationResult(value_state); | 35 helper_.ReportValidationResult(value_state); |
34 | 36 |
35 TrackedPreferenceHelper::ResetAction reset_action = | 37 TrackedPreferenceHelper::ResetAction reset_action = |
36 helper_.GetAction(value_state); | 38 helper_.GetAction(value_state); |
| 39 if (observer) { |
| 40 observer->OnAtomicPreferenceValidation( |
| 41 pref_path_, value, value_state, reset_action); |
| 42 } |
37 helper_.ReportAction(reset_action); | 43 helper_.ReportAction(reset_action); |
38 | 44 |
39 bool was_reset = false; | 45 bool was_reset = false; |
40 if (reset_action == TrackedPreferenceHelper::DO_RESET) { | 46 if (reset_action == TrackedPreferenceHelper::DO_RESET) { |
41 pref_store_contents->RemovePath(pref_path_, NULL); | 47 pref_store_contents->RemovePath(pref_path_, NULL); |
42 was_reset = true; | 48 was_reset = true; |
43 } | 49 } |
44 | 50 |
45 if (value_state != PrefHashStoreTransaction::UNCHANGED) { | 51 if (value_state != PrefHashStoreTransaction::UNCHANGED) { |
46 // Store the hash for the new value (whether it was reset or not). | 52 // Store the hash for the new value (whether it was reset or not). |
47 const base::Value* new_value = NULL; | 53 const base::Value* new_value = NULL; |
48 pref_store_contents->Get(pref_path_, &new_value); | 54 pref_store_contents->Get(pref_path_, &new_value); |
49 transaction->StoreHash(pref_path_, new_value); | 55 transaction->StoreHash(pref_path_, new_value); |
50 } | 56 } |
51 | 57 |
52 return was_reset; | 58 return was_reset; |
53 } | 59 } |
OLD | NEW |