Index: chrome/browser/ui/alternate_error_tab_observer.cc |
=================================================================== |
--- chrome/browser/ui/alternate_error_tab_observer.cc (revision 131375) |
+++ chrome/browser/ui/alternate_error_tab_observer.cc (working copy) |
@@ -17,9 +17,11 @@ |
using content::WebContents; |
AlternateErrorPageTabObserver::AlternateErrorPageTabObserver( |
- WebContents* web_contents) |
- : content::WebContentsObserver(web_contents) { |
- PrefService* prefs = GetProfile()->GetPrefs(); |
+ WebContents* web_contents, |
+ Profile* profile) |
+ : content::WebContentsObserver(web_contents), |
+ profile_(profile) { |
+ PrefService* prefs = profile_->GetPrefs(); |
if (prefs) { |
pref_change_registrar_.Init(prefs); |
pref_change_registrar_.Add(prefs::kAlternateErrorPagesEnabled, this); |
@@ -34,15 +36,10 @@ |
// static |
void AlternateErrorPageTabObserver::RegisterUserPrefs(PrefService* prefs) { |
- prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, |
- true, |
+ prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true, |
PrefService::SYNCABLE_PREF); |
} |
-Profile* AlternateErrorPageTabObserver::GetProfile() const { |
- return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
-} |
- |
//////////////////////////////////////////////////////////////////////////////// |
// WebContentsObserver overrides |
@@ -57,24 +54,14 @@ |
void AlternateErrorPageTabObserver::Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
- switch (type) { |
- case chrome::NOTIFICATION_GOOGLE_URL_UPDATED: |
- UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); |
- break; |
- case chrome::NOTIFICATION_PREF_CHANGED: { |
- std::string* pref_name = content::Details<std::string>(details).ptr(); |
- DCHECK(content::Source<PrefService>(source).ptr() == |
- GetProfile()->GetPrefs()); |
- if (*pref_name == prefs::kAlternateErrorPagesEnabled) { |
- UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); |
- } else { |
- NOTREACHED() << "unexpected pref change notification" << *pref_name; |
- } |
- break; |
- } |
- default: |
- NOTREACHED(); |
+ if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
+ DCHECK_EQ(profile_->GetPrefs(), content::Source<PrefService>(source).ptr()); |
+ DCHECK_EQ(std::string(prefs::kAlternateErrorPagesEnabled), |
+ *content::Details<std::string>(details).ptr()); |
+ } else { |
+ DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type); |
} |
+ UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -83,11 +70,10 @@ |
GURL AlternateErrorPageTabObserver::GetAlternateErrorPageURL() const { |
GURL url; |
// Disable alternate error pages when in Incognito mode. |
- Profile* profile = GetProfile(); |
- if (profile->IsOffTheRecord()) |
+ if (profile_->IsOffTheRecord()) |
return url; |
- if (profile->GetPrefs()->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { |
+ if (profile_->GetPrefs()->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { |
url = google_util::AppendGoogleLocaleParam( |
GURL(google_util::kLinkDoctorBaseURL)); |
url = google_util::AppendGoogleTLDParam(url); |