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

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

Issue 266553002: Add TrackedPreferenceValidationDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: undo git cl format 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_split_preference.h" 5 #include "chrome/browser/prefs/tracked/tracked_split_preference.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/prefs/pref_hash_store_transaction.h" 11 #include "chrome/browser/prefs/pref_hash_store_transaction.h"
12 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h"
12 13
13 TrackedSplitPreference::TrackedSplitPreference( 14 TrackedSplitPreference::TrackedSplitPreference(
14 const std::string& pref_path, 15 const std::string& pref_path,
15 size_t reporting_id, 16 size_t reporting_id,
16 size_t reporting_ids_count, 17 size_t reporting_ids_count,
17 PrefHashFilter::EnforcementLevel enforcement_level) 18 PrefHashFilter::EnforcementLevel enforcement_level,
19 TrackedPreferenceValidationDelegate* delegate)
18 : pref_path_(pref_path), 20 : pref_path_(pref_path),
19 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level) { 21 helper_(pref_path, reporting_id, reporting_ids_count, enforcement_level),
22 delegate_(delegate) {
20 } 23 }
21 24
22 void TrackedSplitPreference::OnNewValue( 25 void TrackedSplitPreference::OnNewValue(
23 const base::Value* value, 26 const base::Value* value,
24 PrefHashStoreTransaction* transaction) const { 27 PrefHashStoreTransaction* transaction) const {
25 const base::DictionaryValue* dict_value = NULL; 28 const base::DictionaryValue* dict_value = NULL;
26 if (value && !value->GetAsDictionary(&dict_value)) { 29 if (value && !value->GetAsDictionary(&dict_value)) {
27 NOTREACHED(); 30 NOTREACHED();
28 return; 31 return;
29 } 32 }
(...skipping 15 matching lines...) Expand all
45 PrefHashStoreTransaction::ValueState value_state = 48 PrefHashStoreTransaction::ValueState value_state =
46 transaction->CheckSplitValue(pref_path_, dict_value, &invalid_keys); 49 transaction->CheckSplitValue(pref_path_, dict_value, &invalid_keys);
47 50
48 if (value_state == PrefHashStoreTransaction::CHANGED) 51 if (value_state == PrefHashStoreTransaction::CHANGED)
49 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size()); 52 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size());
50 53
51 helper_.ReportValidationResult(value_state); 54 helper_.ReportValidationResult(value_state);
52 55
53 TrackedPreferenceHelper::ResetAction reset_action = 56 TrackedPreferenceHelper::ResetAction reset_action =
54 helper_.GetAction(value_state); 57 helper_.GetAction(value_state);
58 if (delegate_) {
59 delegate_->OnSplitPreferenceValidation(
60 pref_path_, dict_value, invalid_keys, value_state, reset_action);
61 }
55 helper_.ReportAction(reset_action); 62 helper_.ReportAction(reset_action);
56 63
57 bool was_reset = false; 64 bool was_reset = false;
58 if (reset_action == TrackedPreferenceHelper::DO_RESET) { 65 if (reset_action == TrackedPreferenceHelper::DO_RESET) {
59 if (value_state == PrefHashStoreTransaction::CHANGED) { 66 if (value_state == PrefHashStoreTransaction::CHANGED) {
60 DCHECK(!invalid_keys.empty()); 67 DCHECK(!invalid_keys.empty());
61 68
62 for (std::vector<std::string>::const_iterator it = 69 for (std::vector<std::string>::const_iterator it =
63 invalid_keys.begin(); it != invalid_keys.end(); ++it) { 70 invalid_keys.begin(); it != invalid_keys.end(); ++it) {
64 dict_value->Remove(*it, NULL); 71 dict_value->Remove(*it, NULL);
65 } 72 }
66 } else { 73 } else {
67 pref_store_contents->RemovePath(pref_path_, NULL); 74 pref_store_contents->RemovePath(pref_path_, NULL);
68 } 75 }
69 was_reset = true; 76 was_reset = true;
70 } 77 }
71 78
72 if (value_state != PrefHashStoreTransaction::UNCHANGED) { 79 if (value_state != PrefHashStoreTransaction::UNCHANGED) {
73 // Store the hash for the new value (whether it was reset or not). 80 // Store the hash for the new value (whether it was reset or not).
74 const base::DictionaryValue* new_dict_value = NULL; 81 const base::DictionaryValue* new_dict_value = NULL;
75 pref_store_contents->GetDictionary(pref_path_, &new_dict_value); 82 pref_store_contents->GetDictionary(pref_path_, &new_dict_value);
76 transaction->StoreSplitHash(pref_path_, new_dict_value); 83 transaction->StoreSplitHash(pref_path_, new_dict_value);
77 } 84 }
78 85
79 return was_reset; 86 return was_reset;
80 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698