Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Side by Side Diff: chrome/browser/prefs/tracked/tracked_atomic_preference.cc

Issue 1227973003: Componentize //chrome/browser/prefs/tracked. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/prefs/tracked/tracked_atomic_preference.h"
6
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"
10
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) {
22 }
23
24 void TrackedAtomicPreference::OnNewValue(
25 const base::Value* value,
26 PrefHashStoreTransaction* transaction) const {
27 transaction->StoreHash(pref_path_, value);
28 }
29
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);
37
38 helper_.ReportValidationResult(value_state);
39
40 TrackedPreferenceHelper::ResetAction reset_action =
41 helper_.GetAction(value_state);
42 if (delegate_) {
43 delegate_->OnAtomicPreferenceValidation(
44 pref_path_, value, value_state, helper_.IsPersonal());
45 }
46 helper_.ReportAction(reset_action);
47
48 bool was_reset = false;
49 if (reset_action == TrackedPreferenceHelper::DO_RESET) {
50 pref_store_contents->RemovePath(pref_path_, NULL);
51 was_reset = true;
52 }
53
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);
59 }
60
61 return was_reset;
62 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/tracked/tracked_atomic_preference.h ('k') | chrome/browser/prefs/tracked/tracked_preference.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698