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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_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 LKGR. 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/safe_browsing/safe_browsing_tab_observer.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 #endif 49 #endif
50 } 50 }
51 51
52 SafeBrowsingTabObserver::~SafeBrowsingTabObserver() { 52 SafeBrowsingTabObserver::~SafeBrowsingTabObserver() {
53 } 53 }
54 54
55 //////////////////////////////////////////////////////////////////////////////// 55 ////////////////////////////////////////////////////////////////////////////////
56 // content::NotificationObserver overrides 56 // content::NotificationObserver overrides
57 57
58 void SafeBrowsingTabObserver::Observe( 58 void SafeBrowsingTabObserver::OnPreferenceChanged(
59 int type, 59 PrefServiceBase* service,
60 const content::NotificationSource& source, 60 const std::string& pref_name) {
61 const content::NotificationDetails& details) { 61 Profile* profile =
62 switch (type) { 62 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
63 case chrome::NOTIFICATION_PREF_CHANGED: { 63 DCHECK(service == profile->GetPrefs());
64 Profile* profile = 64 if (pref_name == prefs::kSafeBrowsingEnabled) {
65 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 65 UpdateSafebrowsingDetectionHost();
66 std::string* pref_name = content::Details<std::string>(details).ptr(); 66 } else {
67 DCHECK(content::Source<PrefService>(source).ptr() == 67 NOTREACHED() << "unexpected pref change notification" << pref_name;
68 profile->GetPrefs());
69 if (*pref_name == prefs::kSafeBrowsingEnabled) {
70 UpdateSafebrowsingDetectionHost();
71 } else {
72 NOTREACHED() << "unexpected pref change notification" << *pref_name;
73 }
74 break;
75 }
76 default:
77 NOTREACHED();
78 } 68 }
79 } 69 }
80 70
81 //////////////////////////////////////////////////////////////////////////////// 71 ////////////////////////////////////////////////////////////////////////////////
82 // Internal helpers 72 // Internal helpers
83 73
84 void SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost() { 74 void SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost() {
85 #if defined(ENABLE_SAFE_BROWSING) 75 #if defined(ENABLE_SAFE_BROWSING)
86 Profile* profile = 76 Profile* profile =
87 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 77 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
88 PrefService* prefs = profile->GetPrefs(); 78 PrefService* prefs = profile->GetPrefs();
89 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled); 79 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled);
90 if (safe_browsing && 80 if (safe_browsing &&
91 g_browser_process->safe_browsing_detection_service()) { 81 g_browser_process->safe_browsing_detection_service()) {
92 if (!safebrowsing_detection_host_.get()) { 82 if (!safebrowsing_detection_host_.get()) {
93 safebrowsing_detection_host_.reset( 83 safebrowsing_detection_host_.reset(
94 ClientSideDetectionHost::Create(web_contents_)); 84 ClientSideDetectionHost::Create(web_contents_));
95 } 85 }
96 } else { 86 } else {
97 safebrowsing_detection_host_.reset(); 87 safebrowsing_detection_host_.reset();
98 } 88 }
99 89
100 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); 90 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
101 rvh->Send(new ChromeViewMsg_SetClientSidePhishingDetection( 91 rvh->Send(new ChromeViewMsg_SetClientSidePhishingDetection(
102 rvh->GetRoutingID(), safe_browsing)); 92 rvh->GetRoutingID(), safe_browsing));
103 #endif 93 #endif
104 } 94 }
105 95
106 } // namespace safe_browsing 96 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698