| 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_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/callback.h" | 14 #include "base/callback.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/scoped_ptr.h" | |
| 18 #include "base/values.h" | 17 #include "base/values.h" |
| 19 #include "chrome/browser/browser_thread.h" | 18 #include "chrome/browser/browser_thread.h" |
| 20 #include "chrome/common/notification_observer.h" | 19 #include "chrome/common/notification_observer.h" |
| 21 #include "chrome/common/notification_registrar.h" | 20 #include "chrome/common/notification_registrar.h" |
| 22 #include "chrome/common/pref_store.h" | 21 #include "chrome/common/pref_store.h" |
| 23 | 22 |
| 24 class FilePath; | 23 class FilePath; |
| 25 class PrefNotifier; | 24 class PrefNotifier; |
| 26 class PrefStore; | 25 class PrefStore; |
| 27 class Profile; | 26 class Profile; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 PrefStore* device_management_prefs, | 69 PrefStore* device_management_prefs, |
| 71 PrefStore* extension_prefs, | 70 PrefStore* extension_prefs, |
| 72 PrefStore* command_line_prefs, | 71 PrefStore* command_line_prefs, |
| 73 PrefStore* user_prefs, | 72 PrefStore* user_prefs, |
| 74 PrefStore* recommended_prefs, | 73 PrefStore* recommended_prefs, |
| 75 PrefStore* default_prefs, | 74 PrefStore* default_prefs, |
| 76 PrefNotifier* pref_notifier, | 75 PrefNotifier* pref_notifier, |
| 77 Profile* profile); | 76 Profile* profile); |
| 78 virtual ~PrefValueStore(); | 77 virtual ~PrefValueStore(); |
| 79 | 78 |
| 80 // Gets the value for the given preference name that has a valid value type; | 79 // Gets the value for the given preference name that has the specified value |
| 81 // that is, the same type the preference was registered with, or NULL for | 80 // type. Returns true if a valid value was found in any of the available |
| 82 // default values of Dictionaries and Lists. Returns true if a valid value | 81 // PrefStores. Most callers should use Preference::GetValue() instead of |
| 83 // was found in any of the available PrefStores. Most callers should use | 82 // calling this method directly. |
| 84 // Preference::GetValue() instead of calling this method directly. | 83 bool GetValue(const std::string& name, |
| 85 bool GetValue(const std::string& name, Value** out_value) const; | 84 Value::ValueType type, |
| 86 | 85 Value** out_value) const; |
| 87 // Adds a preference to the mapping of names to types. | |
| 88 void RegisterPreferenceType(const std::string& name, Value::ValueType type); | |
| 89 | |
| 90 // Gets the registered value type for the given preference name. Returns | |
| 91 // Value::TYPE_NULL if the preference has never been registered. | |
| 92 Value::ValueType GetRegisteredType(const std::string& name) const; | |
| 93 | |
| 94 // Returns true if the PrefValueStore contains the given preference (i.e., | |
| 95 // it's been registered), and a value with the correct type has been actively | |
| 96 // set in some pref store. The application default specified when the pref was | |
| 97 // registered does not count as an "actively set" value, but another pref | |
| 98 // store setting a value that happens to be equal to the default does. | |
| 99 bool HasPrefPath(const char* name) const; | |
| 100 | 86 |
| 101 // These methods return true if a preference with the given name is in the | 87 // These methods return true if a preference with the given name is in the |
| 102 // indicated pref store, even if that value is currently being overridden by | 88 // indicated pref store, even if that value is currently being overridden by |
| 103 // a higher-priority source. | 89 // a higher-priority source. |
| 104 bool PrefValueInManagedPlatformStore(const char* name) const; | 90 bool PrefValueInManagedPlatformStore(const char* name) const; |
| 105 bool PrefValueInDeviceManagementStore(const char* name) const; | 91 bool PrefValueInDeviceManagementStore(const char* name) const; |
| 106 bool PrefValueInExtensionStore(const char* name) const; | 92 bool PrefValueInExtensionStore(const char* name) const; |
| 107 bool PrefValueInUserStore(const char* name) const; | 93 bool PrefValueInUserStore(const char* name) const; |
| 108 | 94 |
| 109 // These methods return true if a preference with the given name is actually | 95 // 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... |
| 162 | 148 |
| 163 private: | 149 private: |
| 164 // PrefStore::Observer implementation. | 150 // PrefStore::Observer implementation. |
| 165 virtual void OnPrefValueChanged(const std::string& key); | 151 virtual void OnPrefValueChanged(const std::string& key); |
| 166 virtual void OnInitializationCompleted(); | 152 virtual void OnInitializationCompleted(); |
| 167 | 153 |
| 168 // PrefValueStore this keeper is part of. | 154 // PrefValueStore this keeper is part of. |
| 169 PrefValueStore* pref_value_store_; | 155 PrefValueStore* pref_value_store_; |
| 170 | 156 |
| 171 // The PrefStore managed by this keeper. | 157 // The PrefStore managed by this keeper. |
| 172 scoped_ptr<PrefStore> pref_store_; | 158 scoped_refptr<PrefStore> pref_store_; |
| 173 | 159 |
| 174 // Type of the pref store. | 160 // Type of the pref store. |
| 175 PrefStoreType type_; | 161 PrefStoreType type_; |
| 176 | 162 |
| 177 DISALLOW_COPY_AND_ASSIGN(PrefStoreKeeper); | 163 DISALLOW_COPY_AND_ASSIGN(PrefStoreKeeper); |
| 178 }; | 164 }; |
| 179 | 165 |
| 180 typedef std::map<std::string, Value::ValueType> PrefTypeMap; | 166 typedef std::map<std::string, Value::ValueType> PrefTypeMap; |
| 181 | 167 |
| 182 friend class PrefValueStorePolicyRefreshTest; | 168 friend class PrefValueStorePolicyRefreshTest; |
| 183 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, TestPolicyRefresh); | 169 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, TestPolicyRefresh); |
| 184 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, | 170 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, |
| 185 TestRefreshPolicyPrefsCompletion); | 171 TestRefreshPolicyPrefsCompletion); |
| 186 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, | 172 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, |
| 187 TestConcurrentPolicyRefresh); | 173 TestConcurrentPolicyRefresh); |
| 188 | 174 |
| 189 // Returns true if the actual type is a valid type for the expected type when | |
| 190 // found in the given store. | |
| 191 static bool IsValidType(Value::ValueType expected, | |
| 192 Value::ValueType actual, | |
| 193 PrefStoreType store); | |
| 194 | |
| 195 // Returns true if the preference with the given name has a value in the | 175 // Returns true if the preference with the given name has a value in the |
| 196 // given PrefStoreType, of the same value type as the preference was | 176 // given PrefStoreType, of the same value type as the preference was |
| 197 // registered with. | 177 // registered with. |
| 198 bool PrefValueInStore(const char* name, PrefStoreType store) const; | 178 bool PrefValueInStore(const char* name, PrefStoreType store) const; |
| 199 | 179 |
| 200 // Returns true if a preference has an explicit value in any of the | 180 // Returns true if a preference has an explicit value in any of the |
| 201 // stores in the range specified by |first_checked_store| and | 181 // stores in the range specified by |first_checked_store| and |
| 202 // |last_checked_store|, even if that value is currently being | 182 // |last_checked_store|, even if that value is currently being |
| 203 // overridden by a higher-priority store. | 183 // overridden by a higher-priority store. |
| 204 bool PrefValueInStoreRange(const char* name, | 184 bool PrefValueInStoreRange(const char* name, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 233 // ownership of the |callback| object. | 213 // ownership of the |callback| object. |
| 234 void RefreshPolicyPrefsCompletion( | 214 void RefreshPolicyPrefsCompletion( |
| 235 policy::ConfigurationPolicyPrefStore* new_managed_platform_pref_store, | 215 policy::ConfigurationPolicyPrefStore* new_managed_platform_pref_store, |
| 236 policy::ConfigurationPolicyPrefStore* new_device_management_pref_store, | 216 policy::ConfigurationPolicyPrefStore* new_device_management_pref_store, |
| 237 policy::ConfigurationPolicyPrefStore* new_recommended_pref_store); | 217 policy::ConfigurationPolicyPrefStore* new_recommended_pref_store); |
| 238 | 218 |
| 239 // Called during policy refresh to do the ReadPrefs on the FILE thread. | 219 // Called during policy refresh to do the ReadPrefs on the FILE thread. |
| 240 // RefreshPolicyPrefsOnFileThread takes ownership of the |callback| object. | 220 // RefreshPolicyPrefsOnFileThread takes ownership of the |callback| object. |
| 241 void RefreshPolicyPrefsOnFileThread( | 221 void RefreshPolicyPrefsOnFileThread( |
| 242 BrowserThread::ID calling_thread_id, | 222 BrowserThread::ID calling_thread_id, |
| 243 policy::ConfigurationPolicyPrefStore* new_managed_platform_pref_store, | 223 scoped_refptr<policy::ConfigurationPolicyPrefStore> |
| 244 policy::ConfigurationPolicyPrefStore* new_device_management_pref_store, | 224 new_managed_platform_pref_store, |
| 245 policy::ConfigurationPolicyPrefStore* new_recommended_pref_store); | 225 scoped_refptr<policy::ConfigurationPolicyPrefStore> |
| 226 new_device_management_pref_store, |
| 227 scoped_refptr<policy::ConfigurationPolicyPrefStore> |
| 228 _new_recommended_pref_store); |
| 246 | 229 |
| 247 // NotificationObserver methods: | 230 // NotificationObserver methods: |
| 248 virtual void Observe(NotificationType type, | 231 virtual void Observe(NotificationType type, |
| 249 const NotificationSource& source, | 232 const NotificationSource& source, |
| 250 const NotificationDetails& details); | 233 const NotificationDetails& details); |
| 251 | 234 |
| 252 // Called from the PrefStoreKeeper implementation when a pref value for |key| | 235 // Called from the PrefStoreKeeper implementation when a pref value for |key| |
| 253 // changed in the pref store for |type|. | 236 // changed in the pref store for |type|. |
| 254 void OnPrefValueChanged(PrefStoreType type, const std::string& key); | 237 void OnPrefValueChanged(PrefStoreType type, const std::string& key); |
| 255 | 238 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 274 } | 257 } |
| 275 | 258 |
| 276 // Keeps the PrefStore references in order of precedence. | 259 // Keeps the PrefStore references in order of precedence. |
| 277 PrefStoreKeeper pref_stores_[PREF_STORE_TYPE_MAX + 1]; | 260 PrefStoreKeeper pref_stores_[PREF_STORE_TYPE_MAX + 1]; |
| 278 | 261 |
| 279 // Used for generating PREF_CHANGED and PREF_INITIALIZATION_COMPLETED | 262 // Used for generating PREF_CHANGED and PREF_INITIALIZATION_COMPLETED |
| 280 // notifications. This is a weak reference, since the notifier is owned by the | 263 // notifications. This is a weak reference, since the notifier is owned by the |
| 281 // corresponding PrefService. | 264 // corresponding PrefService. |
| 282 PrefNotifier* pref_notifier_; | 265 PrefNotifier* pref_notifier_; |
| 283 | 266 |
| 284 // A mapping of preference names to their registered types. | |
| 285 PrefTypeMap pref_types_; | |
| 286 | |
| 287 // The associated profile, in case this value store is associated with a | 267 // The associated profile, in case this value store is associated with a |
| 288 // profile pref service. Used for recreating the device management pref store | 268 // profile pref service. Used for recreating the device management pref store |
| 289 // upon policy refresh. | 269 // upon policy refresh. |
| 290 Profile* profile_; | 270 Profile* profile_; |
| 291 | 271 |
| 292 // TODO(mnissler): Remove this after cleaning up policy refresh handling. | 272 // TODO(mnissler): Remove this after cleaning up policy refresh handling. |
| 293 NotificationRegistrar registrar_; | 273 NotificationRegistrar registrar_; |
| 294 | 274 |
| 295 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); | 275 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); |
| 296 }; | 276 }; |
| 297 | 277 |
| 298 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ | 278 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ |
| OLD | NEW |