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

Side by Side Diff: chrome/browser/ui/alternate_error_tab_observer.cc

Issue 11345008: Remove content::NotificationObserver dependency from most Prefs code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head for commit 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/alternate_error_tab_observer.h" 5 #include "chrome/browser/ui/alternate_error_tab_observer.h"
6 6
7 #include "chrome/browser/google/google_util.h" 7 #include "chrome/browser/google/google_util.h"
8 #include "chrome/browser/prefs/pref_service.h" 8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 UpdateAlternateErrorPageURL(render_view_host); 49 UpdateAlternateErrorPageURL(render_view_host);
50 } 50 }
51 51
52 //////////////////////////////////////////////////////////////////////////////// 52 ////////////////////////////////////////////////////////////////////////////////
53 // content::NotificationObserver overrides 53 // content::NotificationObserver overrides
54 54
55 void AlternateErrorPageTabObserver::Observe( 55 void AlternateErrorPageTabObserver::Observe(
56 int type, 56 int type,
57 const content::NotificationSource& source, 57 const content::NotificationSource& source,
58 const content::NotificationDetails& details) { 58 const content::NotificationDetails& details) {
59 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 59 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type);
60 DCHECK_EQ(profile_->GetPrefs(), content::Source<PrefService>(source).ptr());
61 DCHECK_EQ(std::string(prefs::kAlternateErrorPagesEnabled),
62 *content::Details<std::string>(details).ptr());
63 } else {
64 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type);
65 }
66 UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); 60 UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost());
67 } 61 }
68 62
63 ////////////////////////////////////////////////////////////////////////////////
64 // PrefObserver overrides
65
66 void AlternateErrorPageTabObserver::OnPreferenceChanged(
67 PrefServiceBase* service,
68 const std::string& pref_name) {
69 DCHECK_EQ(profile_->GetPrefs(), service);
70 DCHECK(prefs::kAlternateErrorPagesEnabled == pref_name);
71 UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost());
72 }
73
69 //////////////////////////////////////////////////////////////////////////////// 74 ////////////////////////////////////////////////////////////////////////////////
70 // Internal helpers 75 // Internal helpers
71 76
72 GURL AlternateErrorPageTabObserver::GetAlternateErrorPageURL() const { 77 GURL AlternateErrorPageTabObserver::GetAlternateErrorPageURL() const {
73 GURL url; 78 GURL url;
74 // Disable alternate error pages when in Incognito mode. 79 // Disable alternate error pages when in Incognito mode.
75 if (profile_->IsOffTheRecord()) 80 if (profile_->IsOffTheRecord())
76 return url; 81 return url;
77 82
78 if (profile_->GetPrefs()->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { 83 if (profile_->GetPrefs()->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
79 url = google_util::LinkDoctorBaseURL(); 84 url = google_util::LinkDoctorBaseURL();
80 if (!url.is_valid()) 85 if (!url.is_valid())
81 return url; 86 return url;
82 url = google_util::AppendGoogleLocaleParam(url); 87 url = google_util::AppendGoogleLocaleParam(url);
83 url = google_util::AppendGoogleTLDParam(profile_, url); 88 url = google_util::AppendGoogleTLDParam(profile_, url);
84 } 89 }
85 return url; 90 return url;
86 } 91 }
87 92
88 void AlternateErrorPageTabObserver::UpdateAlternateErrorPageURL( 93 void AlternateErrorPageTabObserver::UpdateAlternateErrorPageURL(
89 RenderViewHost* rvh) { 94 RenderViewHost* rvh) {
90 rvh->SetAltErrorPageURL(GetAlternateErrorPageURL()); 95 rvh->SetAltErrorPageURL(GetAlternateErrorPageURL());
91 } 96 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/alternate_error_tab_observer.h ('k') | chrome/browser/ui/app_list/apps_model_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698