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

Side by Side Diff: components/user_prefs/tracked/mock_validation_delegate.cc

Issue 2719833002: Convert TrackedPreferenceValidationDelegate into a mojo interface. (Closed)
Patch Set: Created 3 years, 9 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
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 "components/user_prefs/tracked/mock_validation_delegate.h" 5 #include "components/user_prefs/tracked/mock_validation_delegate.h"
6 6
7 MockValidationDelegate::MockValidationDelegate() { 7 MockValidationDelegateRecord::MockValidationDelegateRecord() = default;
8 }
9 8
10 MockValidationDelegate::~MockValidationDelegate() { 9 MockValidationDelegateRecord::~MockValidationDelegateRecord() = default;
11 }
12 10
13 size_t MockValidationDelegate::CountValidationsOfState( 11 size_t MockValidationDelegateRecord::CountValidationsOfState(
14 PrefHashStoreTransaction::ValueState value_state) const { 12 PrefHashStoreTransaction::ValueState value_state) const {
15 size_t count = 0; 13 size_t count = 0;
16 for (size_t i = 0; i < validations_.size(); ++i) { 14 for (size_t i = 0; i < validations_.size(); ++i) {
17 if (validations_[i].value_state == value_state) 15 if (validations_[i].value_state == value_state)
18 ++count; 16 ++count;
19 } 17 }
20 return count; 18 return count;
21 } 19 }
22 20
23 size_t MockValidationDelegate::CountExternalValidationsOfState( 21 size_t MockValidationDelegateRecord::CountExternalValidationsOfState(
24 PrefHashStoreTransaction::ValueState value_state) const { 22 PrefHashStoreTransaction::ValueState value_state) const {
25 size_t count = 0; 23 size_t count = 0;
26 for (size_t i = 0; i < validations_.size(); ++i) { 24 for (size_t i = 0; i < validations_.size(); ++i) {
27 if (validations_[i].external_validation_value_state == value_state) 25 if (validations_[i].external_validation_value_state == value_state)
28 ++count; 26 ++count;
29 } 27 }
30 return count; 28 return count;
31 } 29 }
32 30
33 const MockValidationDelegate::ValidationEvent* 31 const MockValidationDelegateRecord::ValidationEvent*
34 MockValidationDelegate::GetEventForPath(const std::string& pref_path) const { 32 MockValidationDelegateRecord::GetEventForPath(
33 const std::string& pref_path) const {
35 for (size_t i = 0; i < validations_.size(); ++i) { 34 for (size_t i = 0; i < validations_.size(); ++i) {
36 if (validations_[i].pref_path == pref_path) 35 if (validations_[i].pref_path == pref_path)
37 return &validations_[i]; 36 return &validations_[i];
38 } 37 }
39 return NULL; 38 return NULL;
40 } 39 }
41 40
42 void MockValidationDelegate::OnAtomicPreferenceValidation( 41 void MockValidationDelegateRecord::RecordValidation(
43 const std::string& pref_path,
44 const base::Value* value,
45 PrefHashStoreTransaction::ValueState value_state,
46 PrefHashStoreTransaction::ValueState external_validation_value_state,
47 bool is_personal) {
48 RecordValidation(pref_path, value_state, external_validation_value_state,
49 is_personal, PrefHashFilter::TRACKING_STRATEGY_ATOMIC);
50 }
51
52 void MockValidationDelegate::OnSplitPreferenceValidation(
53 const std::string& pref_path,
54 const base::DictionaryValue* dict_value,
55 const std::vector<std::string>& invalid_keys,
56 const std::vector<std::string>& external_validation_invalid_keys,
57 PrefHashStoreTransaction::ValueState value_state,
58 PrefHashStoreTransaction::ValueState external_validation_value_state,
59 bool is_personal) {
60 RecordValidation(pref_path, value_state, external_validation_value_state,
61 is_personal, PrefHashFilter::TRACKING_STRATEGY_SPLIT);
62 }
63
64 void MockValidationDelegate::RecordValidation(
65 const std::string& pref_path, 42 const std::string& pref_path,
66 PrefHashStoreTransaction::ValueState value_state, 43 PrefHashStoreTransaction::ValueState value_state,
67 PrefHashStoreTransaction::ValueState external_validation_value_state, 44 PrefHashStoreTransaction::ValueState external_validation_value_state,
68 bool is_personal, 45 bool is_personal,
69 PrefHashFilter::PrefTrackingStrategy strategy) { 46 PrefHashFilter::PrefTrackingStrategy strategy) {
70 validations_.push_back(ValidationEvent(pref_path, value_state, 47 validations_.push_back(ValidationEvent(pref_path, value_state,
71 external_validation_value_state, 48 external_validation_value_state,
72 is_personal, strategy)); 49 is_personal, strategy));
73 } 50 }
51
52 MockValidationDelegate::MockValidationDelegate(
53 scoped_refptr<MockValidationDelegateRecord> record)
54 : record_(std::move(record)) {}
55
56 MockValidationDelegate::~MockValidationDelegate() = default;
57
58 void MockValidationDelegate::OnAtomicPreferenceValidation(
59 const std::string& pref_path,
60 std::unique_ptr<base::Value> value,
61 PrefHashStoreTransaction::ValueState value_state,
62 PrefHashStoreTransaction::ValueState external_validation_value_state,
63 bool is_personal) {
64 record_->RecordValidation(pref_path, value_state,
65 external_validation_value_state, is_personal,
66 PrefHashFilter::TRACKING_STRATEGY_ATOMIC);
67 }
68
69 void MockValidationDelegate::OnSplitPreferenceValidation(
70 const std::string& pref_path,
71 const std::vector<std::string>& invalid_keys,
72 const std::vector<std::string>& external_validation_invalid_keys,
73 PrefHashStoreTransaction::ValueState value_state,
74 PrefHashStoreTransaction::ValueState external_validation_value_state,
75 bool is_personal) {
76 record_->RecordValidation(pref_path, value_state,
77 external_validation_value_state, is_personal,
78 PrefHashFilter::TRACKING_STRATEGY_SPLIT);
79 }
OLDNEW
« no previous file with comments | « components/user_prefs/tracked/mock_validation_delegate.h ('k') | components/user_prefs/tracked/pref_hash_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698