Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: chrome/browser/api/prefs/pref_member.h

Issue 11316163: Remove the last usages of PrefObserver outside of Prefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Win and CrOS build. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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) {
11 // my_string_.Init(prefs::kHomePage, prefs, NULL /* no observer */); 11 // my_string_.Init(prefs::kHomePage, prefs, NULL /* no observer */);
Mattias Nissler (ping if slow) 2012/12/04 10:10:34 Update this?
Jói 2012/12/04 10:55:57 Done.
12 // } 12 // }
13 // private: 13 // private:
14 // StringPrefMember my_string_; 14 // StringPrefMember my_string_;
15 // }; 15 // };
16 // 16 //
17 // my_string_ should stay in sync with the prefs::kHomePage pref and will 17 // my_string_ should stay in sync with the prefs::kHomePage pref and will
18 // update if either the pref changes or if my_string_.SetValue is called. 18 // update if either the pref changes or if my_string_.SetValue is called.
19 // 19 //
20 // An optional observer can be passed into the Init method which can be used to 20 // An optional observer can be passed into the Init method which can be used to
21 // notify MyClass of changes. Note that if you use SetValue(), the observer 21 // notify MyClass of changes. Note that if you use SetValue(), the observer
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
Mattias Nissler (ping if slow) 2012/12/04 10:10:34 So this wasn't used previously? ;) Any reason to
Jói 2012/12/04 10:55:57 It's a performance optimization; we already create
Mattias Nissler (ping if slow) 2012/12/04 11:18:33 Is the difference measurable? I usually prefer les
Jói 2012/12/04 11:42:26 The performance difference is probably not measura
Mattias Nissler (ping if slow) 2012/12/04 15:24:37 I don't feel too strong, feel free to keep as is.
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
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
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698