| 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 | 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(Internal); | 97 DISALLOW_COPY_AND_ASSIGN(Internal); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 PrefMemberBase(); | 100 PrefMemberBase(); |
| 101 virtual ~PrefMemberBase(); | 101 virtual ~PrefMemberBase(); |
| 102 | 102 |
| 103 // See PrefMember<> for description. | 103 // See PrefMember<> for description. |
| 104 void Init(const char* pref_name, PrefServiceBase* prefs, | 104 void Init(const char* pref_name, PrefServiceBase* prefs, |
| 105 const NamedChangeCallback& observer); | 105 const NamedChangeCallback& observer); |
| 106 void Init(const char* pref_name, PrefServiceBase* prefs); |
| 106 | 107 |
| 107 virtual void CreateInternal() const = 0; | 108 virtual void CreateInternal() const = 0; |
| 108 | 109 |
| 109 // See PrefMember<> for description. | 110 // See PrefMember<> for description. |
| 110 void Destroy(); | 111 void Destroy(); |
| 111 | 112 |
| 112 void MoveToThread(const scoped_refptr<base::MessageLoopProxy>& message_loop); | 113 void MoveToThread(const scoped_refptr<base::MessageLoopProxy>& message_loop); |
| 113 | 114 |
| 114 // PrefObserver | 115 // PrefObserver |
| 115 virtual void OnPreferenceChanged(PrefServiceBase* service, | 116 virtual void OnPreferenceChanged(PrefServiceBase* service, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 void Init(const char* pref_name, PrefServiceBase* prefs, | 172 void Init(const char* pref_name, PrefServiceBase* prefs, |
| 172 const base::Closure& observer) { | 173 const base::Closure& observer) { |
| 173 subtle::PrefMemberBase::Init( | 174 subtle::PrefMemberBase::Init( |
| 174 pref_name, prefs, | 175 pref_name, prefs, |
| 175 base::Bind(&PrefMemberBase::InvokeUnnamedCallback, observer)); | 176 base::Bind(&PrefMemberBase::InvokeUnnamedCallback, observer)); |
| 176 } | 177 } |
| 177 void Init(const char* pref_name, PrefServiceBase* prefs) { | 178 void Init(const char* pref_name, PrefServiceBase* prefs) { |
| 178 subtle::PrefMemberBase::Init(pref_name, prefs); | 179 subtle::PrefMemberBase::Init(pref_name, prefs); |
| 179 } | 180 } |
| 180 | 181 |
| 181 // Deprecated version of Init. | |
| 182 void Init(const char* pref_name, PrefServiceBase* prefs, | |
| 183 PrefObserver* observer) { | |
| 184 if (observer) { | |
| 185 Init(pref_name, prefs, base::Bind(&PrefObserver::OnPreferenceChanged, | |
| 186 base::Unretained(observer), prefs)); | |
| 187 } else { | |
| 188 Init(pref_name, prefs, NamedChangeCallback()); | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 // Unsubscribes the PrefMember from the PrefService. After calling this | 182 // Unsubscribes the PrefMember from the PrefService. After calling this |
| 193 // function, the PrefMember may not be used any more on the UI thread. | 183 // function, the PrefMember may not be used any more on the UI thread. |
| 194 // Assuming |MoveToThread| was previously called, |GetValue|, |IsManaged|, | 184 // Assuming |MoveToThread| was previously called, |GetValue|, |IsManaged|, |
| 195 // and |IsUserModifiable| can still be called from the other thread but | 185 // and |IsUserModifiable| can still be called from the other thread but |
| 196 // the results will no longer update from the PrefService. | 186 // the results will no longer update from the PrefService. |
| 197 // This method should only be called on the UI thread. | 187 // This method should only be called on the UI thread. |
| 198 void Destroy() { | 188 void Destroy() { |
| 199 subtle::PrefMemberBase::Destroy(); | 189 subtle::PrefMemberBase::Destroy(); |
| 200 } | 190 } |
| 201 | 191 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 282 |
| 293 typedef PrefMember<bool> BooleanPrefMember; | 283 typedef PrefMember<bool> BooleanPrefMember; |
| 294 typedef PrefMember<int> IntegerPrefMember; | 284 typedef PrefMember<int> IntegerPrefMember; |
| 295 typedef PrefMember<double> DoublePrefMember; | 285 typedef PrefMember<double> DoublePrefMember; |
| 296 typedef PrefMember<std::string> StringPrefMember; | 286 typedef PrefMember<std::string> StringPrefMember; |
| 297 typedef PrefMember<FilePath> FilePathPrefMember; | 287 typedef PrefMember<FilePath> FilePathPrefMember; |
| 298 // This preference member is expensive for large string arrays. | 288 // This preference member is expensive for large string arrays. |
| 299 typedef PrefMember<std::vector<std::string> > StringListPrefMember; | 289 typedef PrefMember<std::vector<std::string> > StringListPrefMember; |
| 300 | 290 |
| 301 #endif // CHROME_BROWSER_API_PREFS_PREF_MEMBER_H_ | 291 #endif // CHROME_BROWSER_API_PREFS_PREF_MEMBER_H_ |
| OLD | NEW |