Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: chrome/test/testing_pref_service.h

Issue 5646003: Sanitize PrefStore interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PrefService mock construction in PrefServiceTest to include command line store. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/reliability/page_load_test.cc ('k') | chrome/test/testing_pref_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 virtual ~TestingPrefService() {}
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 21
38 // 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
39 // preference is not defined at the managed layer. 23 // preference is not defined at the managed layer.
40 const Value* GetManagedPref(const char* path); 24 const Value* GetManagedPref(const char* path) const;
41 25
42 // 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
43 // changed. Assumes ownership of |value|. 27 // changed. Assumes ownership of |value|.
44 void SetManagedPref(const char* path, Value* value); 28 void SetManagedPref(const char* path, Value* value);
45 29
46 // 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
47 // preference has been defined previously. 31 // preference has been defined previously.
48 void RemoveManagedPref(const char* path); 32 void RemoveManagedPref(const char* path);
49 33
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. 34 // Similar to the above, but for user preferences.
63 const Value* GetUserPref(const char* path); 35 const Value* GetUserPref(const char* path) const;
64 void SetUserPref(const char* path, Value* value); 36 void SetUserPref(const char* path, Value* value);
65 void RemoveUserPref(const char* path); 37 void RemoveUserPref(const char* path);
66 38
67 private: 39 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|. 40 // Reads the value of the preference indicated by |path| from |pref_store|.
78 // Returns NULL if the preference was not found. 41 // Returns NULL if the preference was not found.
79 const Value* GetPref(PrefStore* pref_store, const char* path); 42 const Value* GetPref(TestingPrefStore* pref_store, const char* path) const;
80 43
81 // Sets the value for |path| in |pref_store|. 44 // Sets the value for |path| in |pref_store|.
82 void SetPref(PrefStore* pref_store, const char* path, Value* value); 45 void SetPref(TestingPrefStore* pref_store, const char* path, Value* value);
83 46
84 // Removes the preference identified by |path| from |pref_store|. 47 // Removes the preference identified by |path| from |pref_store|.
85 void RemovePref(PrefStore* pref_store, const char* path); 48 void RemovePref(TestingPrefStore* pref_store, const char* path);
86 49
87 // Pointers to the pref stores our value store uses. 50 // Pointers to the pref stores our value store uses.
88 PrefStore* managed_platform_prefs_; // weak 51 TestingPrefStore* managed_platform_prefs_; // weak
89 PrefStore* device_management_prefs_; // weak 52 TestingPrefStore* device_management_prefs_; // weak
90 PrefStore* user_prefs_; // weak 53 TestingPrefStore* user_prefs_; // weak
91 PrefStore* default_prefs_; // weak
92 54
93 DISALLOW_COPY_AND_ASSIGN(TestingPrefService); 55 DISALLOW_COPY_AND_ASSIGN(TestingPrefService);
94 }; 56 };
95 57
96 #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_ 58 #endif // CHROME_TEST_TESTING_PREF_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/test/reliability/page_load_test.cc ('k') | chrome/test/testing_pref_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698