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

Unified Diff: chrome/browser/api/prefs/pref_member.h

Issue 11368098: Draft change to use base::Closure instead of PrefObserver in PrefChangeRegistrar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/api/prefs/pref_member.h
diff --git a/chrome/browser/api/prefs/pref_member.h b/chrome/browser/api/prefs/pref_member.h
index 78436936149008c0f37080326aecc12312c8556c..721d3c7d1a93e689645149fc681fd783c871bf0f 100644
--- a/chrome/browser/api/prefs/pref_member.h
+++ b/chrome/browser/api/prefs/pref_member.h
@@ -28,6 +28,8 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/callback_forward.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
@@ -91,7 +93,8 @@ class PrefMemberBase : public PrefObserver {
// See PrefMember<> for description.
void Init(const char* pref_name, PrefServiceBase* prefs,
- PrefObserver* observer);
+ const base::Closure& observer);
+ void Init(const char* pref_name, PrefServiceBase* prefs);
virtual void CreateInternal() const = 0;
@@ -124,9 +127,12 @@ class PrefMemberBase : public PrefObserver {
virtual Internal* internal() const = 0;
private:
+ // |observer_| is bound to this unless an external observer is provided.
+ void DoNothing() {}
Mattias Nissler (ping if slow) 2012/11/07 16:02:24 base/bind_helpers.h has a DoNothing that you can u
Jói 2012/11/08 11:03:14 Thanks, switched.
+
// Ordered the members to compact the class instance.
std::string pref_name_;
- PrefObserver* observer_;
+ base::Closure observer_;
PrefServiceBase* prefs_;
protected:
@@ -148,14 +154,30 @@ class PrefMember : public subtle::PrefMemberBase {
PrefMember() {}
virtual ~PrefMember() {}
- // Do the actual initialization of the class. |observer| may be null if you
- // don't want any notifications of changes.
- // This method should only be called on the UI thread.
+ // Do the actual initialization of the class. Use the two-parameter
+ // version if you don't want any notifications of changes. This
+ // method should only be called on the UI thread.
void Init(const char* pref_name, PrefServiceBase* prefs,
- PrefObserver* observer) {
+ const base::Closure& observer) {
subtle::PrefMemberBase::Init(pref_name, prefs, observer);
}
+ void Init(const char* pref_name, PrefServiceBase* prefs) {
+ subtle::PrefMemberBase::Init(pref_name, prefs);
+ }
+
+ // Deprecated version of Init.
+ void Init(const char* pref_name, PrefServiceBase* prefs,
+ PrefObserver* observer) {
+ if (observer) {
+ Init(pref_name, prefs, base::Bind(&PrefObserver::OnPreferenceChanged,
+ base::Unretained(observer),
+ prefs, pref_name));
+ } else {
+ Init(pref_name, prefs);
+ }
+ }
+
// Unsubscribes the PrefMember from the PrefService. After calling this
// function, the PrefMember may not be used any more on the UI thread.
// Assuming |MoveToThread| was previously called, |GetValue|, |IsManaged|,

Powered by Google App Engine
This is Rietveld 408576698