Add GCMChannelStatusSyncer to schedule requests and enable/disable GCM
[chromium-blink-merge.git] / chrome / browser / prefs / tracked / tracked_atomic_preference.cc
blob643b3febee000759790ca3c310b160f2ae217b23
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"
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 TrackedPreferenceValidationDelegate* delegate)
17 : pref_path_(pref_path),
18 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level),
19 delegate_(delegate) {
22 void TrackedAtomicPreference::OnNewValue(
23 const base::Value* value,
24 PrefHashStoreTransaction* transaction) const {
25 transaction->StoreHash(pref_path_, value);
28 bool TrackedAtomicPreference::EnforceAndReport(
29 base::DictionaryValue* pref_store_contents,
30 PrefHashStoreTransaction* transaction) const {
31 const base::Value* value = NULL;
32 pref_store_contents->Get(pref_path_, &value);
33 PrefHashStoreTransaction::ValueState value_state =
34 transaction->CheckValue(pref_path_, value);
36 helper_.ReportValidationResult(value_state);
38 TrackedPreferenceHelper::ResetAction reset_action =
39 helper_.GetAction(value_state);
40 if (delegate_) {
41 delegate_->OnAtomicPreferenceValidation(
42 pref_path_, value, value_state, reset_action);
44 helper_.ReportAction(reset_action);
46 bool was_reset = false;
47 if (reset_action == TrackedPreferenceHelper::DO_RESET) {
48 pref_store_contents->RemovePath(pref_path_, NULL);
49 was_reset = true;
52 if (value_state != PrefHashStoreTransaction::UNCHANGED) {
53 // Store the hash for the new value (whether it was reset or not).
54 const base::Value* new_value = NULL;
55 pref_store_contents->Get(pref_path_, &new_value);
56 transaction->StoreHash(pref_path_, new_value);
59 return was_reset;