Chromium Code Reviews| 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 |
| 11 class TestingPrefStore; | 12 class TestingPrefStore; |
| 12 | 13 |
| 13 // A PrefService subclass for testing. It operates totally in memory and | 14 // A PrefService subclass for testing. It operates totally in memory and |
| 14 // provides additional API for manipulating preferences at the different levels | 15 // provides additional API for manipulating preferences at the different levels |
| 15 // (managed, extension, user) conveniently. | 16 // (managed, extension, user) conveniently. |
| 16 class TestingPrefService : public PrefService { | 17 class TestingPrefServiceBase : public PrefService { |
| 17 public: | 18 public: |
| 18 // Create an empty instance. | 19 virtual ~TestingPrefServiceBase(); |
| 19 TestingPrefService(); | |
| 20 virtual ~TestingPrefService() {} | |
| 21 | 20 |
| 22 // 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 |
| 23 // preference is not defined at the managed layer. | 22 // preference is not defined at the managed layer. |
| 24 const Value* GetManagedPref(const char* path) const; | 23 const Value* GetManagedPref(const char* path) const; |
| 25 | 24 |
| 26 // 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 |
| 27 // changed. Assumes ownership of |value|. | 26 // changed. Assumes ownership of |value|. |
| 28 void SetManagedPref(const char* path, Value* value); | 27 void SetManagedPref(const char* path, Value* value); |
| 29 | 28 |
| 30 // 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 |
| 31 // preference has been defined previously. | 30 // preference has been defined previously. |
| 32 void RemoveManagedPref(const char* path); | 31 void RemoveManagedPref(const char* path); |
| 33 | 32 |
| 34 // Similar to the above, but for user preferences. | 33 // Similar to the above, but for user preferences. |
| 35 const Value* GetUserPref(const char* path) const; | 34 const Value* GetUserPref(const char* path) const; |
| 36 void SetUserPref(const char* path, Value* value); | 35 void SetUserPref(const char* path, Value* value); |
| 37 void RemoveUserPref(const char* path); | 36 void RemoveUserPref(const char* path); |
| 38 | 37 |
| 38 protected: | |
| 39 TestingPrefServiceBase( | |
| 40 TestingPrefStore* managed_platform_prefs, | |
| 41 TestingPrefStore* device_management_prefs, | |
| 42 TestingPrefStore* user_prefs); | |
| 43 | |
| 44 // Pointers to the pref stores our value store uses. | |
| 45 scoped_refptr<TestingPrefStore> managed_platform_prefs_; | |
| 46 scoped_refptr<TestingPrefStore> device_management_prefs_; | |
| 47 scoped_refptr<TestingPrefStore> user_prefs_; | |
|
danno
2011/01/14 13:05:09
make these private?
battre
2011/01/20 17:59:29
Done.
| |
| 48 | |
| 39 private: | 49 private: |
| 40 // Reads the value of the preference indicated by |path| from |pref_store|. | 50 // Reads the value of the preference indicated by |path| from |pref_store|. |
| 41 // Returns NULL if the preference was not found. | 51 // Returns NULL if the preference was not found. |
| 42 const Value* GetPref(TestingPrefStore* pref_store, const char* path) const; | 52 const Value* GetPref(TestingPrefStore* pref_store, const char* path) const; |
| 43 | 53 |
| 44 // Sets the value for |path| in |pref_store|. | 54 // Sets the value for |path| in |pref_store|. |
| 45 void SetPref(TestingPrefStore* pref_store, const char* path, Value* value); | 55 void SetPref(TestingPrefStore* pref_store, const char* path, Value* value); |
| 46 | 56 |
| 47 // Removes the preference identified by |path| from |pref_store|. | 57 // Removes the preference identified by |path| from |pref_store|. |
| 48 void RemovePref(TestingPrefStore* pref_store, const char* path); | 58 void RemovePref(TestingPrefStore* pref_store, const char* path); |
| 49 | 59 |
| 50 // Pointers to the pref stores our value store uses. | 60 DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceBase); |
| 51 TestingPrefStore* managed_platform_prefs_; // weak | 61 }; |
| 52 TestingPrefStore* device_management_prefs_; // weak | |
| 53 TestingPrefStore* user_prefs_; // weak | |
| 54 | 62 |
| 63 // Class for simplified construction of TestPrefServiceBase objects. | |
| 64 class TestingPrefService : public TestingPrefServiceBase { | |
| 65 public: | |
| 66 TestingPrefService(); | |
| 67 virtual ~TestingPrefService(); | |
| 68 | |
| 69 private: | |
| 55 DISALLOW_COPY_AND_ASSIGN(TestingPrefService); | 70 DISALLOW_COPY_AND_ASSIGN(TestingPrefService); |
| 56 }; | 71 }; |
| 57 | 72 |
| 58 #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_ | 73 #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_ |
| OLD | NEW |