Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ | 5 #ifndef CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ |
| 6 #define CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ | 6 #define CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/prefs/testing_pref_store.h" | 10 #include "base/prefs/testing_pref_store.h" |
| 11 #include "chrome/browser/prefs/pref_registry.h" | |
| 10 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 11 | 13 |
| 12 class DefaultPrefStore; | |
| 13 class PrefModelAssociator; | 14 class PrefModelAssociator; |
| 14 class PrefNotifierImpl; | 15 class PrefNotifierImpl; |
| 16 class PrefRegistrySimple; | |
| 15 class TestingBrowserProcess; | 17 class TestingBrowserProcess; |
| 16 class TestingPrefStore; | 18 class TestingPrefStore; |
| 17 | 19 |
| 18 // A PrefService subclass for testing. It operates totally in memory and | 20 // A PrefService subclass for testing. It operates totally in memory and |
| 19 // provides additional API for manipulating preferences at the different levels | 21 // provides additional API for manipulating preferences at the different levels |
| 20 // (managed, extension, user) conveniently. | 22 // (managed, extension, user) conveniently. |
| 21 // | 23 // |
| 22 // Use this via its specializations, TestingPrefServiceSimple and | 24 // Use this via its specializations, TestingPrefServiceSimple and |
| 23 // TestingPrefServiceSyncable. | 25 // TestingPrefServiceSyncable. |
| 24 template <class SuperPrefService> | 26 template <class SuperPrefService> |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 46 // Similar to the above, but for recommended policy preferences. | 48 // Similar to the above, but for recommended policy preferences. |
| 47 const Value* GetRecommendedPref(const char* path) const; | 49 const Value* GetRecommendedPref(const char* path) const; |
| 48 void SetRecommendedPref(const char* path, Value* value); | 50 void SetRecommendedPref(const char* path, Value* value); |
| 49 void RemoveRecommendedPref(const char* path); | 51 void RemoveRecommendedPref(const char* path); |
| 50 | 52 |
| 51 protected: | 53 protected: |
| 52 TestingPrefServiceBase( | 54 TestingPrefServiceBase( |
| 53 TestingPrefStore* managed_prefs, | 55 TestingPrefStore* managed_prefs, |
| 54 TestingPrefStore* user_prefs, | 56 TestingPrefStore* user_prefs, |
| 55 TestingPrefStore* recommended_prefs, | 57 TestingPrefStore* recommended_prefs, |
| 56 DefaultPrefStore* default_store, | 58 PrefRegistry* pref_registry, |
| 57 PrefNotifierImpl* pref_notifier); | 59 PrefNotifierImpl* pref_notifier); |
| 58 | 60 |
| 59 private: | 61 private: |
| 60 // Reads the value of the preference indicated by |path| from |pref_store|. | 62 // Reads the value of the preference indicated by |path| from |pref_store|. |
| 61 // Returns NULL if the preference was not found. | 63 // Returns NULL if the preference was not found. |
| 62 const Value* GetPref(TestingPrefStore* pref_store, const char* path) const; | 64 const Value* GetPref(TestingPrefStore* pref_store, const char* path) const; |
| 63 | 65 |
| 64 // Sets the value for |path| in |pref_store|. | 66 // Sets the value for |path| in |pref_store|. |
| 65 void SetPref(TestingPrefStore* pref_store, const char* path, Value* value); | 67 void SetPref(TestingPrefStore* pref_store, const char* path, Value* value); |
| 66 | 68 |
| 67 // Removes the preference identified by |path| from |pref_store|. | 69 // Removes the preference identified by |path| from |pref_store|. |
| 68 void RemovePref(TestingPrefStore* pref_store, const char* path); | 70 void RemovePref(TestingPrefStore* pref_store, const char* path); |
| 69 | 71 |
| 70 // Pointers to the pref stores our value store uses. | 72 // Pointers to the pref stores our value store uses. |
| 71 scoped_refptr<TestingPrefStore> managed_prefs_; | 73 scoped_refptr<TestingPrefStore> managed_prefs_; |
| 72 scoped_refptr<TestingPrefStore> user_prefs_; | 74 scoped_refptr<TestingPrefStore> user_prefs_; |
| 73 scoped_refptr<TestingPrefStore> recommended_prefs_; | 75 scoped_refptr<TestingPrefStore> recommended_prefs_; |
| 74 | 76 |
| 75 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceBase); | 77 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceBase); |
| 76 }; | 78 }; |
| 77 | 79 |
| 78 // Test version of PrefServiceSimple. | 80 // Test version of PrefService. |
| 79 class TestingPrefServiceSimple | 81 class TestingPrefServiceSimple |
| 80 : public TestingPrefServiceBase<PrefServiceSimple> { | 82 : public TestingPrefServiceBase<PrefService> { |
| 81 public: | 83 public: |
| 82 TestingPrefServiceSimple(); | 84 TestingPrefServiceSimple(); |
| 83 virtual ~TestingPrefServiceSimple(); | 85 virtual ~TestingPrefServiceSimple(); |
| 84 | 86 |
| 87 // This is provided as a convenience; on a production PrefService | |
|
Mattias Nissler (ping if slow)
2013/01/31 14:50:45
maybe elaborate: "as a convenience for registering
Jói
2013/01/31 16:23:37
Done.
| |
| 88 // you would do all registrations before constructing it, passing it | |
| 89 // a PrefRegistry via its constructor (or via | |
| 90 // e.g. PrefServiceBuilder). | |
| 91 PrefRegistrySimple* registry(); | |
| 92 | |
| 85 private: | 93 private: |
| 86 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSimple); | 94 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSimple); |
| 87 }; | 95 }; |
| 88 | 96 |
| 89 // Test version of PrefServiceSyncable. | 97 // Test version of PrefServiceSyncable. |
| 90 class TestingPrefServiceSyncable | 98 class TestingPrefServiceSyncable |
| 91 : public TestingPrefServiceBase<PrefServiceSyncable> { | 99 : public TestingPrefServiceBase<PrefServiceSyncable> { |
| 92 public: | 100 public: |
| 93 TestingPrefServiceSyncable(); | 101 TestingPrefServiceSyncable(); |
| 94 virtual ~TestingPrefServiceSyncable(); | 102 virtual ~TestingPrefServiceSyncable(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 109 } | 117 } |
| 110 | 118 |
| 111 private: | 119 private: |
| 112 TestingBrowserProcess* browser_process_; | 120 TestingBrowserProcess* browser_process_; |
| 113 TestingPrefServiceSimple local_state_; | 121 TestingPrefServiceSimple local_state_; |
| 114 | 122 |
| 115 DISALLOW_COPY_AND_ASSIGN(ScopedTestingLocalState); | 123 DISALLOW_COPY_AND_ASSIGN(ScopedTestingLocalState); |
| 116 }; | 124 }; |
| 117 | 125 |
| 118 template<> | 126 template<> |
| 119 TestingPrefServiceBase<PrefServiceSimple>::TestingPrefServiceBase( | 127 TestingPrefServiceBase<PrefService>::TestingPrefServiceBase( |
| 120 TestingPrefStore* managed_prefs, | 128 TestingPrefStore* managed_prefs, |
| 121 TestingPrefStore* user_prefs, | 129 TestingPrefStore* user_prefs, |
| 122 TestingPrefStore* recommended_prefs, | 130 TestingPrefStore* recommended_prefs, |
| 123 DefaultPrefStore* default_store, | 131 PrefRegistry* pref_registry, |
| 124 PrefNotifierImpl* pref_notifier); | 132 PrefNotifierImpl* pref_notifier); |
| 125 | 133 |
| 126 template<> | 134 template<> |
| 127 TestingPrefServiceBase<PrefServiceSyncable>::TestingPrefServiceBase( | 135 TestingPrefServiceBase<PrefServiceSyncable>::TestingPrefServiceBase( |
| 128 TestingPrefStore* managed_prefs, | 136 TestingPrefStore* managed_prefs, |
| 129 TestingPrefStore* user_prefs, | 137 TestingPrefStore* user_prefs, |
| 130 TestingPrefStore* recommended_prefs, | 138 TestingPrefStore* recommended_prefs, |
| 131 DefaultPrefStore* default_store, | 139 PrefRegistry* pref_registry, |
| 132 PrefNotifierImpl* pref_notifier); | 140 PrefNotifierImpl* pref_notifier); |
| 133 | 141 |
| 134 template<class SuperPrefService> | 142 template<class SuperPrefService> |
| 135 TestingPrefServiceBase<SuperPrefService>::~TestingPrefServiceBase() { | 143 TestingPrefServiceBase<SuperPrefService>::~TestingPrefServiceBase() { |
| 136 } | 144 } |
| 137 | 145 |
| 138 template<class SuperPrefService> | 146 template<class SuperPrefService> |
| 139 const Value* TestingPrefServiceBase<SuperPrefService>::GetManagedPref( | 147 const Value* TestingPrefServiceBase<SuperPrefService>::GetManagedPref( |
| 140 const char* path) const { | 148 const char* path) const { |
| 141 return GetPref(managed_prefs_, path); | 149 return GetPref(managed_prefs_, path); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 pref_store->SetValue(path, value); | 210 pref_store->SetValue(path, value); |
| 203 } | 211 } |
| 204 | 212 |
| 205 template<class SuperPrefService> | 213 template<class SuperPrefService> |
| 206 void TestingPrefServiceBase<SuperPrefService>::RemovePref( | 214 void TestingPrefServiceBase<SuperPrefService>::RemovePref( |
| 207 TestingPrefStore* pref_store, const char* path) { | 215 TestingPrefStore* pref_store, const char* path) { |
| 208 pref_store->RemoveValue(path); | 216 pref_store->RemoveValue(path); |
| 209 } | 217 } |
| 210 | 218 |
| 211 #endif // CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ | 219 #endif // CHROME_TEST_BASE_TESTING_PREF_SERVICE_H_ |
| OLD | NEW |