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 "components/user_prefs/tracked/tracked_atomic_preference.h"
7 #include "base/values.h"
8 #include "components/user_prefs/tracked/pref_hash_store_transaction.h"
9 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h"
11 TrackedAtomicPreference::TrackedAtomicPreference(
12 const std::string
& pref_path
,
14 size_t reporting_ids_count
,
15 PrefHashFilter::EnforcementLevel enforcement_level
,
16 PrefHashFilter::ValueType value_type
,
17 TrackedPreferenceValidationDelegate
* delegate
)
18 : pref_path_(pref_path
),
27 void TrackedAtomicPreference::OnNewValue(
28 const base::Value
* value
,
29 PrefHashStoreTransaction
* transaction
) const {
30 transaction
->StoreHash(pref_path_
, value
);
33 bool TrackedAtomicPreference::EnforceAndReport(
34 base::DictionaryValue
* pref_store_contents
,
35 PrefHashStoreTransaction
* transaction
) const {
36 const base::Value
* value
= NULL
;
37 pref_store_contents
->Get(pref_path_
, &value
);
38 PrefHashStoreTransaction::ValueState value_state
=
39 transaction
->CheckValue(pref_path_
, value
);
41 helper_
.ReportValidationResult(value_state
);
43 TrackedPreferenceHelper::ResetAction reset_action
=
44 helper_
.GetAction(value_state
);
46 delegate_
->OnAtomicPreferenceValidation(pref_path_
, value
, value_state
,
47 helper_
.IsPersonal());
49 helper_
.ReportAction(reset_action
);
51 bool was_reset
= false;
52 if (reset_action
== TrackedPreferenceHelper::DO_RESET
) {
53 pref_store_contents
->RemovePath(pref_path_
, NULL
);
57 if (value_state
!= PrefHashStoreTransaction::UNCHANGED
) {
58 // Store the hash for the new value (whether it was reset or not).
59 const base::Value
* new_value
= NULL
;
60 pref_store_contents
->Get(pref_path_
, &new_value
);
61 transaction
->StoreHash(pref_path_
, new_value
);