OLD | NEW |
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/browser_feature_extractor.h" | 5 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 BrowseInfo::~BrowseInfo() {} | 73 BrowseInfo::~BrowseInfo() {} |
74 | 74 |
75 static void AddFeature(const std::string& feature_name, | 75 static void AddFeature(const std::string& feature_name, |
76 double feature_value, | 76 double feature_value, |
77 ClientPhishingRequest* request) { | 77 ClientPhishingRequest* request) { |
78 DCHECK(request); | 78 DCHECK(request); |
79 ClientPhishingRequest::Feature* feature = | 79 ClientPhishingRequest::Feature* feature = |
80 request->add_non_model_feature_map(); | 80 request->add_non_model_feature_map(); |
81 feature->set_name(feature_name); | 81 feature->set_name(feature_name); |
82 feature->set_value(feature_value); | 82 feature->set_value(feature_value); |
83 VLOG(2) << "Browser feature: " << feature->name() << " " << feature->value(); | 83 DVLOG(2) << "Browser feature: " << feature->name() << " " << feature->value(); |
84 } | 84 } |
85 | 85 |
86 static void AddMalwareIpUrlInfo(const std::string& ip, | 86 static void AddMalwareIpUrlInfo(const std::string& ip, |
87 const std::vector<IPUrlInfo>& meta_infos, | 87 const std::vector<IPUrlInfo>& meta_infos, |
88 ClientMalwareRequest* request) { | 88 ClientMalwareRequest* request) { |
89 DCHECK(request); | 89 DCHECK(request); |
90 for (std::vector<IPUrlInfo>::const_iterator it = meta_infos.begin(); | 90 for (std::vector<IPUrlInfo>::const_iterator it = meta_infos.begin(); |
91 it != meta_infos.end(); ++it) { | 91 it != meta_infos.end(); ++it) { |
92 ClientMalwareRequest::UrlInfo* urlinfo = | 92 ClientMalwareRequest::UrlInfo* urlinfo = |
93 request->add_bad_ip_url_info(); | 93 request->add_bad_ip_url_info(); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 bool BrowserFeatureExtractor::GetHistoryService(HistoryService** history) { | 457 bool BrowserFeatureExtractor::GetHistoryService(HistoryService** history) { |
458 *history = NULL; | 458 *history = NULL; |
459 if (tab_ && tab_->GetBrowserContext()) { | 459 if (tab_ && tab_->GetBrowserContext()) { |
460 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); | 460 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); |
461 *history = HistoryServiceFactory::GetForProfile(profile, | 461 *history = HistoryServiceFactory::GetForProfile(profile, |
462 Profile::EXPLICIT_ACCESS); | 462 Profile::EXPLICIT_ACCESS); |
463 if (*history) { | 463 if (*history) { |
464 return true; | 464 return true; |
465 } | 465 } |
466 } | 466 } |
467 VLOG(2) << "Unable to query history. No history service available."; | 467 DVLOG(2) << "Unable to query history. No history service available."; |
468 return false; | 468 return false; |
469 } | 469 } |
470 | 470 |
471 void BrowserFeatureExtractor::FinishExtractMalwareFeatures( | 471 void BrowserFeatureExtractor::FinishExtractMalwareFeatures( |
472 scoped_ptr<IPUrlMap> bad_ips, | 472 scoped_ptr<IPUrlMap> bad_ips, |
473 MalwareDoneCallback callback, | 473 MalwareDoneCallback callback, |
474 scoped_ptr<ClientMalwareRequest> request) { | 474 scoped_ptr<ClientMalwareRequest> request) { |
475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
476 int matched_bad_ips = 0; | 476 int matched_bad_ips = 0; |
477 for (IPUrlMap::const_iterator it = bad_ips->begin(); | 477 for (IPUrlMap::const_iterator it = bad_ips->begin(); |
478 it != bad_ips->end(); ++it) { | 478 it != bad_ips->end(); ++it) { |
479 AddMalwareIpUrlInfo(it->first, it->second, request.get()); | 479 AddMalwareIpUrlInfo(it->first, it->second, request.get()); |
480 ++matched_bad_ips; | 480 ++matched_bad_ips; |
481 // Limit the number of matched bad IPs in one request to control | 481 // Limit the number of matched bad IPs in one request to control |
482 // the request's size | 482 // the request's size |
483 if (matched_bad_ips >= kMaxMalwareIPPerRequest) { | 483 if (matched_bad_ips >= kMaxMalwareIPPerRequest) { |
484 break; | 484 break; |
485 } | 485 } |
486 } | 486 } |
487 callback.Run(true, request.Pass()); | 487 callback.Run(true, request.Pass()); |
488 } | 488 } |
489 | 489 |
490 } // namespace safe_browsing | 490 } // namespace safe_browsing |
OLD | NEW |