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

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: Respond to review comments. 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
« no previous file with comments | « base/prefs/public/pref_change_registrar_unittest.cc ('k') | chrome/browser/api/prefs/pref_member.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..be46743e8b2e7ba1ae968028fcbc7cd4a95c9c61 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;
@@ -126,7 +129,7 @@ class PrefMemberBase : public PrefObserver {
private:
// Ordered the members to compact the class instance.
std::string pref_name_;
- PrefObserver* observer_;
+ base::Closure observer_; // Initially bound to base::DoNothing.
PrefServiceBase* prefs_;
protected:
@@ -148,14 +151,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, std::string(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|,
« no previous file with comments | « base/prefs/public/pref_change_registrar_unittest.cc ('k') | chrome/browser/api/prefs/pref_member.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698