| 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 17 matching lines...) Expand all Loading... |
| 28 #include "content/public/common/page_transition_types.h" | 28 #include "content/public/common/page_transition_types.h" |
| 29 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 30 | 30 |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 using content::NavigationController; | 32 using content::NavigationController; |
| 33 using content::NavigationEntry; | 33 using content::NavigationEntry; |
| 34 using content::WebContents; | 34 using content::WebContents; |
| 35 | 35 |
| 36 namespace safe_browsing { | 36 namespace safe_browsing { |
| 37 | 37 |
| 38 const int BrowserFeatureExtractor::kMaxMalwareIPPerRequest = 5; |
| 39 |
| 38 BrowseInfo::BrowseInfo() : http_status_code(0) {} | 40 BrowseInfo::BrowseInfo() : http_status_code(0) {} |
| 39 | 41 |
| 40 BrowseInfo::~BrowseInfo() {} | 42 BrowseInfo::~BrowseInfo() {} |
| 41 | 43 |
| 42 static void AddFeature(const std::string& feature_name, | 44 static void AddFeature(const std::string& feature_name, |
| 43 double feature_value, | 45 double feature_value, |
| 44 ClientPhishingRequest* request) { | 46 ClientPhishingRequest* request) { |
| 45 DCHECK(request); | 47 DCHECK(request); |
| 46 ClientPhishingRequest::Feature* feature = | 48 ClientPhishingRequest::Feature* feature = |
| 47 request->add_non_model_feature_map(); | 49 request->add_non_model_feature_map(); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 weak_factory_.GetWeakPtr(), request, callback)); | 229 weak_factory_.GetWeakPtr(), request, callback)); |
| 228 } | 230 } |
| 229 | 231 |
| 230 void BrowserFeatureExtractor::ExtractMalwareFeatures( | 232 void BrowserFeatureExtractor::ExtractMalwareFeatures( |
| 231 const BrowseInfo* info, | 233 const BrowseInfo* info, |
| 232 ClientMalwareRequest* request) { | 234 ClientMalwareRequest* request) { |
| 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 234 DCHECK(request); | 236 DCHECK(request); |
| 235 DCHECK(info); | 237 DCHECK(info); |
| 236 DCHECK_EQ(0U, request->url().find("http:")); | 238 DCHECK_EQ(0U, request->url().find("http:")); |
| 237 // get the IPs and hosts that match the malware blacklisted IP list. | 239 // get the IPs and urls that match the malware blacklisted IP list. |
| 238 if (service_) { | 240 if (service_) { |
| 239 for (IPHostMap::const_iterator it = info->ips.begin(); | 241 int matched_bad_ips = 0; |
| 242 for (IPUrlMap::const_iterator it = info->ips.begin(); |
| 240 it != info->ips.end(); ++it) { | 243 it != info->ips.end(); ++it) { |
| 241 if (service_->IsBadIpAddress(it->first)) { | 244 if (service_->IsBadIpAddress(it->first)) { |
| 242 AddMalwareFeature(features::kBadIpFetch + it->first, | 245 AddMalwareFeature(features::kBadIpFetch + it->first, |
| 243 it->second, 1.0, request); | 246 it->second, 1.0, request); |
| 247 ++matched_bad_ips; |
| 248 // Limit the number of matched bad IPs in one request to control |
| 249 // the request's size |
| 250 if (matched_bad_ips >= kMaxMalwareIPPerRequest) { |
| 251 return; |
| 252 } |
| 244 } | 253 } |
| 245 } | 254 } |
| 246 } | 255 } |
| 247 } | 256 } |
| 248 | 257 |
| 249 void BrowserFeatureExtractor::ExtractBrowseInfoFeatures( | 258 void BrowserFeatureExtractor::ExtractBrowseInfoFeatures( |
| 250 const BrowseInfo& info, | 259 const BrowseInfo& info, |
| 251 ClientPhishingRequest* request) { | 260 ClientPhishingRequest* request) { |
| 252 if (service_) { | 261 if (service_) { |
| 253 for (IPHostMap::const_iterator it = info.ips.begin(); | 262 for (IPUrlMap::const_iterator it = info.ips.begin(); |
| 254 it != info.ips.end(); ++it) { | 263 it != info.ips.end(); ++it) { |
| 255 if (service_->IsBadIpAddress(it->first)) { | 264 if (service_->IsBadIpAddress(it->first)) { |
| 256 AddFeature(features::kBadIpFetch + it->first, 1.0, request); | 265 AddFeature(features::kBadIpFetch + it->first, 1.0, request); |
| 257 } | 266 } |
| 258 } | 267 } |
| 259 } | 268 } |
| 260 if (info.unsafe_resource.get()) { | 269 if (info.unsafe_resource.get()) { |
| 261 // A SafeBrowsing interstitial was shown for the current URL. | 270 // A SafeBrowsing interstitial was shown for the current URL. |
| 262 AddFeature(features::kSafeBrowsingMaliciousUrl + | 271 AddFeature(features::kSafeBrowsingMaliciousUrl + |
| 263 info.unsafe_resource->url.spec(), | 272 info.unsafe_resource->url.spec(), |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 Profile::EXPLICIT_ACCESS); | 489 Profile::EXPLICIT_ACCESS); |
| 481 if (*history) { | 490 if (*history) { |
| 482 return true; | 491 return true; |
| 483 } | 492 } |
| 484 } | 493 } |
| 485 VLOG(2) << "Unable to query history. No history service available."; | 494 VLOG(2) << "Unable to query history. No history service available."; |
| 486 return false; | 495 return false; |
| 487 } | 496 } |
| 488 | 497 |
| 489 } // namespace safe_browsing | 498 } // namespace safe_browsing |
| OLD | NEW |