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_BROWSER_PREFS_PREF_VALUE_STORE_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ |
6 #define CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
16 #include "base/scoped_ptr.h" | |
17 #include "base/values.h" | 16 #include "base/values.h" |
18 #include "chrome/browser/browser_thread.h" | 17 #include "chrome/browser/browser_thread.h" |
19 #include "chrome/common/pref_store.h" | 18 #include "chrome/common/pref_store.h" |
20 | 19 |
21 class FilePath; | 20 class FilePath; |
22 class PrefNotifier; | 21 class PrefNotifier; |
23 class PrefStore; | 22 class PrefStore; |
24 class Profile; | 23 class Profile; |
25 | 24 |
26 // The PrefValueStore manages various sources of values for Preferences | 25 // The PrefValueStore manages various sources of values for Preferences |
(...skipping 29 matching lines...) Expand all Loading... | |
56 PrefValueStore(PrefStore* managed_platform_prefs, | 55 PrefValueStore(PrefStore* managed_platform_prefs, |
57 PrefStore* device_management_prefs, | 56 PrefStore* device_management_prefs, |
58 PrefStore* extension_prefs, | 57 PrefStore* extension_prefs, |
59 PrefStore* command_line_prefs, | 58 PrefStore* command_line_prefs, |
60 PrefStore* user_prefs, | 59 PrefStore* user_prefs, |
61 PrefStore* recommended_prefs, | 60 PrefStore* recommended_prefs, |
62 PrefStore* default_prefs, | 61 PrefStore* default_prefs, |
63 PrefNotifier* pref_notifier); | 62 PrefNotifier* pref_notifier); |
64 virtual ~PrefValueStore(); | 63 virtual ~PrefValueStore(); |
65 | 64 |
66 // Gets the value for the given preference name that has a valid value type; | 65 // Gets the value for the given preference name that has the specified value |
67 // that is, the same type the preference was registered with, or NULL for | 66 // type. Returns true if a valid value was found in any of the available |
68 // default values of Dictionaries and Lists. Returns true if a valid value | 67 // PrefStores. Most callers should use Preference::GetValue() instead of |
69 // was found in any of the available PrefStores. Most callers should use | 68 // calling this method directly. |
danno
2011/01/14 13:05:09
Please add comment about treatment of type (i.e. t
battre
2011/01/20 17:59:29
Done.
| |
70 // Preference::GetValue() instead of calling this method directly. | 69 bool GetValue(const std::string& name, |
71 bool GetValue(const std::string& name, Value** out_value) const; | 70 Value::ValueType type, |
72 | 71 Value** out_value) const; |
73 // Adds a preference to the mapping of names to types. | |
74 void RegisterPreferenceType(const std::string& name, Value::ValueType type); | |
75 | |
76 // Gets the registered value type for the given preference name. Returns | |
77 // Value::TYPE_NULL if the preference has never been registered. | |
78 Value::ValueType GetRegisteredType(const std::string& name) const; | |
79 | |
80 // Returns true if the PrefValueStore contains the given preference (i.e., | |
81 // it's been registered), and a value with the correct type has been actively | |
82 // set in some pref store. The application default specified when the pref was | |
83 // registered does not count as an "actively set" value, but another pref | |
84 // store setting a value that happens to be equal to the default does. | |
85 bool HasPrefPath(const char* name) const; | |
86 | 72 |
87 // These methods return true if a preference with the given name is in the | 73 // These methods return true if a preference with the given name is in the |
88 // indicated pref store, even if that value is currently being overridden by | 74 // indicated pref store, even if that value is currently being overridden by |
89 // a higher-priority source. | 75 // a higher-priority source. |
90 bool PrefValueInManagedPlatformStore(const char* name) const; | 76 bool PrefValueInManagedPlatformStore(const char* name) const; |
91 bool PrefValueInDeviceManagementStore(const char* name) const; | 77 bool PrefValueInDeviceManagementStore(const char* name) const; |
92 bool PrefValueInExtensionStore(const char* name) const; | 78 bool PrefValueInExtensionStore(const char* name) const; |
93 bool PrefValueInUserStore(const char* name) const; | 79 bool PrefValueInUserStore(const char* name) const; |
94 | 80 |
95 // These methods return true if a preference with the given name is actually | 81 // These methods return true if a preference with the given name is actually |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 | 134 |
149 private: | 135 private: |
150 // PrefStore::Observer implementation. | 136 // PrefStore::Observer implementation. |
151 virtual void OnPrefValueChanged(const std::string& key); | 137 virtual void OnPrefValueChanged(const std::string& key); |
152 virtual void OnInitializationCompleted(); | 138 virtual void OnInitializationCompleted(); |
153 | 139 |
154 // PrefValueStore this keeper is part of. | 140 // PrefValueStore this keeper is part of. |
155 PrefValueStore* pref_value_store_; | 141 PrefValueStore* pref_value_store_; |
156 | 142 |
157 // The PrefStore managed by this keeper. | 143 // The PrefStore managed by this keeper. |
158 scoped_ptr<PrefStore> pref_store_; | 144 scoped_refptr<PrefStore> pref_store_; |
159 | 145 |
160 // Type of the pref store. | 146 // Type of the pref store. |
161 PrefStoreType type_; | 147 PrefStoreType type_; |
162 | 148 |
163 DISALLOW_COPY_AND_ASSIGN(PrefStoreKeeper); | 149 DISALLOW_COPY_AND_ASSIGN(PrefStoreKeeper); |
164 }; | 150 }; |
165 | 151 |
166 typedef std::map<std::string, Value::ValueType> PrefTypeMap; | 152 typedef std::map<std::string, Value::ValueType> PrefTypeMap; |
167 | 153 |
168 friend class PrefValueStorePolicyRefreshTest; | 154 friend class PrefValueStorePolicyRefreshTest; |
169 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, TestPolicyRefresh); | 155 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, TestPolicyRefresh); |
170 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, | 156 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, |
171 TestRefreshPolicyPrefsCompletion); | 157 TestRefreshPolicyPrefsCompletion); |
172 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, | 158 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, |
173 TestConcurrentPolicyRefresh); | 159 TestConcurrentPolicyRefresh); |
174 | 160 |
175 // Returns true if the actual type is a valid type for the expected type when | |
176 // found in the given store. | |
177 static bool IsValidType(Value::ValueType expected, | |
178 Value::ValueType actual, | |
179 PrefStoreType store); | |
180 | |
181 // Returns true if the preference with the given name has a value in the | 161 // Returns true if the preference with the given name has a value in the |
182 // given PrefStoreType, of the same value type as the preference was | 162 // given PrefStoreType, of the same value type as the preference was |
183 // registered with. | 163 // registered with. |
184 bool PrefValueInStore(const char* name, PrefStoreType store) const; | 164 bool PrefValueInStore(const char* name, PrefStoreType store) const; |
185 | 165 |
186 // Returns true if a preference has an explicit value in any of the | 166 // Returns true if a preference has an explicit value in any of the |
187 // stores in the range specified by |first_checked_store| and | 167 // stores in the range specified by |first_checked_store| and |
188 // |last_checked_store|, even if that value is currently being | 168 // |last_checked_store|, even if that value is currently being |
189 // overridden by a higher-priority store. | 169 // overridden by a higher-priority store. |
190 bool PrefValueInStoreRange(const char* name, | 170 bool PrefValueInStoreRange(const char* name, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 // corresponding PrefService. | 221 // corresponding PrefService. |
242 PrefNotifier* pref_notifier_; | 222 PrefNotifier* pref_notifier_; |
243 | 223 |
244 // A mapping of preference names to their registered types. | 224 // A mapping of preference names to their registered types. |
245 PrefTypeMap pref_types_; | 225 PrefTypeMap pref_types_; |
246 | 226 |
247 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); | 227 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); |
248 }; | 228 }; |
249 | 229 |
250 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ | 230 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ |
OLD | NEW |