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.
5 #include "chrome/browser/prefs/tracked/tracked_atomic_preference.h"
7 #include "base/values.h"
8 #include "chrome/browser/prefs/pref_hash_store_transaction.h"
10 TrackedAtomicPreference::TrackedAtomicPreference(
11 const std::string& pref_path,
13 size_t reporting_ids_count,
14 PrefHashFilter::EnforcementLevel enforcement_level)
15 : pref_path_(pref_path),
16 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level) {
19 void TrackedAtomicPreference::OnNewValue(
20 const base::Value* value,
21 PrefHashStoreTransaction* transaction) const {
22 transaction->StoreHash(pref_path_, value);
25 bool TrackedAtomicPreference::EnforceAndReport(
26 base::DictionaryValue* pref_store_contents,
27 PrefHashStoreTransaction* transaction) const {
28 const base::Value* value = NULL;
29 pref_store_contents->Get(pref_path_, &value);
30 PrefHashStoreTransaction::ValueState value_state =
31 transaction->CheckValue(pref_path_, value);
33 helper_.ReportValidationResult(value_state);
35 TrackedPreferenceHelper::ResetAction reset_action =
36 helper_.GetAction(value_state);
37 helper_.ReportAction(reset_action);
39 bool was_reset = false;
40 if (reset_action == TrackedPreferenceHelper::DO_RESET) {
41 pref_store_contents->RemovePath(pref_path_, NULL);
45 if (value_state != PrefHashStoreTransaction::UNCHANGED) {
46 // Store the hash for the new value (whether it was reset or not).
47 const base::Value* new_value = NULL;
48 pref_store_contents->Get(pref_path_, &new_value);
49 transaction->StoreHash(pref_path_, new_value);