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

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

Issue 266553002: Add TrackedPreferenceValidationDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fix Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/prefs/tracked/tracked_atomic_preference.h" 5 #include "chrome/browser/prefs/tracked/tracked_atomic_preference.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/prefs/pref_hash_store_transaction.h" 8 #include "chrome/browser/prefs/pref_hash_store_transaction.h"
9 #include "chrome/browser/prefs/tracked/tracked_preference_validation_observer.h"
9 10
10 TrackedAtomicPreference::TrackedAtomicPreference( 11 TrackedAtomicPreference::TrackedAtomicPreference(
11 const std::string& pref_path, 12 const std::string& pref_path,
12 size_t reporting_id, 13 size_t reporting_id,
13 size_t reporting_ids_count, 14 size_t reporting_ids_count,
14 PrefHashFilter::EnforcementLevel enforcement_level) 15 PrefHashFilter::EnforcementLevel enforcement_level,
16 TrackedPreferenceValidationObserver* observer)
15 : pref_path_(pref_path), 17 : pref_path_(pref_path),
16 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level) { 18 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level),
19 observer_(observer) {
17 } 20 }
18 21
19 void TrackedAtomicPreference::OnNewValue( 22 void TrackedAtomicPreference::OnNewValue(
20 const base::Value* value, 23 const base::Value* value,
21 PrefHashStoreTransaction* transaction) const { 24 PrefHashStoreTransaction* transaction) const {
22 transaction->StoreHash(pref_path_, value); 25 transaction->StoreHash(pref_path_, value);
23 } 26 }
24 27
25 bool TrackedAtomicPreference::EnforceAndReport( 28 bool TrackedAtomicPreference::EnforceAndReport(
26 base::DictionaryValue* pref_store_contents, 29 base::DictionaryValue* pref_store_contents,
27 PrefHashStoreTransaction* transaction) const { 30 PrefHashStoreTransaction* transaction) const {
28 const base::Value* value = NULL; 31 const base::Value* value = NULL;
29 pref_store_contents->Get(pref_path_, &value); 32 pref_store_contents->Get(pref_path_, &value);
30 PrefHashStoreTransaction::ValueState value_state = 33 PrefHashStoreTransaction::ValueState value_state =
31 transaction->CheckValue(pref_path_, value); 34 transaction->CheckValue(pref_path_, value);
32 35
33 helper_.ReportValidationResult(value_state); 36 helper_.ReportValidationResult(value_state);
34 37
35 TrackedPreferenceHelper::ResetAction reset_action = 38 TrackedPreferenceHelper::ResetAction reset_action =
36 helper_.GetAction(value_state); 39 helper_.GetAction(value_state);
40 if (observer_) {
41 observer_->OnAtomicPreferenceValidation(
42 pref_path_, value, value_state, reset_action);
43 }
37 helper_.ReportAction(reset_action); 44 helper_.ReportAction(reset_action);
38 45
39 bool was_reset = false; 46 bool was_reset = false;
40 if (reset_action == TrackedPreferenceHelper::DO_RESET) { 47 if (reset_action == TrackedPreferenceHelper::DO_RESET) {
41 pref_store_contents->RemovePath(pref_path_, NULL); 48 pref_store_contents->RemovePath(pref_path_, NULL);
42 was_reset = true; 49 was_reset = true;
43 } 50 }
44 51
45 if (value_state != PrefHashStoreTransaction::UNCHANGED) { 52 if (value_state != PrefHashStoreTransaction::UNCHANGED) {
46 // Store the hash for the new value (whether it was reset or not). 53 // Store the hash for the new value (whether it was reset or not).
47 const base::Value* new_value = NULL; 54 const base::Value* new_value = NULL;
48 pref_store_contents->Get(pref_path_, &new_value); 55 pref_store_contents->Get(pref_path_, &new_value);
49 transaction->StoreHash(pref_path_, new_value); 56 transaction->StoreHash(pref_path_, new_value);
50 } 57 }
51 58
52 return was_reset; 59 return was_reset;
53 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698