Index: chrome/browser/prefs/pref_member.h |
diff --git a/chrome/browser/prefs/pref_member.h b/chrome/browser/prefs/pref_member.h |
index 88a00711f4e91286a64d7f6130191160c873d0e8..96ee6160ad0cde2a012d9cbd097af4081498cc53 100644 |
--- a/chrome/browser/prefs/pref_member.h |
+++ b/chrome/browser/prefs/pref_member.h |
@@ -33,8 +33,10 @@ |
#include "base/values.h" |
#include "content/browser/browser_thread.h" |
#include "content/common/notification_observer.h" |
+#include "content/common/notification_registrar.h" |
class PrefService; |
+class Profile; |
namespace subtle { |
@@ -86,6 +88,8 @@ class PrefMemberBase : public NotificationObserver { |
virtual void CreateInternal() const = 0; |
+ void ObserveProfileDestruction(Profile* profile); |
+ |
// See PrefMember<> for description. |
void Destroy(); |
@@ -96,7 +100,9 @@ class PrefMemberBase : public NotificationObserver { |
const NotificationSource& source, |
const NotificationDetails& details); |
- void VerifyValuePrefName() const; |
+ void VerifyValuePrefName() const { |
+ DCHECK(!pref_name_.empty()); |
+ } |
// This method is used to do the actual sync with the preference. |
// Note: it is logically const, because it doesn't modify the state |
@@ -105,11 +111,7 @@ class PrefMemberBase : public NotificationObserver { |
// Verifies the preference name, and lazily loads the preference value if |
// it hasn't been loaded yet. |
- void VerifyPref() const { |
- VerifyValuePrefName(); |
- if (!internal()) |
- UpdateValueFromPref(); |
- } |
+ void VerifyPref() const; |
const std::string& pref_name() const { return pref_name_; } |
PrefService* prefs() { return prefs_; } |
@@ -120,6 +122,7 @@ class PrefMemberBase : public NotificationObserver { |
// Ordered the members to compact the class instance. |
private: |
std::string pref_name_; |
+ NotificationRegistrar registrar_; |
NotificationObserver* observer_; |
PrefService* prefs_; |
@@ -145,6 +148,12 @@ class PrefMember : public subtle::PrefMemberBase { |
subtle::PrefMemberBase::Init(pref_name, prefs, observer); |
} |
+ // Starts observing PROFILE_DESTROYED notifications for the given |profile|, |
+ // to automatically unsubscribe from the PrefService. |
+ void ObserveProfileDestruction(Profile* profile) { |
+ subtle::PrefMemberBase::ObserveProfileDestruction(profile); |
+ } |
+ |
// Unsubscribes the PrefMember from the PrefService. After calling this |
// function, the PrefMember may not be used any more. |
// This method should only be called on the UI thread. |