| 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 // Creates a clone of this PrefValueStore with PrefStores overwritten |
| 67 // that is, the same type the preference was registered with, or NULL for | 66 // by the parameters passed, if unequal NULL. |
| 68 // default values of Dictionaries and Lists. Returns true if a valid value | 67 PrefValueStore* CloneAndSpecialize(PrefStore* managed_platform_prefs, |
| 68 PrefStore* device_management_prefs, |
| 69 PrefStore* extension_prefs, |
| 70 PrefStore* command_line_prefs, |
| 71 PrefStore* user_prefs, |
| 72 PrefStore* recommended_prefs, |
| 73 PrefStore* default_prefs, |
| 74 PrefNotifier* pref_notifier); |
| 75 |
| 76 // Gets the value for the given preference name that has the specified value |
| 77 // type. Values stored in a PrefStore that have the matching |name| but |
| 78 // a non-matching |type| are silently skipped. Returns true if a valid value |
| 69 // was found in any of the available PrefStores. Most callers should use | 79 // was found in any of the available PrefStores. Most callers should use |
| 70 // Preference::GetValue() instead of calling this method directly. | 80 // Preference::GetValue() instead of calling this method directly. |
| 71 bool GetValue(const std::string& name, Value** out_value) const; | 81 bool GetValue(const std::string& name, |
| 72 | 82 Value::ValueType type, |
| 73 // Adds a preference to the mapping of names to types. | 83 Value** out_value) const; |
| 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 | 84 |
| 87 // These methods return true if a preference with the given name is in the | 85 // 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 | 86 // indicated pref store, even if that value is currently being overridden by |
| 89 // a higher-priority source. | 87 // a higher-priority source. |
| 90 bool PrefValueInManagedPlatformStore(const char* name) const; | 88 bool PrefValueInManagedPlatformStore(const char* name) const; |
| 91 bool PrefValueInDeviceManagementStore(const char* name) const; | 89 bool PrefValueInDeviceManagementStore(const char* name) const; |
| 92 bool PrefValueInExtensionStore(const char* name) const; | 90 bool PrefValueInExtensionStore(const char* name) const; |
| 93 bool PrefValueInUserStore(const char* name) const; | 91 bool PrefValueInUserStore(const char* name) const; |
| 94 | 92 |
| 95 // These methods return true if a preference with the given name is actually | 93 // 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 | 146 |
| 149 private: | 147 private: |
| 150 // PrefStore::Observer implementation. | 148 // PrefStore::Observer implementation. |
| 151 virtual void OnPrefValueChanged(const std::string& key); | 149 virtual void OnPrefValueChanged(const std::string& key); |
| 152 virtual void OnInitializationCompleted(); | 150 virtual void OnInitializationCompleted(); |
| 153 | 151 |
| 154 // PrefValueStore this keeper is part of. | 152 // PrefValueStore this keeper is part of. |
| 155 PrefValueStore* pref_value_store_; | 153 PrefValueStore* pref_value_store_; |
| 156 | 154 |
| 157 // The PrefStore managed by this keeper. | 155 // The PrefStore managed by this keeper. |
| 158 scoped_ptr<PrefStore> pref_store_; | 156 scoped_refptr<PrefStore> pref_store_; |
| 159 | 157 |
| 160 // Type of the pref store. | 158 // Type of the pref store. |
| 161 PrefStoreType type_; | 159 PrefStoreType type_; |
| 162 | 160 |
| 163 DISALLOW_COPY_AND_ASSIGN(PrefStoreKeeper); | 161 DISALLOW_COPY_AND_ASSIGN(PrefStoreKeeper); |
| 164 }; | 162 }; |
| 165 | 163 |
| 166 typedef std::map<std::string, Value::ValueType> PrefTypeMap; | 164 typedef std::map<std::string, Value::ValueType> PrefTypeMap; |
| 167 | 165 |
| 168 friend class PrefValueStorePolicyRefreshTest; | 166 friend class PrefValueStorePolicyRefreshTest; |
| 169 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, TestPolicyRefresh); | 167 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, TestPolicyRefresh); |
| 170 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, | 168 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, |
| 171 TestRefreshPolicyPrefsCompletion); | 169 TestRefreshPolicyPrefsCompletion); |
| 172 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, | 170 FRIEND_TEST_ALL_PREFIXES(PrefValueStorePolicyRefreshTest, |
| 173 TestConcurrentPolicyRefresh); | 171 TestConcurrentPolicyRefresh); |
| 174 | 172 |
| 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 | 173 // 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 | 174 // given PrefStoreType, of the same value type as the preference was |
| 183 // registered with. | 175 // registered with. |
| 184 bool PrefValueInStore(const char* name, PrefStoreType store) const; | 176 bool PrefValueInStore(const char* name, PrefStoreType store) const; |
| 185 | 177 |
| 186 // Returns true if a preference has an explicit value in any of the | 178 // Returns true if a preference has an explicit value in any of the |
| 187 // stores in the range specified by |first_checked_store| and | 179 // stores in the range specified by |first_checked_store| and |
| 188 // |last_checked_store|, even if that value is currently being | 180 // |last_checked_store|, even if that value is currently being |
| 189 // overridden by a higher-priority store. | 181 // overridden by a higher-priority store. |
| 190 bool PrefValueInStoreRange(const char* name, | 182 bool PrefValueInStoreRange(const char* name, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // corresponding PrefService. | 233 // corresponding PrefService. |
| 242 PrefNotifier* pref_notifier_; | 234 PrefNotifier* pref_notifier_; |
| 243 | 235 |
| 244 // A mapping of preference names to their registered types. | 236 // A mapping of preference names to their registered types. |
| 245 PrefTypeMap pref_types_; | 237 PrefTypeMap pref_types_; |
| 246 | 238 |
| 247 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); | 239 DISALLOW_COPY_AND_ASSIGN(PrefValueStore); |
| 248 }; | 240 }; |
| 249 | 241 |
| 250 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ | 242 #endif // CHROME_BROWSER_PREFS_PREF_VALUE_STORE_H_ |
| OLD | NEW |