Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / prefs / tracked / tracked_atomic_preference.cc
blob1930659f0904bbcba5973e81dcaee703b1e073d3
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/tracked/pref_hash_store_transaction.h"
9 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h"
11 TrackedAtomicPreference::TrackedAtomicPreference(
12 const std::string& pref_path,
13 size_t reporting_id,
14 size_t reporting_ids_count,
15 PrefHashFilter::EnforcementLevel enforcement_level,
16 PrefHashFilter::ValueType value_type,
17 TrackedPreferenceValidationDelegate* delegate)
18 : pref_path_(pref_path),
19 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level,
20 value_type),
21 delegate_(delegate) {
24 void TrackedAtomicPreference::OnNewValue(
25 const base::Value* value,
26 PrefHashStoreTransaction* transaction) const {
27 transaction->StoreHash(pref_path_, value);
30 bool TrackedAtomicPreference::EnforceAndReport(
31 base::DictionaryValue* pref_store_contents,
32 PrefHashStoreTransaction* transaction) const {
33 const base::Value* value = NULL;
34 pref_store_contents->Get(pref_path_, &value);
35 PrefHashStoreTransaction::ValueState value_state =
36 transaction->CheckValue(pref_path_, value);
38 helper_.ReportValidationResult(value_state);
40 TrackedPreferenceHelper::ResetAction reset_action =
41 helper_.GetAction(value_state);
42 if (delegate_) {
43 delegate_->OnAtomicPreferenceValidation(
44 pref_path_, value, value_state, helper_.IsPersonal());
46 helper_.ReportAction(reset_action);
48 bool was_reset = false;
49 if (reset_action == TrackedPreferenceHelper::DO_RESET) {
50 pref_store_contents->RemovePath(pref_path_, NULL);
51 was_reset = true;
54 if (value_state != PrefHashStoreTransaction::UNCHANGED) {
55 // Store the hash for the new value (whether it was reset or not).
56 const base::Value* new_value = NULL;
57 pref_store_contents->Get(pref_path_, &new_value);
58 transaction->StoreHash(pref_path_, new_value);
61 return was_reset;