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 // A helper class that stays in sync with a preference (bool, int, real, | 5 // A helper class that stays in sync with a preference (bool, int, real, |
6 // string or filepath). For example: | 6 // string or filepath). For example: |
7 // | 7 // |
8 // class MyClass { | 8 // class MyClass { |
9 // public: | 9 // public: |
10 // MyClass(PrefService* prefs) { | 10 // MyClass(PrefService* prefs) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 mutable bool is_managed_; | 96 mutable bool is_managed_; |
97 mutable bool is_user_modifiable_; | 97 mutable bool is_user_modifiable_; |
98 | 98 |
99 DISALLOW_COPY_AND_ASSIGN(Internal); | 99 DISALLOW_COPY_AND_ASSIGN(Internal); |
100 }; | 100 }; |
101 | 101 |
102 PrefMemberBase(); | 102 PrefMemberBase(); |
103 virtual ~PrefMemberBase(); | 103 virtual ~PrefMemberBase(); |
104 | 104 |
105 // See PrefMember<> for description. | 105 // See PrefMember<> for description. |
106 void Init(const char* pref_name, PrefService* prefs, | 106 void Init(const std::string& pref_name, |
| 107 PrefService* prefs, |
107 const NamedChangeCallback& observer); | 108 const NamedChangeCallback& observer); |
108 void Init(const char* pref_name, PrefService* prefs); | 109 void Init(const std::string& pref_name, PrefService* prefs); |
109 | 110 |
110 virtual void CreateInternal() const = 0; | 111 virtual void CreateInternal() const = 0; |
111 | 112 |
112 // See PrefMember<> for description. | 113 // See PrefMember<> for description. |
113 void Destroy(); | 114 void Destroy(); |
114 | 115 |
115 void MoveToThread( | 116 void MoveToThread( |
116 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 117 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
117 | 118 |
118 // PrefObserver | 119 // PrefObserver |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 class PrefMember : public subtle::PrefMemberBase { | 163 class PrefMember : public subtle::PrefMemberBase { |
163 public: | 164 public: |
164 // Defer initialization to an Init method so it's easy to make this class be | 165 // Defer initialization to an Init method so it's easy to make this class be |
165 // a member variable. | 166 // a member variable. |
166 PrefMember() {} | 167 PrefMember() {} |
167 virtual ~PrefMember() {} | 168 virtual ~PrefMember() {} |
168 | 169 |
169 // Do the actual initialization of the class. Use the two-parameter | 170 // Do the actual initialization of the class. Use the two-parameter |
170 // version if you don't want any notifications of changes. This | 171 // version if you don't want any notifications of changes. This |
171 // method should only be called on the UI thread. | 172 // method should only be called on the UI thread. |
172 void Init(const char* pref_name, PrefService* prefs, | 173 void Init(const std::string& pref_name, |
| 174 PrefService* prefs, |
173 const NamedChangeCallback& observer) { | 175 const NamedChangeCallback& observer) { |
174 subtle::PrefMemberBase::Init(pref_name, prefs, observer); | 176 subtle::PrefMemberBase::Init(pref_name, prefs, observer); |
175 } | 177 } |
176 void Init(const char* pref_name, PrefService* prefs, | 178 void Init(const std::string& pref_name, |
| 179 PrefService* prefs, |
177 const base::Closure& observer) { | 180 const base::Closure& observer) { |
178 subtle::PrefMemberBase::Init( | 181 subtle::PrefMemberBase::Init( |
179 pref_name, prefs, | 182 pref_name, prefs, |
180 base::Bind(&PrefMemberBase::InvokeUnnamedCallback, observer)); | 183 base::Bind(&PrefMemberBase::InvokeUnnamedCallback, observer)); |
181 } | 184 } |
182 void Init(const char* pref_name, PrefService* prefs) { | 185 void Init(const std::string& pref_name, PrefService* prefs) { |
183 subtle::PrefMemberBase::Init(pref_name, prefs); | 186 subtle::PrefMemberBase::Init(pref_name, prefs); |
184 } | 187 } |
185 | 188 |
186 // Unsubscribes the PrefMember from the PrefService. After calling this | 189 // Unsubscribes the PrefMember from the PrefService. After calling this |
187 // function, the PrefMember may not be used any more on the UI thread. | 190 // function, the PrefMember may not be used any more on the UI thread. |
188 // Assuming |MoveToThread| was previously called, |GetValue|, |IsManaged|, | 191 // Assuming |MoveToThread| was previously called, |GetValue|, |IsManaged|, |
189 // and |IsUserModifiable| can still be called from the other thread but | 192 // and |IsUserModifiable| can still be called from the other thread but |
190 // the results will no longer update from the PrefService. | 193 // the results will no longer update from the PrefService. |
191 // This method should only be called on the UI thread. | 194 // This method should only be called on the UI thread. |
192 void Destroy() { | 195 void Destroy() { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 | 348 |
346 typedef PrefMember<bool> BooleanPrefMember; | 349 typedef PrefMember<bool> BooleanPrefMember; |
347 typedef PrefMember<int> IntegerPrefMember; | 350 typedef PrefMember<int> IntegerPrefMember; |
348 typedef PrefMember<double> DoublePrefMember; | 351 typedef PrefMember<double> DoublePrefMember; |
349 typedef PrefMember<std::string> StringPrefMember; | 352 typedef PrefMember<std::string> StringPrefMember; |
350 typedef PrefMember<base::FilePath> FilePathPrefMember; | 353 typedef PrefMember<base::FilePath> FilePathPrefMember; |
351 // This preference member is expensive for large string arrays. | 354 // This preference member is expensive for large string arrays. |
352 typedef PrefMember<std::vector<std::string> > StringListPrefMember; | 355 typedef PrefMember<std::vector<std::string> > StringListPrefMember; |
353 | 356 |
354 #endif // BASE_PREFS_PREF_MEMBER_H_ | 357 #endif // BASE_PREFS_PREF_MEMBER_H_ |
OLD | NEW |