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