OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Chromium settings and storage represent user-selected preferences and | 7 // Chromium settings and storage represent user-selected preferences and |
8 // information and MUST not be extracted, overwritten or modified except | 8 // information and MUST not be extracted, overwritten or modified except |
9 // through Chromium defined APIs. | 9 // through Chromium defined APIs. |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 class PrefNotifierImpl; | 32 class PrefNotifierImpl; |
33 class PrefObserver; | 33 class PrefObserver; |
34 class PrefRegistry; | 34 class PrefRegistry; |
35 class PrefValueStore; | 35 class PrefValueStore; |
36 class PrefStore; | 36 class PrefStore; |
37 | 37 |
38 namespace base { | 38 namespace base { |
39 class FilePath; | 39 class FilePath; |
40 } | 40 } |
41 | 41 |
| 42 namespace prefs { |
| 43 class ScopedDictionaryPrefUpdate; |
| 44 } |
| 45 |
42 namespace subtle { | 46 namespace subtle { |
43 class PrefMemberBase; | 47 class PrefMemberBase; |
44 class ScopedUserPrefUpdateBase; | 48 class ScopedUserPrefUpdateBase; |
45 } | 49 } |
46 | 50 |
47 // Base class for PrefServices. You can use the base class to read and | 51 // Base class for PrefServices. You can use the base class to read and |
48 // interact with preferences, but not to register new preferences; for | 52 // interact with preferences, but not to register new preferences; for |
49 // that see e.g. PrefRegistrySimple. | 53 // that see e.g. PrefRegistrySimple. |
50 // | 54 // |
51 // Settings and storage accessed through this class represent | 55 // Settings and storage accessed through this class represent |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 private: | 324 private: |
321 // Hash map expected to be fastest here since it minimises expensive | 325 // Hash map expected to be fastest here since it minimises expensive |
322 // string comparisons. Order is unimportant, and deletions are rare. | 326 // string comparisons. Order is unimportant, and deletions are rare. |
323 // Confirmed on Android where this speeded Chrome startup by roughly 50ms | 327 // Confirmed on Android where this speeded Chrome startup by roughly 50ms |
324 // vs. std::map, and by roughly 180ms vs. std::set of Preference pointers. | 328 // vs. std::map, and by roughly 180ms vs. std::set of Preference pointers. |
325 typedef base::hash_map<std::string, Preference> PreferenceMap; | 329 typedef base::hash_map<std::string, Preference> PreferenceMap; |
326 | 330 |
327 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). | 331 // Give access to ReportUserPrefChanged() and GetMutableUserPref(). |
328 friend class subtle::ScopedUserPrefUpdateBase; | 332 friend class subtle::ScopedUserPrefUpdateBase; |
329 friend class PrefServiceTest_WriteablePrefStoreFlags_Test; | 333 friend class PrefServiceTest_WriteablePrefStoreFlags_Test; |
| 334 friend class prefs::ScopedDictionaryPrefUpdate; |
330 | 335 |
331 // Registration of pref change observers must be done using the | 336 // Registration of pref change observers must be done using the |
332 // PrefChangeRegistrar, which is declared as a friend here to grant it | 337 // PrefChangeRegistrar, which is declared as a friend here to grant it |
333 // access to the otherwise protected members Add/RemovePrefObserver. | 338 // access to the otherwise protected members Add/RemovePrefObserver. |
334 // PrefMember registers for preferences changes notification directly to | 339 // PrefMember registers for preferences changes notification directly to |
335 // avoid the storage overhead of the registrar, so its base class must be | 340 // avoid the storage overhead of the registrar, so its base class must be |
336 // declared as a friend, too. | 341 // declared as a friend, too. |
337 friend class PrefChangeRegistrar; | 342 friend class PrefChangeRegistrar; |
338 friend class subtle::PrefMemberBase; | 343 friend class subtle::PrefMemberBase; |
339 | 344 |
340 // These are protected so they can only be accessed by the friend | 345 // These are protected so they can only be accessed by the friend |
341 // classes listed above. | 346 // classes listed above. |
342 // | 347 // |
343 // If the pref at the given path changes, we call the observer's | 348 // If the pref at the given path changes, we call the observer's |
344 // OnPreferenceChanged method. Note that observers should not call | 349 // OnPreferenceChanged method. Note that observers should not call |
345 // these methods directly but rather use a PrefChangeRegistrar to | 350 // these methods directly but rather use a PrefChangeRegistrar to |
346 // make sure the observer gets cleaned up properly. | 351 // make sure the observer gets cleaned up properly. |
347 // | 352 // |
348 // Virtual for testing. | 353 // Virtual for testing. |
349 virtual void AddPrefObserver(const std::string& path, PrefObserver* obs); | 354 virtual void AddPrefObserver(const std::string& path, PrefObserver* obs); |
350 virtual void RemovePrefObserver(const std::string& path, PrefObserver* obs); | 355 virtual void RemovePrefObserver(const std::string& path, PrefObserver* obs); |
351 | 356 |
352 // Sends notification of a changed preference. This needs to be called by | 357 // Sends notification of a changed preference. This needs to be called by |
353 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. | 358 // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed. |
354 void ReportUserPrefChanged(const std::string& key); | 359 void ReportUserPrefChanged(const std::string& key); |
| 360 void ReportUserPrefChanged( |
| 361 const std::string& key, |
| 362 std::set<std::vector<std::string>> path_components); |
355 | 363 |
356 // Sets the value for this pref path in the user pref store and informs the | 364 // Sets the value for this pref path in the user pref store and informs the |
357 // PrefNotifier of the change. | 365 // PrefNotifier of the change. |
358 void SetUserPrefValue(const std::string& path, | 366 void SetUserPrefValue(const std::string& path, |
359 std::unique_ptr<base::Value> new_value); | 367 std::unique_ptr<base::Value> new_value); |
360 | 368 |
361 // Load preferences from storage, attempting to diagnose and handle errors. | 369 // Load preferences from storage, attempting to diagnose and handle errors. |
362 // This should only be called from the constructor. | 370 // This should only be called from the constructor. |
363 void InitFromStorage(bool async); | 371 void InitFromStorage(bool async); |
364 | 372 |
(...skipping 16 matching lines...) Expand all Loading... |
381 | 389 |
382 // Local cache of registered Preference objects. The pref_registry_ | 390 // Local cache of registered Preference objects. The pref_registry_ |
383 // is authoritative with respect to what the types and default values | 391 // is authoritative with respect to what the types and default values |
384 // of registered preferences are. | 392 // of registered preferences are. |
385 mutable PreferenceMap prefs_map_; | 393 mutable PreferenceMap prefs_map_; |
386 | 394 |
387 DISALLOW_COPY_AND_ASSIGN(PrefService); | 395 DISALLOW_COPY_AND_ASSIGN(PrefService); |
388 }; | 396 }; |
389 | 397 |
390 #endif // COMPONENTS_PREFS_PREF_SERVICE_H_ | 398 #endif // COMPONENTS_PREFS_PREF_SERVICE_H_ |
OLD | NEW |