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

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

Issue 21170004: Store and return urls instead of hosts for the malware IP matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: some nit fix on int type Created 7 years, 4 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
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 26 matching lines...) Expand all
37 #include "content/public/common/frame_navigate_params.h" 37 #include "content/public/common/frame_navigate_params.h"
38 #include "url/gurl.h" 38 #include "url/gurl.h"
39 39
40 using content::BrowserThread; 40 using content::BrowserThread;
41 using content::NavigationEntry; 41 using content::NavigationEntry;
42 using content::ResourceRequestDetails; 42 using content::ResourceRequestDetails;
43 using content::WebContents; 43 using content::WebContents;
44 44
45 namespace safe_browsing { 45 namespace safe_browsing {
46 46
47 const int ClientSideDetectionHost::kMaxHostsPerIP = 20; 47 const int ClientSideDetectionHost::kMaxUrlsPerIP = 20;
48 const int ClientSideDetectionHost::kMaxIPsPerBrowse = 200; 48 const int ClientSideDetectionHost::kMaxIPsPerBrowse = 200;
49 49
50 namespace { 50 namespace {
51 51
52 void EmptyUrlCheckCallback(bool processed) { 52 void EmptyUrlCheckCallback(bool processed) {
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 // Send ping if there is matching features. 486 // Send ping if there is matching features.
487 if (request->feature_map_size() > 0) { 487 if (request->feature_map_size() > 0) {
488 VLOG(1) << "Start sending client malware request."; 488 VLOG(1) << "Start sending client malware request.";
489 ClientSideDetectionService::ClientReportMalwareRequestCallback callback; 489 ClientSideDetectionService::ClientReportMalwareRequestCallback callback;
490 csd_service_->SendClientReportMalwareRequest( 490 csd_service_->SendClientReportMalwareRequest(
491 request.release(), // The service takes ownership of the request object 491 request.release(), // The service takes ownership of the request object
492 callback); // no action after request sent for now 492 callback); // no action after request sent for now
493 } 493 }
494 } 494 }
495 495
496 void ClientSideDetectionHost::UpdateIPHostMap(const std::string& ip, 496 void ClientSideDetectionHost::UpdateIPUrlMap(const std::string& ip,
497 const std::string& host) { 497 const std::string& url) {
498 if (ip.empty() || host.empty()) 498 if (ip.empty() || url.empty())
499 return; 499 return;
500 500
501 IPHostMap::iterator it = browse_info_->ips.find(ip); 501 IPUrlMap::iterator it = browse_info_->ips.find(ip);
502 if (it == browse_info_->ips.end()) { 502 if (it == browse_info_->ips.end()) {
503 if (int(browse_info_->ips.size()) < kMaxIPsPerBrowse) { 503 if (int(browse_info_->ips.size()) < kMaxIPsPerBrowse) {
504 std::set<std::string> hosts; 504 std::set<std::string> urls;
505 hosts.insert(host); 505 urls.insert(url);
506 browse_info_->ips.insert(make_pair(ip, hosts)); 506 browse_info_->ips.insert(make_pair(ip, urls));
507 } 507 }
508 } else if (int(it->second.size()) < kMaxHostsPerIP) { 508 } else if (int(it->second.size()) < kMaxUrlsPerIP) {
509 it->second.insert(host); 509 it->second.insert(url);
510 } 510 }
511 } 511 }
512 512
513 void ClientSideDetectionHost::Observe( 513 void ClientSideDetectionHost::Observe(
514 int type, 514 int type,
515 const content::NotificationSource& source, 515 const content::NotificationSource& source,
516 const content::NotificationDetails& details) { 516 const content::NotificationDetails& details) {
517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
518 DCHECK_EQ(type, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED); 518 DCHECK_EQ(type, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED);
519 const ResourceRequestDetails* req = content::Details<ResourceRequestDetails>( 519 const ResourceRequestDetails* req = content::Details<ResourceRequestDetails>(
520 details).ptr(); 520 details).ptr();
521 if (req && browse_info_.get() && malware_report_enabled_ && 521 if (req && browse_info_.get() && malware_report_enabled_ &&
522 !MalwareKillSwitchIsOn()) { 522 !MalwareKillSwitchIsOn()) {
523 UpdateIPHostMap(req->socket_address.host() /* ip */, 523 if (req->url.is_valid()) {
524 req->url.host() /* url host */); 524 UpdateIPUrlMap(req->socket_address.host() /* ip */,
525 req->url.spec() /* url */);
526 }
525 } 527 }
526 } 528 }
527 529
528 bool ClientSideDetectionHost::DidShowSBInterstitial() { 530 bool ClientSideDetectionHost::DidShowSBInterstitial() {
529 if (unsafe_unique_page_id_ <= 0 || !web_contents()) { 531 if (unsafe_unique_page_id_ <= 0 || !web_contents()) {
530 return false; 532 return false;
531 } 533 }
532 const NavigationEntry* nav_entry = 534 const NavigationEntry* nav_entry =
533 web_contents()->GetController().GetActiveEntry(); 535 web_contents()->GetController().GetActiveEntry();
534 return (nav_entry && nav_entry->GetUniqueID() == unsafe_unique_page_id_); 536 return (nav_entry && nav_entry->GetUniqueID() == unsafe_unique_page_id_);
(...skipping 21 matching lines...) Expand all
556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
557 return malware_killswitch_on_; 559 return malware_killswitch_on_;
558 } 560 }
559 561
560 void ClientSideDetectionHost::SetMalwareKillSwitch(bool killswitch_on) { 562 void ClientSideDetectionHost::SetMalwareKillSwitch(bool killswitch_on) {
561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
562 malware_killswitch_on_ = killswitch_on; 564 malware_killswitch_on_ = killswitch_on;
563 } 565 }
564 566
565 } // namespace safe_browsing 567 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698