| 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 CommandLine; |
| 12 namespace policy { | 12 namespace policy { |
| 13 class ConfigurationPolicyProvider; | 13 class ConfigurationPolicyProvider; |
| 14 } | 14 } |
| 15 class PrefStore; | 15 class PrefStore; |
| 16 | 16 |
| 17 // A PrefService subclass for testing. It operates totally in memory and | 17 // A PrefService subclass for testing. It operates totally in memory and |
| 18 // provides additional API for manipulating preferences at the different levels | 18 // provides additional API for manipulating preferences at the different levels |
| 19 // (managed, extension, user) conveniently. | 19 // (managed, extension, user) conveniently. |
| 20 class TestingPrefService : public PrefService { | 20 class TestingPrefService : public PrefService { |
| 21 public: | 21 public: |
| 22 // Subclass to allow directly setting PrefStores. | 22 // Subclass to allow directly setting PrefStores. |
| 23 class TestingPrefValueStore : public PrefValueStore { | 23 class TestingPrefValueStore : public PrefValueStore { |
| 24 public: | 24 public: |
| 25 TestingPrefValueStore(PrefStore* managed_prefs, | 25 TestingPrefValueStore(PrefStore* managed_prefs, |
| 26 PrefStore* device_management_prefs, |
| 26 PrefStore* extension_prefs, | 27 PrefStore* extension_prefs, |
| 27 PrefStore* command_line_prefs, | 28 PrefStore* command_line_prefs, |
| 28 PrefStore* user_prefs, | 29 PrefStore* user_prefs, |
| 29 PrefStore* recommended_prefs, | 30 PrefStore* recommended_prefs, |
| 30 PrefStore* default_prefs); | 31 PrefStore* default_prefs); |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 // Create an empty instance. | 34 // Create an empty instance. |
| 34 TestingPrefService(); | 35 TestingPrefService(); |
| 35 | 36 |
| 36 // Create an instance that has a managed PrefStore and a command- | 37 // Create an instance that has a managed PrefStore and a command- line |
| 37 // line PrefStore. |provider| contains the provider with which to | 38 // PrefStore. |managed_platform_provider| contains the provider with which to |
| 38 // initialize the managed PrefStore. If it is NULL, then a | 39 // initialize the managed platform PrefStore. If it is NULL, then a |
| 39 // DummyPrefStore will be created. |command_line| contains the | 40 // DummyPrefStore will be created. |device_management_provider| contains the |
| 40 // provider with which to initialize the command line PrefStore. If | 41 // provider with which to initialize the device management |
| 41 // it is NULL then a DummyPrefStore will be created as the command | 42 // PrefStore. |command_line| contains the provider with which to initialize |
| 42 // line PrefStore. | 43 // the command line PrefStore. If it is NULL then a DummyPrefStore will be |
| 43 TestingPrefService(policy::ConfigurationPolicyProvider* provider, | 44 // created as the command line PrefStore. |
| 44 CommandLine* command_line); | 45 TestingPrefService( |
| 46 policy::ConfigurationPolicyProvider* managed_platform_provider, |
| 47 policy::ConfigurationPolicyProvider* device_management_provider, |
| 48 CommandLine* command_line); |
| 45 | 49 |
| 46 // Read the value of a preference from the managed layer. Returns NULL if the | 50 // Read the value of a preference from the managed layer. Returns NULL if the |
| 47 // preference is not defined at the managed layer. | 51 // preference is not defined at the managed layer. |
| 48 const Value* GetManagedPref(const char* path); | 52 const Value* GetManagedPref(const char* path); |
| 49 | 53 |
| 50 // Set a preference on the managed layer and fire observers if the preference | 54 // Set a preference on the managed layer and fire observers if the preference |
| 51 // changed. Assumes ownership of |value|. | 55 // changed. Assumes ownership of |value|. |
| 52 void SetManagedPref(const char* path, Value* value); | 56 void SetManagedPref(const char* path, Value* value); |
| 53 | 57 |
| 54 // Clear the preference on the managed layer and fire observers if the | 58 // Clear the preference on the managed layer and fire observers if the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 68 void RemoveManagedPrefWithoutNotification(const char* path); | 72 void RemoveManagedPrefWithoutNotification(const char* path); |
| 69 | 73 |
| 70 // Similar to the above, but for user preferences. | 74 // Similar to the above, but for user preferences. |
| 71 const Value* GetUserPref(const char* path); | 75 const Value* GetUserPref(const char* path); |
| 72 void SetUserPref(const char* path, Value* value); | 76 void SetUserPref(const char* path, Value* value); |
| 73 void RemoveUserPref(const char* path); | 77 void RemoveUserPref(const char* path); |
| 74 | 78 |
| 75 private: | 79 private: |
| 76 // Creates a ConfigurationPolicyPrefStore based on the provided | 80 // Creates a ConfigurationPolicyPrefStore based on the provided |
| 77 // |provider| or a DummyPrefStore if |provider| is NULL. | 81 // |provider| or a DummyPrefStore if |provider| is NULL. |
| 78 PrefStore* CreateManagedPrefStore( | 82 PrefStore* CreatePolicyPrefStoreFromProvider( |
| 79 policy::ConfigurationPolicyProvider* provider); | 83 policy::ConfigurationPolicyProvider* provider); |
| 80 | 84 |
| 81 // Creates a CommandLinePrefStore based on the supplied | 85 // Creates a CommandLinePrefStore based on the supplied |
| 82 // |command_line| or a DummyPrefStore if |command_line| is NULL. | 86 // |command_line| or a DummyPrefStore if |command_line| is NULL. |
| 83 PrefStore* CreateCommandLinePrefStore(CommandLine* command_line); | 87 PrefStore* CreateCommandLinePrefStore(CommandLine* command_line); |
| 84 | 88 |
| 85 // Reads the value of the preference indicated by |path| from |pref_store|. | 89 // Reads the value of the preference indicated by |path| from |pref_store|. |
| 86 // Returns NULL if the preference was not found. | 90 // Returns NULL if the preference was not found. |
| 87 const Value* GetPref(PrefStore* pref_store, const char* path); | 91 const Value* GetPref(PrefStore* pref_store, const char* path); |
| 88 | 92 |
| 89 // Sets the value for |path| in |pref_store|. | 93 // Sets the value for |path| in |pref_store|. |
| 90 void SetPref(PrefStore* pref_store, const char* path, Value* value); | 94 void SetPref(PrefStore* pref_store, const char* path, Value* value); |
| 91 | 95 |
| 92 // Removes the preference identified by |path| from |pref_store|. | 96 // Removes the preference identified by |path| from |pref_store|. |
| 93 void RemovePref(PrefStore* pref_store, const char* path); | 97 void RemovePref(PrefStore* pref_store, const char* path); |
| 94 | 98 |
| 95 // Pointers to the pref stores our value store uses. | 99 // Pointers to the pref stores our value store uses. |
| 96 PrefStore* managed_prefs_; | 100 PrefStore* managed_platform_prefs_; // weak |
| 97 PrefStore* user_prefs_; | 101 PrefStore* device_management_prefs_; // weak |
| 98 PrefStore* default_prefs_; | 102 PrefStore* user_prefs_; // weak |
| 103 PrefStore* default_prefs_; // weak |
| 99 | 104 |
| 100 DISALLOW_COPY_AND_ASSIGN(TestingPrefService); | 105 DISALLOW_COPY_AND_ASSIGN(TestingPrefService); |
| 101 }; | 106 }; |
| 102 | 107 |
| 103 #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_ | 108 #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_ |
| OLD | NEW |