OLD | NEW |
| (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 "components/user_prefs/tracked/mock_validation_delegate.h" | |
6 | |
7 MockValidationDelegateRecord::MockValidationDelegateRecord() = default; | |
8 | |
9 MockValidationDelegateRecord::~MockValidationDelegateRecord() = default; | |
10 | |
11 size_t MockValidationDelegateRecord::CountValidationsOfState( | |
12 PrefHashStoreTransaction::ValueState value_state) const { | |
13 size_t count = 0; | |
14 for (size_t i = 0; i < validations_.size(); ++i) { | |
15 if (validations_[i].value_state == value_state) | |
16 ++count; | |
17 } | |
18 return count; | |
19 } | |
20 | |
21 size_t MockValidationDelegateRecord::CountExternalValidationsOfState( | |
22 PrefHashStoreTransaction::ValueState value_state) const { | |
23 size_t count = 0; | |
24 for (size_t i = 0; i < validations_.size(); ++i) { | |
25 if (validations_[i].external_validation_value_state == value_state) | |
26 ++count; | |
27 } | |
28 return count; | |
29 } | |
30 | |
31 const MockValidationDelegateRecord::ValidationEvent* | |
32 MockValidationDelegateRecord::GetEventForPath( | |
33 const std::string& pref_path) const { | |
34 for (size_t i = 0; i < validations_.size(); ++i) { | |
35 if (validations_[i].pref_path == pref_path) | |
36 return &validations_[i]; | |
37 } | |
38 return NULL; | |
39 } | |
40 | |
41 void MockValidationDelegateRecord::RecordValidation( | |
42 const std::string& pref_path, | |
43 PrefHashStoreTransaction::ValueState value_state, | |
44 PrefHashStoreTransaction::ValueState external_validation_value_state, | |
45 bool is_personal, | |
46 PrefHashFilter::PrefTrackingStrategy strategy) { | |
47 validations_.push_back(ValidationEvent(pref_path, value_state, | |
48 external_validation_value_state, | |
49 is_personal, strategy)); | |
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::PrefTrackingStrategy::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::PrefTrackingStrategy::SPLIT); | |
79 } | |
OLD | NEW |