Chromium Code Reviews| 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.h" | 8 #include "chrome/browser/prefs/pref_hash_store.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 PrefHashStore* pref_hash_store) | 15 PrefHashStore* pref_hash_store) |
| 16 : pref_path_(pref_path), | 16 : pref_path_(pref_path), |
| 17 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level), | 17 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level), |
| 18 pref_hash_store_(pref_hash_store) { | 18 pref_hash_store_(pref_hash_store) { |
| 19 } | 19 } |
| 20 | 20 |
| 21 void TrackedAtomicPreference::OnNewValue( | 21 void TrackedAtomicPreference::OnNewValue( |
| 22 const base::Value* value) const { | 22 const base::Value* value) const { |
| 23 pref_hash_store_->StoreHash(pref_path_, value); | 23 pref_hash_store_->StoreHash(pref_path_, value); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void TrackedAtomicPreference::EnforceAndReport( | 26 bool TrackedAtomicPreference::EnforceAndReport( |
| 27 base::DictionaryValue* pref_store_contents) const { | 27 base::DictionaryValue* pref_store_contents) 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 PrefHashStore::ValueState value_state = | 30 PrefHashStore::ValueState value_state = |
| 31 pref_hash_store_->CheckValue(pref_path_, value); | 31 pref_hash_store_->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 != PrefHashStore::UNCHANGED) { | 45 if (value_state != PrefHashStore::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 pref_hash_store_->StoreHash(pref_path_, new_value); | 49 pref_hash_store_->StoreHash(pref_path_, new_value); |
| 47 } | 50 } |
| 51 | |
| 52 return was_reset; | |
|
erikwright (departed)
2014/02/06 20:04:03
why not just return action == DO_RESET
gab
2014/02/06 20:40:11
I'd argue that it's nicer to have |was_reset| beca
erikwright (departed)
2014/02/06 20:51:57
I don't mind either way.
robertshield
2014/02/07 04:36:19
Mildest of preferences for as is for the reason Ga
robertshield
2014/02/07 04:36:19
Done.
robertshield
2014/02/07 04:36:19
Done.
| |
| 48 } | 53 } |
| OLD | NEW |