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

Side by Side Diff: components/prefs/testing_pref_service.h

Issue 2479113002: Make extensions DSE persistent in browser prefs (Closed)
Patch Set: Fixed after review, round 7 Created 3 years, 12 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_PREFS_TESTING_PREF_SERVICE_H_ 5 #ifndef COMPONENTS_PREFS_TESTING_PREF_SERVICE_H_
6 #define COMPONENTS_PREFS_TESTING_PREF_SERVICE_H_ 6 #define COMPONENTS_PREFS_TESTING_PREF_SERVICE_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 22 matching lines...) Expand all
33 const base::Value* GetManagedPref(const std::string& path) const; 33 const base::Value* GetManagedPref(const std::string& path) const;
34 34
35 // Set a preference on the managed layer and fire observers if the preference 35 // Set a preference on the managed layer and fire observers if the preference
36 // changed. Assumes ownership of |value|. 36 // changed. Assumes ownership of |value|.
37 void SetManagedPref(const std::string& path, base::Value* value); 37 void SetManagedPref(const std::string& path, base::Value* value);
38 38
39 // Clear the preference on the managed layer and fire observers if the 39 // Clear the preference on the managed layer and fire observers if the
40 // preference has been defined previously. 40 // preference has been defined previously.
41 void RemoveManagedPref(const std::string& path); 41 void RemoveManagedPref(const std::string& path);
42 42
43 // Similar to the above, but for extension preferences.
44 // Does not really know about extensions and their order of installation.
45 // Useful in tests that only checks that preference is overriden by extension.
Peter Kasting 2017/01/06 01:44:57 Nit: "...only check that a preference is overridde
Alexander Yashkin 2017/01/07 12:55:59 Done, thanks.
46 const base::Value* GetExtensionPref(const std::string& path) const;
47 void SetExtensionPref(const std::string& path, base::Value* value);
48 void RemoveExtensionPref(const std::string& path);
49
43 // Similar to the above, but for user preferences. 50 // Similar to the above, but for user preferences.
44 const base::Value* GetUserPref(const std::string& path) const; 51 const base::Value* GetUserPref(const std::string& path) const;
45 void SetUserPref(const std::string& path, base::Value* value); 52 void SetUserPref(const std::string& path, base::Value* value);
46 void RemoveUserPref(const std::string& path); 53 void RemoveUserPref(const std::string& path);
47 54
48 // Similar to the above, but for recommended policy preferences. 55 // Similar to the above, but for recommended policy preferences.
49 const base::Value* GetRecommendedPref(const std::string& path) const; 56 const base::Value* GetRecommendedPref(const std::string& path) const;
50 void SetRecommendedPref(const std::string& path, base::Value* value); 57 void SetRecommendedPref(const std::string& path, base::Value* value);
51 void RemoveRecommendedPref(const std::string& path); 58 void RemoveRecommendedPref(const std::string& path);
52 59
53 // Do-nothing implementation for TestingPrefService. 60 // Do-nothing implementation for TestingPrefService.
54 static void HandleReadError(PersistentPrefStore::PrefReadError error) {} 61 static void HandleReadError(PersistentPrefStore::PrefReadError error) {}
55 62
56 protected: 63 protected:
57 TestingPrefServiceBase( 64 TestingPrefServiceBase(TestingPrefStore* managed_prefs,
58 TestingPrefStore* managed_prefs, 65 TestingPrefStore* extension_prefs,
59 TestingPrefStore* user_prefs, 66 TestingPrefStore* user_prefs,
60 TestingPrefStore* recommended_prefs, 67 TestingPrefStore* recommended_prefs,
61 ConstructionPrefRegistry* pref_registry, 68 ConstructionPrefRegistry* pref_registry,
62 PrefNotifierImpl* pref_notifier); 69 PrefNotifierImpl* pref_notifier);
63 70
64 private: 71 private:
65 // Reads the value of the preference indicated by |path| from |pref_store|. 72 // Reads the value of the preference indicated by |path| from |pref_store|.
66 // Returns NULL if the preference was not found. 73 // Returns NULL if the preference was not found.
67 const base::Value* GetPref(TestingPrefStore* pref_store, 74 const base::Value* GetPref(TestingPrefStore* pref_store,
68 const std::string& path) const; 75 const std::string& path) const;
69 76
70 // Sets the value for |path| in |pref_store|. 77 // Sets the value for |path| in |pref_store|.
71 void SetPref(TestingPrefStore* pref_store, 78 void SetPref(TestingPrefStore* pref_store,
72 const std::string& path, 79 const std::string& path,
73 base::Value* value); 80 base::Value* value);
74 81
75 // Removes the preference identified by |path| from |pref_store|. 82 // Removes the preference identified by |path| from |pref_store|.
76 void RemovePref(TestingPrefStore* pref_store, const std::string& path); 83 void RemovePref(TestingPrefStore* pref_store, const std::string& path);
77 84
78 // Pointers to the pref stores our value store uses. 85 // Pointers to the pref stores our value store uses.
79 scoped_refptr<TestingPrefStore> managed_prefs_; 86 scoped_refptr<TestingPrefStore> managed_prefs_;
87 scoped_refptr<TestingPrefStore> extension_prefs_;
80 scoped_refptr<TestingPrefStore> user_prefs_; 88 scoped_refptr<TestingPrefStore> user_prefs_;
81 scoped_refptr<TestingPrefStore> recommended_prefs_; 89 scoped_refptr<TestingPrefStore> recommended_prefs_;
82 90
83 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceBase); 91 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceBase);
84 }; 92 };
85 93
86 // Test version of PrefService. 94 // Test version of PrefService.
87 class TestingPrefServiceSimple 95 class TestingPrefServiceSimple
88 : public TestingPrefServiceBase<PrefService, PrefRegistry> { 96 : public TestingPrefServiceBase<PrefService, PrefRegistry> {
89 public: 97 public:
90 TestingPrefServiceSimple(); 98 TestingPrefServiceSimple();
91 ~TestingPrefServiceSimple() override; 99 ~TestingPrefServiceSimple() override;
92 100
93 // This is provided as a convenience for registering preferences on 101 // This is provided as a convenience for registering preferences on
94 // an existing TestingPrefServiceSimple instance. On a production 102 // an existing TestingPrefServiceSimple instance. On a production
95 // PrefService you would do all registrations before constructing 103 // PrefService you would do all registrations before constructing
96 // it, passing it a PrefRegistry via its constructor (or via 104 // it, passing it a PrefRegistry via its constructor (or via
97 // e.g. PrefServiceFactory). 105 // e.g. PrefServiceFactory).
98 PrefRegistrySimple* registry(); 106 PrefRegistrySimple* registry();
99 107
100 private: 108 private:
101 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSimple); 109 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSimple);
102 }; 110 };
103 111
104 template<> 112 template<>
105 TestingPrefServiceBase<PrefService, PrefRegistry>::TestingPrefServiceBase( 113 TestingPrefServiceBase<PrefService, PrefRegistry>::TestingPrefServiceBase(
106 TestingPrefStore* managed_prefs, 114 TestingPrefStore* managed_prefs,
115 TestingPrefStore* extension_prefs,
107 TestingPrefStore* user_prefs, 116 TestingPrefStore* user_prefs,
108 TestingPrefStore* recommended_prefs, 117 TestingPrefStore* recommended_prefs,
109 PrefRegistry* pref_registry, 118 PrefRegistry* pref_registry,
110 PrefNotifierImpl* pref_notifier); 119 PrefNotifierImpl* pref_notifier);
111 120
112 template<class SuperPrefService, class ConstructionPrefRegistry> 121 template<class SuperPrefService, class ConstructionPrefRegistry>
113 TestingPrefServiceBase< 122 TestingPrefServiceBase<
114 SuperPrefService, ConstructionPrefRegistry>::~TestingPrefServiceBase() { 123 SuperPrefService, ConstructionPrefRegistry>::~TestingPrefServiceBase() {
115 } 124 }
116 125
(...skipping 10 matching lines...) Expand all
127 SetPref(managed_prefs_.get(), path, value); 136 SetPref(managed_prefs_.get(), path, value);
128 } 137 }
129 138
130 template <class SuperPrefService, class ConstructionPrefRegistry> 139 template <class SuperPrefService, class ConstructionPrefRegistry>
131 void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>:: 140 void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
132 RemoveManagedPref(const std::string& path) { 141 RemoveManagedPref(const std::string& path) {
133 RemovePref(managed_prefs_.get(), path); 142 RemovePref(managed_prefs_.get(), path);
134 } 143 }
135 144
136 template <class SuperPrefService, class ConstructionPrefRegistry> 145 template <class SuperPrefService, class ConstructionPrefRegistry>
146 const base::Value* TestingPrefServiceBase<
147 SuperPrefService,
148 ConstructionPrefRegistry>::GetExtensionPref(const std::string& path) const {
149 return GetPref(extension_prefs_.get(), path);
150 }
151
152 template <class SuperPrefService, class ConstructionPrefRegistry>
153 void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
154 SetExtensionPref(const std::string& path, base::Value* value) {
155 SetPref(extension_prefs_.get(), path, value);
156 }
157
158 template <class SuperPrefService, class ConstructionPrefRegistry>
159 void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
160 RemoveExtensionPref(const std::string& path) {
161 RemovePref(extension_prefs_.get(), path);
162 }
163
164 template <class SuperPrefService, class ConstructionPrefRegistry>
137 const base::Value* 165 const base::Value*
138 TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::GetUserPref( 166 TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::GetUserPref(
139 const std::string& path) const { 167 const std::string& path) const {
140 return GetPref(user_prefs_.get(), path); 168 return GetPref(user_prefs_.get(), path);
141 } 169 }
142 170
143 template <class SuperPrefService, class ConstructionPrefRegistry> 171 template <class SuperPrefService, class ConstructionPrefRegistry>
144 void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>:: 172 void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
145 SetUserPref(const std::string& path, base::Value* value) { 173 SetUserPref(const std::string& path, base::Value* value) {
146 SetPref(user_prefs_.get(), path, value); 174 SetPref(user_prefs_.get(), path, value);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 217 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
190 } 218 }
191 219
192 template <class SuperPrefService, class ConstructionPrefRegistry> 220 template <class SuperPrefService, class ConstructionPrefRegistry>
193 void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>:: 221 void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
194 RemovePref(TestingPrefStore* pref_store, const std::string& path) { 222 RemovePref(TestingPrefStore* pref_store, const std::string& path) {
195 pref_store->RemoveValue(path, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 223 pref_store->RemoveValue(path, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
196 } 224 }
197 225
198 #endif // COMPONENTS_PREFS_TESTING_PREF_SERVICE_H_ 226 #endif // COMPONENTS_PREFS_TESTING_PREF_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698