OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // A helper class that assists preferences in firing notifications when lists | 5 // A helper class that assists preferences in firing notifications when lists |
6 // or dictionaries are changed. | 6 // or dictionaries are changed. |
7 | 7 |
8 #ifndef BASE_PREFS_SCOPED_USER_PREF_UPDATE_H_ | 8 #ifndef BASE_PREFS_SCOPED_USER_PREF_UPDATE_H_ |
9 #define BASE_PREFS_SCOPED_USER_PREF_UPDATE_H_ | 9 #define BASE_PREFS_SCOPED_USER_PREF_UPDATE_H_ |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace subtle { | 26 namespace subtle { |
27 | 27 |
28 // Base class for ScopedUserPrefUpdateTemplate that contains the parts | 28 // Base class for ScopedUserPrefUpdateTemplate that contains the parts |
29 // that do not depend on ScopedUserPrefUpdateTemplate's template parameter. | 29 // that do not depend on ScopedUserPrefUpdateTemplate's template parameter. |
30 // | 30 // |
31 // We need this base class mostly for making it a friend of PrefService | 31 // We need this base class mostly for making it a friend of PrefService |
32 // and getting access to PrefService::GetMutableUserPref and | 32 // and getting access to PrefService::GetMutableUserPref and |
33 // PrefService::ReportUserPrefChanged. | 33 // PrefService::ReportUserPrefChanged. |
34 class BASE_PREFS_EXPORT ScopedUserPrefUpdateBase : public base::NonThreadSafe { | 34 class BASE_PREFS_EXPORT ScopedUserPrefUpdateBase : public base::NonThreadSafe { |
35 protected: | 35 protected: |
36 ScopedUserPrefUpdateBase(PrefService* service, const char* path); | 36 ScopedUserPrefUpdateBase(PrefService* service, const std::string& path); |
37 | 37 |
38 // Calls Notify(). | 38 // Calls Notify(). |
39 ~ScopedUserPrefUpdateBase(); | 39 ~ScopedUserPrefUpdateBase(); |
40 | 40 |
41 // Sets |value_| to |service_|->GetMutableUserPref and returns it. | 41 // Sets |value_| to |service_|->GetMutableUserPref and returns it. |
42 base::Value* GetValueOfType(base::Value::Type type); | 42 base::Value* GetValueOfType(base::Value::Type type); |
43 | 43 |
44 private: | 44 private: |
45 // If |value_| is not null, triggers a notification of PrefObservers and | 45 // If |value_| is not null, triggers a notification of PrefObservers and |
46 // resets |value_|. | 46 // resets |value_|. |
(...skipping 12 matching lines...) Expand all Loading... |
59 } // namespace subtle | 59 } // namespace subtle |
60 | 60 |
61 // Class to support modifications to DictionaryValues and ListValues while | 61 // Class to support modifications to DictionaryValues and ListValues while |
62 // guaranteeing that PrefObservers are notified of changed values. | 62 // guaranteeing that PrefObservers are notified of changed values. |
63 // | 63 // |
64 // This class may only be used on the UI thread as it requires access to the | 64 // This class may only be used on the UI thread as it requires access to the |
65 // PrefService. | 65 // PrefService. |
66 template <typename T, base::Value::Type type_enum_value> | 66 template <typename T, base::Value::Type type_enum_value> |
67 class ScopedUserPrefUpdate : public subtle::ScopedUserPrefUpdateBase { | 67 class ScopedUserPrefUpdate : public subtle::ScopedUserPrefUpdateBase { |
68 public: | 68 public: |
69 ScopedUserPrefUpdate(PrefService* service, const char* path) | 69 ScopedUserPrefUpdate(PrefService* service, const std::string& path) |
70 : ScopedUserPrefUpdateBase(service, path) {} | 70 : ScopedUserPrefUpdateBase(service, path) {} |
71 | 71 |
72 // Triggers an update notification if Get() was called. | 72 // Triggers an update notification if Get() was called. |
73 virtual ~ScopedUserPrefUpdate() {} | 73 virtual ~ScopedUserPrefUpdate() {} |
74 | 74 |
75 // Returns a mutable |T| instance that | 75 // Returns a mutable |T| instance that |
76 // - is already in the user pref store, or | 76 // - is already in the user pref store, or |
77 // - is (silently) created and written to the user pref store if none existed | 77 // - is (silently) created and written to the user pref store if none existed |
78 // before. | 78 // before. |
79 // | 79 // |
(...skipping 19 matching lines...) Expand all Loading... |
99 DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdate); | 99 DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdate); |
100 }; | 100 }; |
101 | 101 |
102 typedef ScopedUserPrefUpdate<base::DictionaryValue, | 102 typedef ScopedUserPrefUpdate<base::DictionaryValue, |
103 base::Value::TYPE_DICTIONARY> | 103 base::Value::TYPE_DICTIONARY> |
104 DictionaryPrefUpdate; | 104 DictionaryPrefUpdate; |
105 typedef ScopedUserPrefUpdate<base::ListValue, base::Value::TYPE_LIST> | 105 typedef ScopedUserPrefUpdate<base::ListValue, base::Value::TYPE_LIST> |
106 ListPrefUpdate; | 106 ListPrefUpdate; |
107 | 107 |
108 #endif // BASE_PREFS_SCOPED_USER_PREF_UPDATE_H_ | 108 #endif // BASE_PREFS_SCOPED_USER_PREF_UPDATE_H_ |
OLD | NEW |