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> |
| 10 #include <vector> |
| 11 |
9 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" |
10 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/ref_counted.h" |
11 #include "base/string16.h" | 17 #include "base/string16.h" |
12 #include "base/scoped_ptr.h" | 18 #include "base/scoped_ptr.h" |
13 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/chrome_thread.h" |
14 #include "chrome/common/pref_store.h" | 21 #include "chrome/common/pref_store.h" |
15 | 22 |
16 class PrefStore; | 23 class PrefStore; |
17 | 24 |
18 // The class PrefValueStore provides values for preferences. Each Preference | 25 // The class PrefValueStore provides values for preferences. Each Preference |
19 // has a unique name. This name is used to retrieve the value of a Preference. | 26 // has a unique name. This name is used to retrieve the value of a Preference. |
20 // The value of a preference can be either managed, user-defined or recommended. | 27 // The value of a preference can be either managed, user-defined or recommended. |
21 // Managed preference values are set (managed) by a third person (like an | 28 // Managed preference values are set (managed) by a third person (like an |
22 // admin for example). They have the highest priority and can not be | 29 // admin for example). They have the highest priority and can not be |
23 // altered by the user. | 30 // altered by the user. |
24 // User-defined values are chosen by the user. If there is already | 31 // User-defined values are chosen by the user. If there is already |
25 // a managed value for a preference the user-defined value is ignored and | 32 // a managed value for a preference the user-defined value is ignored and |
26 // the managed value is used (returned). | 33 // the managed value is used (returned). |
27 // Otherwise user-defined values have a higher precedence than recommended | 34 // Otherwise user-defined values have a higher precedence than recommended |
28 // values. Recommended preference values are set by a third person | 35 // values. Recommended preference values are set by a third person |
29 // (like an admin). | 36 // (like an admin). |
30 class PrefValueStore { | 37 // Unless otherwise explicitly noted, all of the methods of this class must |
| 38 // be called on the UI thread. |
| 39 class PrefValueStore : public base::RefCountedThreadSafe<PrefValueStore> { |
31 public: | 40 public: |
32 // In decreasing order of precedence: | 41 // In decreasing order of precedence: |
33 // |managed_prefs| contains all managed (policy) preference values. | 42 // |managed_prefs| contains all managed (policy) preference values. |
34 // |extension_prefs| contains preference values set by extensions. | 43 // |extension_prefs| contains preference values set by extensions. |
35 // |command_line_prefs| contains preference values set by command-line | 44 // |command_line_prefs| contains preference values set by command-line |
36 // switches. | 45 // switches. |
37 // |user_prefs| contains all user-set preference values. | 46 // |user_prefs| contains all user-set preference values. |
38 // |recommended_prefs| contains all recommended (policy) preference values. | 47 // |recommended_prefs| contains all recommended (policy) preference values. |
39 PrefValueStore(PrefStore* managed_prefs, | 48 PrefValueStore(PrefStore* managed_prefs, |
40 PrefStore* extension_prefs, | 49 PrefStore* extension_prefs, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // These methods return true if a preference with the given name is actually | 103 // These methods return true if a preference with the given name is actually |
95 // being controlled by the indicated pref store and not being overridden by | 104 // being controlled by the indicated pref store and not being overridden by |
96 // a higher-priority source. | 105 // a higher-priority source. |
97 bool PrefValueFromExtensionStore(const wchar_t* name); | 106 bool PrefValueFromExtensionStore(const wchar_t* name); |
98 bool PrefValueFromUserStore(const wchar_t* name); | 107 bool PrefValueFromUserStore(const wchar_t* name); |
99 | 108 |
100 // Check whether a Preference value is modifiable by the user, i.e. whether | 109 // Check whether a Preference value is modifiable by the user, i.e. whether |
101 // there is no higher-priority source controlling it. | 110 // there is no higher-priority source controlling it. |
102 bool PrefValueUserModifiable(const wchar_t* name); | 111 bool PrefValueUserModifiable(const wchar_t* name); |
103 | 112 |
| 113 // Signature of callback triggered after policy refresh. Parameter is not |
| 114 // passed as reference to prevent passing along a pointer to a set whose |
| 115 // lifecycle is managed in another thread. |
| 116 typedef Callback1<std::vector<std::string> >::Type* AfterRefreshCallback; |
| 117 |
| 118 // Called as a result of a notification of policy change. Triggers a |
| 119 // reload of managed preferences from policy. Caller must pass in |
| 120 // new, uninitialized managed and recommended PrefStores in |
| 121 // |managed_pref_store| and |recommended_pref_store| respectively, since |
| 122 // PrefValueStore doesn't know about policy-specific PrefStores. |
| 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 |
| 125 // after RefreshPolicyPrefs has returned. |
| 126 void RefreshPolicyPrefs(PrefStore* managed_pref_store, |
| 127 PrefStore* recommended_pref_store, |
| 128 AfterRefreshCallback callback); |
| 129 |
104 private: | 130 private: |
| 131 friend class PrefValueStoreTest; |
| 132 FRIEND_TEST_ALL_PREFIXES(PrefValueStoreTest, |
| 133 TestRefreshPolicyPrefsCompletion); |
| 134 |
105 // PrefStores must be listed here in order from highest to lowest priority. | 135 // PrefStores must be listed here in order from highest to lowest priority. |
106 enum PrefStoreType { | 136 enum PrefStoreType { |
107 // Not associated with an actual PrefStore but used as invalid marker, e.g. | 137 // Not associated with an actual PrefStore but used as invalid marker, e.g. |
108 // as return value. | 138 // as return value. |
109 INVALID = -1, | 139 INVALID = -1, |
110 MANAGED = 0, | 140 MANAGED = 0, |
111 EXTENSION, | 141 EXTENSION, |
112 COMMAND_LINE, | 142 COMMAND_LINE, |
113 USER, | 143 USER, |
114 RECOMMENDED, | 144 RECOMMENDED, |
115 PREF_STORE_TYPE_MAX = RECOMMENDED | 145 PREF_STORE_TYPE_MAX = RECOMMENDED |
116 }; | 146 }; |
117 | 147 |
118 scoped_ptr<PrefStore> pref_stores_[PREF_STORE_TYPE_MAX + 1]; | 148 scoped_ptr<PrefStore> pref_stores_[PREF_STORE_TYPE_MAX + 1]; |
119 | 149 |
120 bool PrefValueInStore(const wchar_t* name, PrefStoreType type); | 150 bool PrefValueInStore(const wchar_t* name, PrefStoreType type); |
121 | 151 |
122 // Returns the pref store type identifying the source that controls the | 152 // Returns the pref store type identifying the source that controls the |
123 // Preference identified by |name|. If none of the sources has a value, | 153 // Preference identified by |name|. If none of the sources has a value, |
124 // INVALID is returned. | 154 // INVALID is returned. |
125 PrefStoreType ControllingPrefStoreForPref(const wchar_t* name); | 155 PrefStoreType ControllingPrefStoreForPref(const wchar_t* name); |
126 | 156 |
| 157 // Called during policy refresh after ReadPrefs completes on the thread |
| 158 // that initiated the policy refresh. |
| 159 void RefreshPolicyPrefsCompletion( |
| 160 PrefStore* new_managed_pref_store, |
| 161 PrefStore* new_recommended_pref_store, |
| 162 AfterRefreshCallback callback); |
| 163 |
| 164 // Called during policy refresh to do the ReadPrefs on the FILE thread. |
| 165 void RefreshPolicyPrefsOnFileThread( |
| 166 ChromeThread::ID calling_thread_id, |
| 167 PrefStore* new_managed_pref_store, |
| 168 PrefStore* new_recommended_pref_store, |
| 169 AfterRefreshCallback callback); |
| 170 |
127 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); | 171 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); |
128 }; | 172 }; |
129 | 173 |
130 #endif // CHROME_BROWSER_PREF_VALUE_STORE_H_ | 174 #endif // CHROME_BROWSER_PREF_VALUE_STORE_H_ |
OLD | NEW |