Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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 // This provides a way to access the application's current preferences. | 5 // This provides a way to access the application's current preferences. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 7 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| 8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/common/json_pref_store.h" | 18 #include "chrome/common/json_pref_store.h" |
| 19 | 19 |
| 20 class DefaultPrefStore; | 20 class DefaultPrefStore; |
| 21 class FilePath; | 21 class FilePath; |
| 22 class NotificationObserver; | 22 class NotificationObserver; |
| 23 class PersistentPrefStore; | 23 class PersistentPrefStore; |
| 24 class PrefChangeObserver; | 24 class PrefModelAssociator; |
| 25 class PrefNotifier; | 25 class PrefNotifier; |
| 26 class PrefNotifierImpl; | 26 class PrefNotifierImpl; |
| 27 class PrefStore; | 27 class PrefStore; |
| 28 class PrefValueStore; | 28 class PrefValueStore; |
| 29 class Profile; | 29 class Profile; |
| 30 class SyncableService; | |
| 30 | 31 |
| 31 namespace subtle { | 32 namespace subtle { |
| 32 class PrefMemberBase; | 33 class PrefMemberBase; |
| 33 class ScopedUserPrefUpdateBase; | 34 class ScopedUserPrefUpdateBase; |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 class PrefService; | 37 class PrefService; |
| 37 | 38 |
| 38 class PrefServiceDelegate { | 39 class PrefServiceDelegate { |
| 39 public: | 40 public: |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 // we need to save immediately (basically, during shutdown). Otherwise, you | 165 // we need to save immediately (basically, during shutdown). Otherwise, you |
| 165 // should use ScheduleSavePersistentPrefs. | 166 // should use ScheduleSavePersistentPrefs. |
| 166 bool SavePersistentPrefs(); | 167 bool SavePersistentPrefs(); |
| 167 | 168 |
| 168 // Serializes the data and schedules save using ImportantFileWriter. | 169 // Serializes the data and schedules save using ImportantFileWriter. |
| 169 void ScheduleSavePersistentPrefs(); | 170 void ScheduleSavePersistentPrefs(); |
| 170 | 171 |
| 171 // Lands pending writes to disk. | 172 // Lands pending writes to disk. |
| 172 void CommitPendingWrite(); | 173 void CommitPendingWrite(); |
| 173 | 174 |
| 174 // Make the PrefService aware of a pref. | 175 // Make the PrefService aware of a pref, and inform the Sync model associator |
| 175 void RegisterBooleanPref(const char* path, bool default_value); | 176 // if we want to synchronize it. |
| 176 void RegisterIntegerPref(const char* path, int default_value); | 177 void RegisterBooleanPref(const char* path, |
| 177 void RegisterDoublePref(const char* path, double default_value); | 178 bool default_value, |
| 178 void RegisterStringPref(const char* path, const std::string& default_value); | 179 bool syncable); |
| 179 void RegisterFilePathPref(const char* path, const FilePath& default_value); | 180 void RegisterIntegerPref(const char* path, |
| 180 void RegisterListPref(const char* path); | 181 int default_value, |
| 181 void RegisterDictionaryPref(const char* path); | 182 bool syncable); |
| 183 void RegisterDoublePref(const char* path, | |
| 184 double default_value, | |
| 185 bool syncable); | |
| 186 void RegisterStringPref(const char* path, | |
| 187 const std::string& default_value, | |
| 188 bool syncable); | |
| 189 void RegisterFilePathPref(const char* path, | |
| 190 const FilePath& default_value, | |
| 191 bool syncable); | |
| 192 void RegisterListPref(const char* path, bool syncable); | |
| 193 void RegisterDictionaryPref(const char* path, bool syncable); | |
| 182 // These take ownership of the default_value: | 194 // These take ownership of the default_value: |
| 183 void RegisterListPref(const char* path, ListValue* default_value); | 195 void RegisterListPref(const char* path, |
| 184 void RegisterDictionaryPref(const char* path, DictionaryValue* default_value); | 196 ListValue* default_value, |
| 197 bool syncable); | |
| 198 void RegisterDictionaryPref(const char* path, | |
| 199 DictionaryValue* default_value, | |
| 200 bool syncable); | |
| 185 | 201 |
| 186 // These variants use a default value from the locale dll instead. | 202 // These variants use a default value from the locale dll instead. |
| 187 void RegisterLocalizedBooleanPref(const char* path, | 203 void RegisterLocalizedBooleanPref(const char* path, |
| 188 int locale_default_message_id); | 204 int locale_default_message_id, |
| 205 bool syncable); | |
| 189 void RegisterLocalizedIntegerPref(const char* path, | 206 void RegisterLocalizedIntegerPref(const char* path, |
| 190 int locale_default_message_id); | 207 int locale_default_message_id, |
| 208 bool syncable); | |
| 191 void RegisterLocalizedDoublePref(const char* path, | 209 void RegisterLocalizedDoublePref(const char* path, |
| 192 int locale_default_message_id); | 210 int locale_default_message_id, |
| 211 bool syncable); | |
| 193 void RegisterLocalizedStringPref(const char* path, | 212 void RegisterLocalizedStringPref(const char* path, |
| 194 int locale_default_message_id); | 213 int locale_default_message_id, |
| 214 bool syncable); | |
| 195 | 215 |
| 196 // If the path is valid and the value at the end of the path matches the type | 216 // If the path is valid and the value at the end of the path matches the type |
| 197 // specified, it will return the specified value. Otherwise, the default | 217 // specified, it will return the specified value. Otherwise, the default |
| 198 // value (set when the pref was registered) will be returned. | 218 // value (set when the pref was registered) will be returned. |
| 199 bool GetBoolean(const char* path) const; | 219 bool GetBoolean(const char* path) const; |
| 200 int GetInteger(const char* path) const; | 220 int GetInteger(const char* path) const; |
| 201 double GetDouble(const char* path) const; | 221 double GetDouble(const char* path) const; |
| 202 std::string GetString(const char* path) const; | 222 std::string GetString(const char* path) const; |
| 203 FilePath GetFilePath(const char* path) const; | 223 FilePath GetFilePath(const char* path) const; |
| 204 | 224 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 221 void SetInteger(const char* path, int value); | 241 void SetInteger(const char* path, int value); |
| 222 void SetDouble(const char* path, double value); | 242 void SetDouble(const char* path, double value); |
| 223 void SetString(const char* path, const std::string& value); | 243 void SetString(const char* path, const std::string& value); |
| 224 void SetFilePath(const char* path, const FilePath& value); | 244 void SetFilePath(const char* path, const FilePath& value); |
| 225 | 245 |
| 226 // Int64 helper methods that actually store the given value as a string. | 246 // Int64 helper methods that actually store the given value as a string. |
| 227 // Note that if obtaining the named value via GetDictionary or GetList, the | 247 // Note that if obtaining the named value via GetDictionary or GetList, the |
| 228 // Value type will be TYPE_STRING. | 248 // Value type will be TYPE_STRING. |
| 229 void SetInt64(const char* path, int64 value); | 249 void SetInt64(const char* path, int64 value); |
| 230 int64 GetInt64(const char* path) const; | 250 int64 GetInt64(const char* path) const; |
| 231 void RegisterInt64Pref(const char* path, int64 default_value); | 251 void RegisterInt64Pref(const char* path, int64 default_value, bool syncable); |
| 232 | 252 |
| 233 // Returns true if a value has been set for the specified path. | 253 // Returns true if a value has been set for the specified path. |
| 234 // NOTE: this is NOT the same as FindPreference. In particular | 254 // NOTE: this is NOT the same as FindPreference. In particular |
| 235 // FindPreference returns whether RegisterXXX has been invoked, where as | 255 // FindPreference returns whether RegisterXXX has been invoked, where as |
| 236 // this checks if a value exists for the path. | 256 // this checks if a value exists for the path. |
| 237 bool HasPrefPath(const char* path) const; | 257 bool HasPrefPath(const char* path) const; |
| 238 | 258 |
| 239 // Returns a dictionary with effective preference values. The ownership | 259 // Returns a dictionary with effective preference values. The ownership |
| 240 // is passed to the caller. | 260 // is passed to the caller. |
| 241 DictionaryValue* GetPreferenceValues() const; | 261 DictionaryValue* GetPreferenceValues() const; |
| 242 | 262 |
| 243 // A helper method to quickly look up a preference. Returns NULL if the | 263 // A helper method to quickly look up a preference. Returns NULL if the |
| 244 // preference is not registered. | 264 // preference is not registered. |
| 245 const Preference* FindPreference(const char* pref_name) const; | 265 const Preference* FindPreference(const char* pref_name) const; |
| 246 | 266 |
| 247 bool ReadOnly() const; | 267 bool ReadOnly() const; |
| 248 | 268 |
| 269 // SyncableService getter. | |
| 270 // TODO(zea): Have PrefService implement SyncableService directly. | |
| 271 SyncableService* GetSyncableService(); | |
| 272 | |
| 249 protected: | 273 protected: |
| 250 // Construct a new pref service, specifying the pref sources as explicit | 274 // Construct a new pref service, specifying the pref sources as explicit |
| 251 // PrefStore pointers. This constructor is what CreatePrefService() ends up | 275 // PrefStore pointers. This constructor is what CreatePrefService() ends up |
| 252 // calling. It's also used for unit tests. | 276 // calling. It's also used for unit tests. |
| 253 PrefService(PrefStore* managed_platform_prefs, | 277 PrefService(PrefStore* managed_platform_prefs, |
| 254 PrefStore* managed_cloud_prefs, | 278 PrefStore* managed_cloud_prefs, |
| 255 PrefStore* extension_prefs, | 279 PrefStore* extension_prefs, |
| 256 PrefStore* command_line_prefs, | 280 PrefStore* command_line_prefs, |
| 257 PersistentPrefStore* user_prefs, | 281 PersistentPrefStore* user_prefs, |
| 258 PrefStore* recommended_platform_prefs, | 282 PrefStore* recommended_platform_prefs, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 // method with PREF_CHANGED. Note that observers should not call these methods | 325 // method with PREF_CHANGED. Note that observers should not call these methods |
| 302 // directly but rather use a PrefChangeRegistrar to make sure the observer | 326 // directly but rather use a PrefChangeRegistrar to make sure the observer |
| 303 // gets cleaned up properly. | 327 // gets cleaned up properly. |
| 304 virtual void AddPrefObserver(const char* path, NotificationObserver* obs); | 328 virtual void AddPrefObserver(const char* path, NotificationObserver* obs); |
| 305 virtual void RemovePrefObserver(const char* path, NotificationObserver* obs); | 329 virtual void RemovePrefObserver(const char* path, NotificationObserver* obs); |
| 306 | 330 |
| 307 // Registers a new preference at |path|. The |default_value| must not be | 331 // Registers a new preference at |path|. The |default_value| must not be |
| 308 // NULL as it determines the preference value's type. | 332 // NULL as it determines the preference value's type. |
| 309 // RegisterPreference must not be called twice for the same path. | 333 // RegisterPreference must not be called twice for the same path. |
| 310 // This method takes ownership of |default_value|. | 334 // This method takes ownership of |default_value|. |
| 311 void RegisterPreference(const char* path, Value* default_value); | 335 void RegisterPreference(const char* path, |
| 336 Value* default_value, | |
| 337 bool syncable); | |
| 312 | 338 |
| 313 // Sets the value for this pref path in the user pref store and informs the | 339 // Sets the value for this pref path in the user pref store and informs the |
| 314 // PrefNotifier of the change. | 340 // PrefNotifier of the change. |
| 315 void SetUserPrefValue(const char* path, Value* new_value); | 341 void SetUserPrefValue(const char* path, Value* new_value); |
| 316 | 342 |
| 317 // Load preferences from storage, attempting to diagnose and handle errors. | 343 // Load preferences from storage, attempting to diagnose and handle errors. |
| 318 // This should only be called from the constructor. | 344 // This should only be called from the constructor. |
| 319 void InitFromStorage(); | 345 void InitFromStorage(); |
| 320 | 346 |
| 321 // Used to set the value of dictionary or list values in the user pref store. | 347 // Used to set the value of dictionary or list values in the user pref store. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 337 | 363 |
| 338 // Local cache of registered Preference objects. The default_store_ | 364 // Local cache of registered Preference objects. The default_store_ |
| 339 // is authoritative with respect to what the types and default values | 365 // is authoritative with respect to what the types and default values |
| 340 // of registered preferences are. | 366 // of registered preferences are. |
| 341 mutable PreferenceSet prefs_; | 367 mutable PreferenceSet prefs_; |
| 342 | 368 |
| 343 // Holds delegator to be called after initialization, if async version | 369 // Holds delegator to be called after initialization, if async version |
| 344 // is used. | 370 // is used. |
| 345 PrefServiceDelegate* delegate_; | 371 PrefServiceDelegate* delegate_; |
| 346 | 372 |
| 373 // The model associator that maintains the links with the sync db. | |
| 374 scoped_ptr<PrefModelAssociator> pref_sync_associator_; | |
|
Mattias Nissler (ping if slow)
2011/05/06 04:00:02
What's the advantage of adding the PrefModelAssoci
tim (not reviewing)
2011/05/06 04:27:54
Part of this is we're getting rid of our "glue" la
| |
| 375 | |
| 347 DISALLOW_COPY_AND_ASSIGN(PrefService); | 376 DISALLOW_COPY_AND_ASSIGN(PrefService); |
| 348 }; | 377 }; |
| 349 | 378 |
| 350 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 379 #endif // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |
| OLD | NEW |