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