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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_tab_observer.cc

Issue 11414083: Remove PrefObserver usage, batch 9. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to sort-of good revision (r169014). 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 20 matching lines...) Expand all
31 #endif 31 #endif
32 32
33 SafeBrowsingTabObserver::SafeBrowsingTabObserver( 33 SafeBrowsingTabObserver::SafeBrowsingTabObserver(
34 content::WebContents* web_contents) : web_contents_(web_contents) { 34 content::WebContents* web_contents) : web_contents_(web_contents) {
35 #if defined(ENABLE_SAFE_BROWSING) 35 #if defined(ENABLE_SAFE_BROWSING)
36 Profile* profile = 36 Profile* profile =
37 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 37 Profile::FromBrowserContext(web_contents->GetBrowserContext());
38 PrefService* prefs = profile->GetPrefs(); 38 PrefService* prefs = profile->GetPrefs();
39 if (prefs) { 39 if (prefs) {
40 pref_change_registrar_.Init(prefs); 40 pref_change_registrar_.Init(prefs);
41 pref_change_registrar_.Add(prefs::kSafeBrowsingEnabled, this); 41 pref_change_registrar_.Add(
42 prefs::kSafeBrowsingEnabled,
43 base::Bind(&SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost,
44 base::Unretained(this)));
42 45
43 if (prefs->GetBoolean(prefs::kSafeBrowsingEnabled) && 46 if (prefs->GetBoolean(prefs::kSafeBrowsingEnabled) &&
44 g_browser_process->safe_browsing_detection_service()) { 47 g_browser_process->safe_browsing_detection_service()) {
45 safebrowsing_detection_host_.reset( 48 safebrowsing_detection_host_.reset(
46 ClientSideDetectionHost::Create(web_contents)); 49 ClientSideDetectionHost::Create(web_contents));
47 } 50 }
48 } 51 }
49 #endif 52 #endif
50 } 53 }
51 54
52 SafeBrowsingTabObserver::~SafeBrowsingTabObserver() { 55 SafeBrowsingTabObserver::~SafeBrowsingTabObserver() {
53 } 56 }
54 57
55 //////////////////////////////////////////////////////////////////////////////// 58 ////////////////////////////////////////////////////////////////////////////////
56 // content::NotificationObserver overrides
57
58 void SafeBrowsingTabObserver::OnPreferenceChanged(
59 PrefServiceBase* service,
60 const std::string& pref_name) {
61 Profile* profile =
62 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
63 DCHECK(service == profile->GetPrefs());
64 if (pref_name == prefs::kSafeBrowsingEnabled) {
65 UpdateSafebrowsingDetectionHost();
66 } else {
67 NOTREACHED() << "unexpected pref change notification" << pref_name;
68 }
69 }
70
71 ////////////////////////////////////////////////////////////////////////////////
72 // Internal helpers 59 // Internal helpers
73 60
74 void SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost() { 61 void SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost() {
75 #if defined(ENABLE_SAFE_BROWSING) 62 #if defined(ENABLE_SAFE_BROWSING)
76 Profile* profile = 63 Profile* profile =
77 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 64 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
78 PrefService* prefs = profile->GetPrefs(); 65 PrefService* prefs = profile->GetPrefs();
79 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled); 66 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled);
80 if (safe_browsing && 67 if (safe_browsing &&
81 g_browser_process->safe_browsing_detection_service()) { 68 g_browser_process->safe_browsing_detection_service()) {
82 if (!safebrowsing_detection_host_.get()) { 69 if (!safebrowsing_detection_host_.get()) {
83 safebrowsing_detection_host_.reset( 70 safebrowsing_detection_host_.reset(
84 ClientSideDetectionHost::Create(web_contents_)); 71 ClientSideDetectionHost::Create(web_contents_));
85 } 72 }
86 } else { 73 } else {
87 safebrowsing_detection_host_.reset(); 74 safebrowsing_detection_host_.reset();
88 } 75 }
89 76
90 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); 77 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
91 rvh->Send(new ChromeViewMsg_SetClientSidePhishingDetection( 78 rvh->Send(new ChromeViewMsg_SetClientSidePhishingDetection(
92 rvh->GetRoutingID(), safe_browsing)); 79 rvh->GetRoutingID(), safe_browsing));
93 #endif 80 #endif
94 } 81 }
95 82
96 } // namespace safe_browsing 83 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_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