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

Side by Side Diff: services/preferences/public/cpp/tracked/mock_validation_delegate.h

Issue 2782803002: Move tracked prefs into services/preferences/tracked. (Closed)
Patch Set: rebase Created 3 years, 8 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 #ifndef COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ 5 #ifndef SERVICES_PREFERENCES_PUBLIC_CPP_TRACKED_MOCK_VALIDATION_DELEGATE_H_
6 #define COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ 6 #define SERVICES_PREFERENCES_PUBLIC_CPP_TRACKED_MOCK_VALIDATION_DELEGATE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "components/user_prefs/tracked/pref_hash_filter.h" 15 #include "services/preferences/public/interfaces/preferences_configuration.mojom .h"
16 #include "components/user_prefs/tracked/pref_hash_store_transaction.h"
17 #include "services/preferences/public/interfaces/tracked_preference_validation_d elegate.mojom.h" 16 #include "services/preferences/public/interfaces/tracked_preference_validation_d elegate.mojom.h"
18 17
19 class MockValidationDelegate; 18 class MockValidationDelegate;
20 19
21 // A mock tracked preference validation delegate for use by tests. 20 // A mock tracked preference validation delegate for use by tests.
22 class MockValidationDelegateRecord 21 class MockValidationDelegateRecord
23 : public base::RefCounted<MockValidationDelegateRecord> { 22 : public base::RefCounted<MockValidationDelegateRecord> {
24 public: 23 public:
25 struct ValidationEvent { 24 struct ValidationEvent {
26 ValidationEvent( 25 ValidationEvent(
27 const std::string& path, 26 const std::string& path,
28 PrefHashStoreTransaction::ValueState state, 27 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState state,
29 PrefHashStoreTransaction::ValueState external_validation_state, 28 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState
29 external_validation_state,
30 bool is_personal, 30 bool is_personal,
31 PrefHashFilter::PrefTrackingStrategy tracking_strategy) 31 prefs::mojom::TrackedPreferenceMetadata::PrefTrackingStrategy
32 tracking_strategy)
32 : pref_path(path), 33 : pref_path(path),
33 value_state(state), 34 value_state(state),
34 external_validation_value_state(external_validation_state), 35 external_validation_value_state(external_validation_state),
35 is_personal(is_personal), 36 is_personal(is_personal),
36 strategy(tracking_strategy) {} 37 strategy(tracking_strategy) {}
37 38
38 std::string pref_path; 39 std::string pref_path;
39 PrefHashStoreTransaction::ValueState value_state; 40 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState value_state;
40 PrefHashStoreTransaction::ValueState external_validation_value_state; 41 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState
42 external_validation_value_state;
41 bool is_personal; 43 bool is_personal;
42 PrefHashFilter::PrefTrackingStrategy strategy; 44 prefs::mojom::TrackedPreferenceMetadata::PrefTrackingStrategy strategy;
43 }; 45 };
44 46
45 MockValidationDelegateRecord(); 47 MockValidationDelegateRecord();
46 48
47 // Returns the number of recorded validations. 49 // Returns the number of recorded validations.
48 size_t recorded_validations_count() const { return validations_.size(); } 50 size_t recorded_validations_count() const { return validations_.size(); }
49 51
50 // Returns the number of validations of a given value state. 52 // Returns the number of validations of a given value state.
51 size_t CountValidationsOfState( 53 size_t CountValidationsOfState(
52 PrefHashStoreTransaction::ValueState value_state) const; 54 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState value_state)
55 const;
53 56
54 // Returns the number of external validations of a given value state. 57 // Returns the number of external validations of a given value state.
55 size_t CountExternalValidationsOfState( 58 size_t CountExternalValidationsOfState(
56 PrefHashStoreTransaction::ValueState value_state) const; 59 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState value_state)
60 const;
57 61
58 // Returns the event for the preference with a given path. 62 // Returns the event for the preference with a given path.
59 const ValidationEvent* GetEventForPath(const std::string& pref_path) const; 63 const ValidationEvent* GetEventForPath(const std::string& pref_path) const;
60 64
61 private: 65 private:
62 friend class MockValidationDelegate; 66 friend class MockValidationDelegate;
63 friend class base::RefCounted<MockValidationDelegateRecord>; 67 friend class base::RefCounted<MockValidationDelegateRecord>;
64 68
65 ~MockValidationDelegateRecord(); 69 ~MockValidationDelegateRecord();
66 70
67 // Adds a new validation event. 71 // Adds a new validation event.
68 void RecordValidation( 72 void RecordValidation(
69 const std::string& pref_path, 73 const std::string& pref_path,
70 PrefHashStoreTransaction::ValueState value_state, 74 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState value_state,
71 PrefHashStoreTransaction::ValueState external_validation_value_state, 75 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState
76 external_validation_value_state,
72 bool is_personal, 77 bool is_personal,
73 PrefHashFilter::PrefTrackingStrategy strategy); 78 prefs::mojom::TrackedPreferenceMetadata::PrefTrackingStrategy strategy);
74 79
75 std::vector<ValidationEvent> validations_; 80 std::vector<ValidationEvent> validations_;
76 81
77 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegateRecord); 82 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegateRecord);
78 }; 83 };
79 84
80 class MockValidationDelegate 85 class MockValidationDelegate
81 : public prefs::mojom::TrackedPreferenceValidationDelegate { 86 : public prefs::mojom::TrackedPreferenceValidationDelegate {
82 public: 87 public:
83 explicit MockValidationDelegate( 88 explicit MockValidationDelegate(
84 scoped_refptr<MockValidationDelegateRecord> record); 89 scoped_refptr<MockValidationDelegateRecord> record);
85 ~MockValidationDelegate() override; 90 ~MockValidationDelegate() override;
86 91
87 // TrackedPreferenceValidationDelegate implementation. 92 // TrackedPreferenceValidationDelegate implementation.
88 void OnAtomicPreferenceValidation( 93 void OnAtomicPreferenceValidation(
89 const std::string& pref_path, 94 const std::string& pref_path,
90 std::unique_ptr<base::Value> value, 95 std::unique_ptr<base::Value> value,
91 PrefHashStoreTransaction::ValueState value_state, 96 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState value_state,
92 PrefHashStoreTransaction::ValueState external_validation_value_state, 97 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState
98 external_validation_value_state,
93 bool is_personal) override; 99 bool is_personal) override;
94 void OnSplitPreferenceValidation( 100 void OnSplitPreferenceValidation(
95 const std::string& pref_path, 101 const std::string& pref_path,
96 const std::vector<std::string>& invalid_keys, 102 const std::vector<std::string>& invalid_keys,
97 const std::vector<std::string>& external_validation_invalid_keys, 103 const std::vector<std::string>& external_validation_invalid_keys,
98 PrefHashStoreTransaction::ValueState value_state, 104 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState value_state,
99 PrefHashStoreTransaction::ValueState external_validation_value_state, 105 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState
106 external_validation_value_state,
100 bool is_personal) override; 107 bool is_personal) override;
101 108
102 private: 109 private:
103 // Adds a new validation event. 110 // Adds a new validation event.
104 void RecordValidation( 111 void RecordValidation(
105 const std::string& pref_path, 112 const std::string& pref_path,
106 PrefHashStoreTransaction::ValueState value_state, 113 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState value_state,
107 PrefHashStoreTransaction::ValueState external_validation_value_state, 114 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState
115 external_validation_value_state,
108 bool is_personal, 116 bool is_personal,
109 PrefHashFilter::PrefTrackingStrategy strategy); 117 prefs::mojom::TrackedPreferenceMetadata::PrefTrackingStrategy strategy);
110 118
111 scoped_refptr<MockValidationDelegateRecord> record_; 119 scoped_refptr<MockValidationDelegateRecord> record_;
112 120
113 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate); 121 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate);
114 }; 122 };
115 123
116 #endif // COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ 124 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_TRACKED_MOCK_VALIDATION_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698