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