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

Unified Diff: chrome/browser/prefs/pref_member.cc

Issue 6773006: Add enableReferrers and enableHyperlinkAuditing to contentSettings.misc API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add comment Created 9 years, 8 months 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/prefs/pref_member.cc
diff --git a/chrome/browser/prefs/pref_member.cc b/chrome/browser/prefs/pref_member.cc
index 405aab63d850747d491fdfc6d5cc779a1373195c..b5dd530c01a5fcef33abeb4c9678ea7976f1a9d4 100644
--- a/chrome/browser/prefs/pref_member.cc
+++ b/chrome/browser/prefs/pref_member.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/value_conversions.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "content/common/notification_source.h"
#include "content/common/notification_type.h"
namespace subtle {
@@ -18,8 +19,7 @@ PrefMemberBase::PrefMemberBase()
}
PrefMemberBase::~PrefMemberBase() {
- if (prefs_ && !pref_name_.empty())
- prefs_->RemovePrefObserver(pref_name_.c_str(), this);
+ Destroy();
}
@@ -37,8 +37,15 @@ void PrefMemberBase::Init(const char* pref_name, PrefService* prefs,
prefs_->AddPrefObserver(pref_name, this);
}
+void PrefMemberBase::ObserveProfileDestruction(Profile* profile) {
+ DCHECK(registrar_.IsEmpty());
+ registrar_.Add(this,
+ NotificationType::PROFILE_DESTROYED,
+ Source<Profile>(profile));
+}
+
void PrefMemberBase::Destroy() {
- if (prefs_) {
+ if (prefs_ && !pref_name_.empty()) {
prefs_->RemovePrefObserver(pref_name_.c_str(), this);
prefs_ = NULL;
}
@@ -55,15 +62,23 @@ void PrefMemberBase::MoveToThread(BrowserThread::ID thread_id) {
void PrefMemberBase::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- VerifyValuePrefName();
- DCHECK(NotificationType::PREF_CHANGED == type);
- UpdateValueFromPref();
- if (!setting_value_ && observer_)
- observer_->Observe(type, source, details);
-}
-
-void PrefMemberBase::VerifyValuePrefName() const {
- DCHECK(!pref_name_.empty());
+ switch (type.value) {
+ case NotificationType::PREF_CHANGED: {
+ VerifyValuePrefName();
+ UpdateValueFromPref();
+ if (!setting_value_ && observer_)
+ observer_->Observe(type, source, details);
+ break;
+ }
+ case NotificationType::PROFILE_DESTROYED: {
+ Destroy();
+ registrar_.RemoveAll();
+ break;
+ }
+ default: {
+ NOTREACHED();
+ }
+ }
}
void PrefMemberBase::UpdateValueFromPref() const {
@@ -76,6 +91,12 @@ void PrefMemberBase::UpdateValueFromPref() const {
internal()->UpdateValue(pref->GetValue()->DeepCopy(), pref->IsManaged());
}
+void PrefMemberBase::VerifyPref() const {
+ VerifyValuePrefName();
+ if (!internal())
+ UpdateValueFromPref();
+}
+
PrefMemberBase::Internal::Internal() : thread_id_(BrowserThread::UI) { }
PrefMemberBase::Internal::~Internal() { }

Powered by Google App Engine
This is Rietveld 408576698