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_BROWSER_PREF_VALUE_STORE_H_ | 5 #ifndef CHROME_BROWSER_PREF_VALUE_STORE_H_ |
6 #define CHROME_BROWSER_PREF_VALUE_STORE_H_ | 6 #define CHROME_BROWSER_PREF_VALUE_STORE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/ref_counted.h" | 16 #include "base/ref_counted.h" |
17 #include "base/string16.h" | 17 #include "base/string16.h" |
18 #include "base/scoped_ptr.h" | 18 #include "base/scoped_ptr.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "chrome/browser/chrome_thread.h" | 20 #include "chrome/browser/chrome_thread.h" |
21 #include "chrome/common/pref_store.h" | 21 #include "chrome/common/pref_store.h" |
22 | 22 |
23 class PrefStore; | 23 class PrefStore; |
24 class Profile; | |
24 | 25 |
25 // The class PrefValueStore provides values for preferences. Each Preference | 26 // The class PrefValueStore provides values for preferences. Each Preference |
26 // has a unique name. This name is used to retrieve the value of a Preference. | 27 // has a unique name. This name is used to retrieve the value of a Preference. |
27 // The value of a preference can be either managed, user-defined or recommended. | 28 // The value of a preference can be either managed, user-defined or recommended. |
28 // Managed preference values are set (managed) by a third person (like an | 29 // Managed preference values are set (managed) by a third person (like an |
29 // admin for example). They have the highest priority and can not be | 30 // admin for example). They have the highest priority and can not be |
30 // altered by the user. | 31 // altered by the user. |
31 // User-defined values are chosen by the user. If there is already | 32 // User-defined values are chosen by the user. If there is already |
32 // a managed value for a preference the user-defined value is ignored and | 33 // a managed value for a preference the user-defined value is ignored and |
33 // the managed value is used (returned). | 34 // the managed value is used (returned). |
34 // Otherwise user-defined values have a higher precedence than recommended | 35 // Otherwise user-defined values have a higher precedence than recommended |
35 // values. Recommended preference values are set by a third person | 36 // values. Recommended preference values are set by a third person |
36 // (like an admin). | 37 // (like an admin). |
37 // Unless otherwise explicitly noted, all of the methods of this class must | 38 // Unless otherwise explicitly noted, all of the methods of this class must |
38 // be called on the UI thread. | 39 // be called on the UI thread. |
39 class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { | 40 class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { |
40 public: | 41 public: |
41 // In decreasing order of precedence: | 42 ~PrefValueStore(); |
42 // |managed_prefs| contains all managed (policy) preference values. | |
43 // |extension_prefs| contains preference values set by extensions. | |
44 // |command_line_prefs| contains preference values set by command-line | |
45 // switches. | |
46 // |user_prefs| contains all user-set preference values. | |
47 // |recommended_prefs| contains all recommended (policy) preference values. | |
48 PrefValueStore(PrefStore* managed_prefs, | |
49 PrefStore* extension_prefs, | |
50 PrefStore* command_line_prefs, | |
51 PrefStore* user_prefs, | |
52 PrefStore* recommended_prefs); | |
53 | 43 |
54 ~PrefValueStore(); | 44 // Returns a new PrefValueStore with all applicable PrefStores. The |
45 // |pref_filename| points to the user preference file. The |profile| is the | |
46 // one to which these preferences apply; it may be NULL if we're dealing | |
47 // with the local state. If |pref_filename| is empty, the user PrefStore will | |
48 // not be created. If |user_only| is true, no PrefStores will be created | |
49 // other than the user PrefStore (if |pref_filename| is not empty). This | |
50 // should not be called directly. The usual way to create a PrefValueStore is | |
51 // by creating a PrefService. | |
52 static PrefValueStore* CreatePrefValueStore(const FilePath& pref_filename, | |
53 Profile* profile, | |
54 bool user_only); | |
55 | 55 |
56 // Get the preference value for the given preference name. | 56 // Get the preference value for the given preference name. |
57 // Return true if a value for the given preference name was found. | 57 // Return true if a value for the given preference name was found. |
58 bool GetValue(const std::wstring& name, Value** out_value) const; | 58 bool GetValue(const std::wstring& name, Value** out_value) const; |
59 | 59 |
60 // Read preference values into the three PrefStores so that they are available | 60 // Read preference values into the three PrefStores so that they are available |
61 // through the GetValue method. Return the first error that occurs (but | 61 // through the GetValue method. Return the first error that occurs (but |
62 // continue reading the remaining PrefStores). | 62 // continue reading the remaining PrefStores). |
63 PrefStore::PrefReadError ReadPrefs(); | 63 PrefStore::PrefReadError ReadPrefs(); |
64 | 64 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 // new, uninitialized managed and recommended PrefStores in | 120 // new, uninitialized managed and recommended PrefStores in |
121 // |managed_pref_store| and |recommended_pref_store| respectively, since | 121 // |managed_pref_store| and |recommended_pref_store| respectively, since |
122 // PrefValueStore doesn't know about policy-specific PrefStores. | 122 // PrefValueStore doesn't know about policy-specific PrefStores. |
123 // |callback| is called with the set of preferences changed by the policy | 123 // |callback| is called with the set of preferences changed by the policy |
124 // refresh. |callback| is called the caller's thread as a Task | 124 // refresh. |callback| is called the caller's thread as a Task |
125 // after RefreshPolicyPrefs has returned. | 125 // after RefreshPolicyPrefs has returned. |
126 void RefreshPolicyPrefs(PrefStore* managed_pref_store, | 126 void RefreshPolicyPrefs(PrefStore* managed_pref_store, |
127 PrefStore* recommended_pref_store, | 127 PrefStore* recommended_pref_store, |
128 AfterRefreshCallback callback); | 128 AfterRefreshCallback callback); |
129 | 129 |
130 protected: | |
131 // In decreasing order of precedence: | |
132 // |managed_prefs| contains all managed (policy) preference values. | |
133 // |extension_prefs| contains preference values set by extensions. | |
134 // |command_line_prefs| contains preference values set by command-line | |
135 // switches. | |
136 // |user_prefs| contains all user-set preference values. | |
137 // |recommended_prefs| contains all recommended (policy) preference values. | |
138 // | |
139 // This constructor should only be used by subclasses in testing. The usual | |
Mattias Nissler (ping if slow)
2010/08/06 07:29:42
nit: It's also used for creating the actual PrefVa
| |
140 // way to create a PrefValueStore is by creating a PrefService. | |
141 PrefValueStore(PrefStore* managed_prefs, | |
142 PrefStore* extension_prefs, | |
143 PrefStore* command_line_prefs, | |
144 PrefStore* user_prefs, | |
145 PrefStore* recommended_prefs); | |
146 | |
130 private: | 147 private: |
131 friend class PrefValueStoreTest; | 148 friend class PrefValueStoreTest; |
132 FRIEND_TEST_ALL_PREFIXES(PrefValueStoreTest, | 149 FRIEND_TEST_ALL_PREFIXES(PrefValueStoreTest, |
133 TestRefreshPolicyPrefsCompletion); | 150 TestRefreshPolicyPrefsCompletion); |
134 | 151 |
135 // PrefStores must be listed here in order from highest to lowest priority. | 152 // PrefStores must be listed here in order from highest to lowest priority. |
136 enum PrefStoreType { | 153 enum PrefStoreType { |
137 // Not associated with an actual PrefStore but used as invalid marker, e.g. | 154 // Not associated with an actual PrefStore but used as invalid marker, e.g. |
138 // as return value. | 155 // as return value. |
139 INVALID = -1, | 156 INVALID = -1, |
(...skipping 25 matching lines...) Expand all Loading... | |
165 void RefreshPolicyPrefsOnFileThread( | 182 void RefreshPolicyPrefsOnFileThread( |
166 ChromeThread::ID calling_thread_id, | 183 ChromeThread::ID calling_thread_id, |
167 PrefStore* new_managed_pref_store, | 184 PrefStore* new_managed_pref_store, |
168 PrefStore* new_recommended_pref_store, | 185 PrefStore* new_recommended_pref_store, |
169 AfterRefreshCallback callback); | 186 AfterRefreshCallback callback); |
170 | 187 |
171 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); | 188 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); |
172 }; | 189 }; |
173 | 190 |
174 #endif // CHROME_BROWSER_PREF_VALUE_STORE_H_ | 191 #endif // CHROME_BROWSER_PREF_VALUE_STORE_H_ |
OLD | NEW |