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

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

Issue 16290004: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 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/client_side_detection_host.h" 5 #include "chrome/browser/safe_browsing/client_side_detection_host.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 ClientSideDetectionHost* host) 73 ClientSideDetectionHost* host)
74 : canceled_(false), 74 : canceled_(false),
75 params_(params), 75 params_(params),
76 web_contents_(web_contents), 76 web_contents_(web_contents),
77 csd_service_(csd_service), 77 csd_service_(csd_service),
78 database_manager_(database_manager), 78 database_manager_(database_manager),
79 host_(host) { 79 host_(host) {
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
81 DCHECK(web_contents_); 81 DCHECK(web_contents_);
82 DCHECK(csd_service_); 82 DCHECK(csd_service_);
83 DCHECK(database_manager_); 83 DCHECK(database_manager_.get());
84 DCHECK(host_); 84 DCHECK(host_);
85 } 85 }
86 86
87 void Start() { 87 void Start() {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
89 89
90 // We start by doing some simple checks that can run on the UI thread. 90 // We start by doing some simple checks that can run on the UI thread.
91 UMA_HISTOGRAM_COUNTS("SBClientPhishing.ClassificationStart", 1); 91 UMA_HISTOGRAM_COUNTS("SBClientPhishing.ClassificationStart", 1);
92 92
93 // Only classify [X]HTML documents. 93 // Only classify [X]HTML documents.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 NO_CLASSIFY_UNSUPPORTED_MIME_TYPE, 159 NO_CLASSIFY_UNSUPPORTED_MIME_TYPE,
160 160
161 NO_CLASSIFY_MAX // Always add new values before this one. 161 NO_CLASSIFY_MAX // Always add new values before this one.
162 }; 162 };
163 163
164 // The destructor can be called either from the UI or the IO thread. 164 // The destructor can be called either from the UI or the IO thread.
165 virtual ~ShouldClassifyUrlRequest() { } 165 virtual ~ShouldClassifyUrlRequest() { }
166 166
167 void CheckCsdWhitelist(const GURL& url) { 167 void CheckCsdWhitelist(const GURL& url) {
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
169 if (!database_manager_ || 169 if (!database_manager_.get() ||
170 database_manager_->MatchCsdWhitelistUrl(url)) { 170 database_manager_->MatchCsdWhitelistUrl(url)) {
171 // We're done. There is no point in going back to the UI thread. 171 // We're done. There is no point in going back to the UI thread.
172 VLOG(1) << "Skipping phishing classification for URL: " << url 172 VLOG(1) << "Skipping phishing classification for URL: " << url
173 << " because it matches the csd whitelist"; 173 << " because it matches the csd whitelist";
174 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail", 174 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.PreClassificationCheckFail",
175 NO_CLASSIFY_MATCH_CSD_WHITELIST, 175 NO_CLASSIFY_MATCH_CSD_WHITELIST,
176 NO_CLASSIFY_MAX); 176 NO_CLASSIFY_MAX);
177 return; 177 return;
178 } 178 }
179 179
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 malware_report_enabled_(false) { 254 malware_report_enabled_(false) {
255 DCHECK(tab); 255 DCHECK(tab);
256 // Note: csd_service_ and sb_service will be NULL here in testing. 256 // Note: csd_service_ and sb_service will be NULL here in testing.
257 csd_service_ = g_browser_process->safe_browsing_detection_service(); 257 csd_service_ = g_browser_process->safe_browsing_detection_service();
258 feature_extractor_.reset(new BrowserFeatureExtractor(tab, csd_service_)); 258 feature_extractor_.reset(new BrowserFeatureExtractor(tab, csd_service_));
259 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED, 259 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED,
260 content::Source<WebContents>(tab)); 260 content::Source<WebContents>(tab));
261 261
262 scoped_refptr<SafeBrowsingService> sb_service = 262 scoped_refptr<SafeBrowsingService> sb_service =
263 g_browser_process->safe_browsing_service(); 263 g_browser_process->safe_browsing_service();
264 if (sb_service) { 264 if (sb_service.get()) {
265 ui_manager_ = sb_service->ui_manager(); 265 ui_manager_ = sb_service->ui_manager();
266 database_manager_ = sb_service->database_manager(); 266 database_manager_ = sb_service->database_manager();
267 ui_manager_->AddObserver(this); 267 ui_manager_->AddObserver(this);
268 } 268 }
269 269
270 // Only enable the malware bad IP matching and report feature for canary 270 // Only enable the malware bad IP matching and report feature for canary
271 // and dev channel. 271 // and dev channel.
272 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 272 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
273 malware_report_enabled_ = ( 273 malware_report_enabled_ = (
274 channel == chrome::VersionInfo::CHANNEL_DEV || 274 channel == chrome::VersionInfo::CHANNEL_DEV ||
275 channel == chrome::VersionInfo::CHANNEL_CANARY); 275 channel == chrome::VersionInfo::CHANNEL_CANARY);
276 } 276 }
277 277
278 ClientSideDetectionHost::~ClientSideDetectionHost() { 278 ClientSideDetectionHost::~ClientSideDetectionHost() {
279 if (ui_manager_) 279 if (ui_manager_.get())
280 ui_manager_->RemoveObserver(this); 280 ui_manager_->RemoveObserver(this);
281 } 281 }
282 282
283 bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) { 283 bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) {
284 bool handled = true; 284 bool handled = true;
285 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) 285 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message)
286 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone, 286 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_PhishingDetectionDone,
287 OnPhishingDetectionDone) 287 OnPhishingDetectionDone)
288 IPC_MESSAGE_UNHANDLED(handled = false) 288 IPC_MESSAGE_UNHANDLED(handled = false)
289 IPC_END_MESSAGE_MAP() 289 IPC_END_MESSAGE_MAP()
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 // Store redirect chain information. 322 // Store redirect chain information.
323 if (params.url.host() != cur_host_) { 323 if (params.url.host() != cur_host_) {
324 cur_host_ = params.url.host(); 324 cur_host_ = params.url.host();
325 cur_host_redirects_ = params.redirects; 325 cur_host_redirects_ = params.redirects;
326 } 326 }
327 browse_info_->host_redirects = cur_host_redirects_; 327 browse_info_->host_redirects = cur_host_redirects_;
328 browse_info_->url_redirects = params.redirects; 328 browse_info_->url_redirects = params.redirects;
329 browse_info_->http_status_code = details.http_status_code; 329 browse_info_->http_status_code = details.http_status_code;
330 330
331 // Notify the renderer if it should classify this URL. 331 // Notify the renderer if it should classify this URL.
332 classification_request_ = new ShouldClassifyUrlRequest(params, 332 classification_request_ = new ShouldClassifyUrlRequest(
333 web_contents(), 333 params, web_contents(), csd_service_, database_manager_.get(), this);
334 csd_service_,
335 database_manager_,
336 this);
337 classification_request_->Start(); 334 classification_request_->Start();
338 } 335 }
339 336
340 void ClientSideDetectionHost::OnSafeBrowsingHit( 337 void ClientSideDetectionHost::OnSafeBrowsingHit(
341 const SafeBrowsingUIManager::UnsafeResource& resource) { 338 const SafeBrowsingUIManager::UnsafeResource& resource) {
342 // Check that this notification is really for us and that it corresponds to 339 // Check that this notification is really for us and that it corresponds to
343 // either a malware or phishing hit. In this case we store the unique page 340 // either a malware or phishing hit. In this case we store the unique page
344 // ID for later. 341 // ID for later.
345 if (web_contents() && 342 if (web_contents() &&
346 web_contents()->GetRenderProcessHost()->GetID() == 343 web_contents()->GetRenderProcessHost()->GetID() ==
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 browse_info_.reset(); 418 browse_info_.reset();
422 } 419 }
423 420
424 void ClientSideDetectionHost::MaybeShowPhishingWarning(GURL phishing_url, 421 void ClientSideDetectionHost::MaybeShowPhishingWarning(GURL phishing_url,
425 bool is_phishing) { 422 bool is_phishing) {
426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
427 VLOG(2) << "Received server phishing verdict for URL:" << phishing_url 424 VLOG(2) << "Received server phishing verdict for URL:" << phishing_url
428 << " is_phishing:" << is_phishing; 425 << " is_phishing:" << is_phishing;
429 if (is_phishing) { 426 if (is_phishing) {
430 DCHECK(web_contents()); 427 DCHECK(web_contents());
431 if (ui_manager_) { 428 if (ui_manager_.get()) {
432 SafeBrowsingUIManager::UnsafeResource resource; 429 SafeBrowsingUIManager::UnsafeResource resource;
433 resource.url = phishing_url; 430 resource.url = phishing_url;
434 resource.original_url = phishing_url; 431 resource.original_url = phishing_url;
435 resource.is_subresource = false; 432 resource.is_subresource = false;
436 resource.threat_type = SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL; 433 resource.threat_type = SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL;
437 resource.render_process_host_id = 434 resource.render_process_host_id =
438 web_contents()->GetRenderProcessHost()->GetID(); 435 web_contents()->GetRenderProcessHost()->GetID();
439 resource.render_view_id = 436 resource.render_view_id =
440 web_contents()->GetRenderViewHost()->GetRoutingID(); 437 web_contents()->GetRenderViewHost()->GetRoutingID();
441 if (!ui_manager_->IsWhitelisted(resource)) { 438 if (!ui_manager_->IsWhitelisted(resource)) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 } 528 }
532 529
533 void ClientSideDetectionHost::set_client_side_detection_service( 530 void ClientSideDetectionHost::set_client_side_detection_service(
534 ClientSideDetectionService* service) { 531 ClientSideDetectionService* service) {
535 csd_service_ = service; 532 csd_service_ = service;
536 } 533 }
537 534
538 void ClientSideDetectionHost::set_safe_browsing_managers( 535 void ClientSideDetectionHost::set_safe_browsing_managers(
539 SafeBrowsingUIManager* ui_manager, 536 SafeBrowsingUIManager* ui_manager,
540 SafeBrowsingDatabaseManager* database_manager) { 537 SafeBrowsingDatabaseManager* database_manager) {
541 if (ui_manager_) 538 if (ui_manager_.get())
542 ui_manager_->RemoveObserver(this); 539 ui_manager_->RemoveObserver(this);
543 540
544 ui_manager_ = ui_manager; 541 ui_manager_ = ui_manager;
545 if (ui_manager) 542 if (ui_manager)
546 ui_manager_->AddObserver(this); 543 ui_manager_->AddObserver(this);
547 544
548 database_manager_ = database_manager; 545 database_manager_ = database_manager;
549 } 546 }
550 547
551 } // namespace safe_browsing 548 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698