OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_TESTING_PREF_SERVICE_H_ | 5 #ifndef CHROME_TEST_TESTING_PREF_SERVICE_H_ |
6 #define CHROME_TEST_TESTING_PREF_SERVICE_H_ | 6 #define CHROME_TEST_TESTING_PREF_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/ref_counted.h" | |
9 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
10 | 11 |
12 class ExtensionPrefStore; | |
11 class TestingPrefStore; | 13 class TestingPrefStore; |
12 | 14 |
13 // A PrefService subclass for testing. It operates totally in memory and | 15 // A PrefService subclass for testing. It operates totally in memory and |
14 // provides additional API for manipulating preferences at the different levels | 16 // provides additional API for manipulating preferences at the different levels |
15 // (managed, extension, user) conveniently. | 17 // (managed, extension, user) conveniently. |
16 class TestingPrefService : public PrefService { | 18 class TestingPrefServiceBase : public PrefService { |
17 public: | 19 public: |
18 // Create an empty instance. | 20 virtual ~TestingPrefServiceBase(); |
19 TestingPrefService(); | |
20 virtual ~TestingPrefService() {} | |
21 | 21 |
22 // Read the value of a preference from the managed layer. Returns NULL if the | 22 // Read the value of a preference from the managed layer. Returns NULL if the |
23 // preference is not defined at the managed layer. | 23 // preference is not defined at the managed layer. |
24 const Value* GetManagedPref(const char* path) const; | 24 const Value* GetManagedPref(const char* path) const; |
25 | 25 |
26 // Set a preference on the managed layer and fire observers if the preference | 26 // Set a preference on the managed layer and fire observers if the preference |
27 // changed. Assumes ownership of |value|. | 27 // changed. Assumes ownership of |value|. |
28 void SetManagedPref(const char* path, Value* value); | 28 void SetManagedPref(const char* path, Value* value); |
29 | 29 |
30 // Clear the preference on the managed layer and fire observers if the | 30 // Clear the preference on the managed layer and fire observers if the |
31 // preference has been defined previously. | 31 // preference has been defined previously. |
32 void RemoveManagedPref(const char* path); | 32 void RemoveManagedPref(const char* path); |
33 | 33 |
34 // Similar to the above, but for user preferences. | 34 // Similar to the above, but for user preferences. |
35 const Value* GetUserPref(const char* path) const; | 35 const Value* GetUserPref(const char* path) const; |
36 void SetUserPref(const char* path, Value* value); | 36 void SetUserPref(const char* path, Value* value); |
37 void RemoveUserPref(const char* path); | 37 void RemoveUserPref(const char* path); |
38 | 38 |
39 ExtensionPrefStore* GetExtensionPrefs(); | |
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
This is bad, we should have TestingPrefStores excl
battre
2011/01/05 20:23:08
Gone. TestingPrefService cannot use ExtensionPrefS
| |
40 | |
41 protected: | |
42 TestingPrefServiceBase( | |
43 TestingPrefStore* managed_platform_prefs, | |
44 TestingPrefStore* device_management_prefs, | |
45 ExtensionPrefStore* extension_prefs, | |
46 TestingPrefStore* user_prefs); | |
47 | |
48 // Pointers to the pref stores our value store uses. | |
49 scoped_refptr<TestingPrefStore> managed_platform_prefs_; | |
50 scoped_refptr<TestingPrefStore> device_management_prefs_; | |
51 scoped_refptr<ExtensionPrefStore> extension_prefs_; | |
52 scoped_refptr<TestingPrefStore> user_prefs_; | |
53 | |
39 private: | 54 private: |
40 // Reads the value of the preference indicated by |path| from |pref_store|. | 55 // Reads the value of the preference indicated by |path| from |pref_store|. |
41 // Returns NULL if the preference was not found. | 56 // Returns NULL if the preference was not found. |
42 const Value* GetPref(TestingPrefStore* pref_store, const char* path) const; | 57 const Value* GetPref(TestingPrefStore* pref_store, const char* path) const; |
43 | 58 |
44 // Sets the value for |path| in |pref_store|. | 59 // Sets the value for |path| in |pref_store|. |
45 void SetPref(TestingPrefStore* pref_store, const char* path, Value* value); | 60 void SetPref(TestingPrefStore* pref_store, const char* path, Value* value); |
46 | 61 |
47 // Removes the preference identified by |path| from |pref_store|. | 62 // Removes the preference identified by |path| from |pref_store|. |
48 void RemovePref(TestingPrefStore* pref_store, const char* path); | 63 void RemovePref(TestingPrefStore* pref_store, const char* path); |
49 | 64 |
50 // Pointers to the pref stores our value store uses. | 65 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceBase); |
51 TestingPrefStore* managed_platform_prefs_; // weak | 66 }; |
52 TestingPrefStore* device_management_prefs_; // weak | |
53 TestingPrefStore* user_prefs_; // weak | |
54 | 67 |
68 // Class for simplified construction of TestPrefServiceBase objects. | |
69 class TestingPrefService : public TestingPrefServiceBase { | |
70 public: | |
71 TestingPrefService(); | |
72 virtual ~TestingPrefService(); | |
73 private: | |
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
new line before private:
battre
2011/01/05 20:23:08
Done.
| |
55 DISALLOW_COPY_AND_ASSIGN(TestingPrefService); | 74 DISALLOW_COPY_AND_ASSIGN(TestingPrefService); |
56 }; | 75 }; |
57 | 76 |
58 #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_ | 77 #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_ |
OLD | NEW |