OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 | 10 |
11 class CommandLine; | 11 class TestingPrefStore; |
12 namespace policy { | |
13 class ConfigurationPolicyProvider; | |
14 } | |
15 class PrefStore; | |
16 | 12 |
17 // A PrefService subclass for testing. It operates totally in memory and | 13 // A PrefService subclass for testing. It operates totally in memory and |
18 // provides additional API for manipulating preferences at the different levels | 14 // provides additional API for manipulating preferences at the different levels |
19 // (managed, extension, user) conveniently. | 15 // (managed, extension, user) conveniently. |
20 class TestingPrefService : public PrefService { | 16 class TestingPrefService : public PrefService { |
21 public: | 17 public: |
22 // Create an empty instance. | 18 // Create an empty instance. |
23 TestingPrefService(); | 19 TestingPrefService(); |
24 | 20 |
25 // Create an instance that has a managed PrefStore and a command- line | |
26 // PrefStore. |managed_platform_provider| contains the provider with which to | |
27 // initialize the managed platform PrefStore. If it is NULL, then a | |
28 // TestingPrefStore will be created. |device_management_provider| contains the | |
29 // provider with which to initialize the device management | |
30 // PrefStore. |command_line| contains the provider with which to initialize | |
31 // the command line PrefStore. If it is NULL then a TestingPrefStore will be | |
32 // created as the command line PrefStore. | |
33 TestingPrefService( | |
34 policy::ConfigurationPolicyProvider* managed_platform_provider, | |
35 policy::ConfigurationPolicyProvider* device_management_provider, | |
36 CommandLine* command_line); | |
37 | |
38 // Read the value of a preference from the managed layer. Returns NULL if the | 21 // Read the value of a preference from the managed layer. Returns NULL if the |
39 // preference is not defined at the managed layer. | 22 // preference is not defined at the managed layer. |
40 const Value* GetManagedPref(const char* path); | 23 const Value* GetManagedPref(const char* path); |
41 | 24 |
42 // Set a preference on the managed layer and fire observers if the preference | 25 // Set a preference on the managed layer and fire observers if the preference |
43 // changed. Assumes ownership of |value|. | 26 // changed. Assumes ownership of |value|. |
44 void SetManagedPref(const char* path, Value* value); | 27 void SetManagedPref(const char* path, Value* value); |
45 | 28 |
46 // Clear the preference on the managed layer and fire observers if the | 29 // Clear the preference on the managed layer and fire observers if the |
47 // preference has been defined previously. | 30 // preference has been defined previously. |
48 void RemoveManagedPref(const char* path); | 31 void RemoveManagedPref(const char* path); |
49 | 32 |
50 // Set a preference on the managed layer. Assumes ownership of |value|. | |
51 // We don't fire observers for each change because in the real code, the | |
52 // notification is sent after all the prefs have been loaded. See | |
53 // ConfigurationPolicyPrefStore::ReadPrefs(). | |
54 void SetManagedPrefWithoutNotification(const char* path, Value* value); | |
55 | |
56 // Clear the preference on the managed layer. | |
57 // We don't fire observers for each change because in the real code, the | |
58 // notification is sent after all the prefs have been loaded. See | |
59 // ConfigurationPolicyPrefStore::ReadPrefs(). | |
60 void RemoveManagedPrefWithoutNotification(const char* path); | |
61 | |
62 // Similar to the above, but for user preferences. | 33 // Similar to the above, but for user preferences. |
63 const Value* GetUserPref(const char* path); | 34 const Value* GetUserPref(const char* path); |
64 void SetUserPref(const char* path, Value* value); | 35 void SetUserPref(const char* path, Value* value); |
65 void RemoveUserPref(const char* path); | 36 void RemoveUserPref(const char* path); |
66 | 37 |
67 private: | 38 private: |
68 // Creates a ConfigurationPolicyPrefStore based on the provided | |
69 // |provider| or a TestingPrefStore if |provider| is NULL. | |
70 PrefStore* CreatePolicyPrefStoreFromProvider( | |
71 policy::ConfigurationPolicyProvider* provider); | |
72 | |
73 // Creates a CommandLinePrefStore based on the supplied | |
74 // |command_line| or a TestingPrefStore if |command_line| is NULL. | |
75 PrefStore* CreateCommandLinePrefStore(CommandLine* command_line); | |
76 | |
77 // Reads the value of the preference indicated by |path| from |pref_store|. | 39 // Reads the value of the preference indicated by |path| from |pref_store|. |
78 // Returns NULL if the preference was not found. | 40 // Returns NULL if the preference was not found. |
79 const Value* GetPref(PrefStore* pref_store, const char* path); | 41 const Value* GetPref(TestingPrefStore* pref_store, const char* path); |
battre (please use the other)
2010/12/08 12:24:15
Any reason why this has to be a TestingPrefStore i
battre (please use the other)
2010/12/08 12:24:15
const? maybe not because it is a Testing class
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Because we know it'll be a TestingPrefStore and fo
| |
80 | 42 |
81 // Sets the value for |path| in |pref_store|. | 43 // Sets the value for |path| in |pref_store|. |
82 void SetPref(PrefStore* pref_store, const char* path, Value* value); | 44 void SetPref(TestingPrefStore* pref_store, const char* path, Value* value); |
battre (please use the other)
2010/12/08 12:24:15
Any reason why this has to be a TestingPrefStore i
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
See the other comment.
| |
83 | 45 |
84 // Removes the preference identified by |path| from |pref_store|. | 46 // Removes the preference identified by |path| from |pref_store|. |
85 void RemovePref(PrefStore* pref_store, const char* path); | 47 void RemovePref(TestingPrefStore* pref_store, const char* path); |
86 | 48 |
87 // Pointers to the pref stores our value store uses. | 49 // Pointers to the pref stores our value store uses. |
88 PrefStore* managed_platform_prefs_; // weak | 50 TestingPrefStore* managed_platform_prefs_; // weak |
89 PrefStore* device_management_prefs_; // weak | 51 TestingPrefStore* device_management_prefs_; // weak |
90 PrefStore* user_prefs_; // weak | 52 TestingPrefStore* user_prefs_; // weak |
91 PrefStore* default_prefs_; // weak | |
92 | 53 |
93 DISALLOW_COPY_AND_ASSIGN(TestingPrefService); | 54 DISALLOW_COPY_AND_ASSIGN(TestingPrefService); |
94 }; | 55 }; |
95 | 56 |
96 #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_ | 57 #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_ |
OLD | NEW |