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" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "chrome/browser/history/history_service.h" | 16 #include "chrome/browser/history/history_service.h" |
17 #include "chrome/browser/history/history_service_factory.h" | 17 #include "chrome/browser/history/history_service_factory.h" |
18 #include "chrome/browser/history/history_types.h" | 18 #include "chrome/browser/history/history_types.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/safe_browsing/browser_features.h" | 20 #include "chrome/browser/safe_browsing/browser_features.h" |
21 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 21 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
22 #include "chrome/browser/safe_browsing/database_manager.h" | 22 #include "chrome/browser/safe_browsing/database_manager.h" |
23 #include "chrome/common/safe_browsing/csd.pb.h" | 23 #include "chrome/common/safe_browsing/csd.pb.h" |
24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/navigation_controller.h" | 25 #include "content/public/browser/navigation_controller.h" |
26 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "content/public/common/page_transition_types.h" | 28 #include "ui/base/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::ResourceType; | 34 using content::ResourceType; |
35 using content::WebContents; | 35 using content::WebContents; |
36 | 36 |
37 namespace safe_browsing { | 37 namespace safe_browsing { |
38 | 38 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 features::kReferrer, | 115 features::kReferrer, |
116 entry->GetReferrer().url.spec().c_str()), | 116 entry->GetReferrer().url.spec().c_str()), |
117 1.0, | 117 1.0, |
118 request); | 118 request); |
119 } | 119 } |
120 AddFeature(feature_prefix + features::kHasSSLReferrer, | 120 AddFeature(feature_prefix + features::kHasSSLReferrer, |
121 is_secure_referrer ? 1.0 : 0.0, | 121 is_secure_referrer ? 1.0 : 0.0, |
122 request); | 122 request); |
123 AddFeature(feature_prefix + features::kPageTransitionType, | 123 AddFeature(feature_prefix + features::kPageTransitionType, |
124 static_cast<double>( | 124 static_cast<double>( |
125 content::PageTransitionStripQualifier( | 125 ui::PageTransitionStripQualifier( |
126 entry->GetTransitionType())), | 126 entry->GetTransitionType())), |
127 request); | 127 request); |
128 AddFeature(feature_prefix + features::kIsFirstNavigation, | 128 AddFeature(feature_prefix + features::kIsFirstNavigation, |
129 index == 0 ? 1.0 : 0.0, | 129 index == 0 ? 1.0 : 0.0, |
130 request); | 130 request); |
131 // Redirect chain should always be at least of size one, as the rendered | 131 // Redirect chain should always be at least of size one, as the rendered |
132 // url is the last element in the chain. | 132 // url is the last element in the chain. |
133 if (redirect_chain.empty()) { | 133 if (redirect_chain.empty()) { |
134 NOTREACHED(); | 134 NOTREACHED(); |
135 return; | 135 return; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 static_cast<double>(row.visit_count()), | 338 static_cast<double>(row.visit_count()), |
339 request.get()); | 339 request.get()); |
340 | 340 |
341 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1); | 341 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1); |
342 int num_visits_24h_ago = 0; | 342 int num_visits_24h_ago = 0; |
343 int num_visits_typed = 0; | 343 int num_visits_typed = 0; |
344 int num_visits_link = 0; | 344 int num_visits_link = 0; |
345 for (history::VisitVector::const_iterator it = visits.begin(); | 345 for (history::VisitVector::const_iterator it = visits.begin(); |
346 it != visits.end(); | 346 it != visits.end(); |
347 ++it) { | 347 ++it) { |
348 if (!content::PageTransitionIsMainFrame(it->transition)) { | 348 if (!ui::PageTransitionIsMainFrame(it->transition)) { |
349 continue; | 349 continue; |
350 } | 350 } |
351 if (it->visit_time < threshold) { | 351 if (it->visit_time < threshold) { |
352 ++num_visits_24h_ago; | 352 ++num_visits_24h_ago; |
353 } | 353 } |
354 content::PageTransition transition = content::PageTransitionStripQualifier( | 354 ui::PageTransition transition = ui::PageTransitionStripQualifier( |
355 it->transition); | 355 it->transition); |
356 if (transition == content::PAGE_TRANSITION_TYPED) { | 356 if (transition == ui::PAGE_TRANSITION_TYPED) { |
357 ++num_visits_typed; | 357 ++num_visits_typed; |
358 } else if (transition == content::PAGE_TRANSITION_LINK) { | 358 } else if (transition == ui::PAGE_TRANSITION_LINK) { |
359 ++num_visits_link; | 359 ++num_visits_link; |
360 } | 360 } |
361 } | 361 } |
362 AddFeature(features::kUrlHistoryVisitCountMoreThan24hAgo, | 362 AddFeature(features::kUrlHistoryVisitCountMoreThan24hAgo, |
363 static_cast<double>(num_visits_24h_ago), | 363 static_cast<double>(num_visits_24h_ago), |
364 request.get()); | 364 request.get()); |
365 AddFeature(features::kUrlHistoryTypedCount, | 365 AddFeature(features::kUrlHistoryTypedCount, |
366 static_cast<double>(num_visits_typed), | 366 static_cast<double>(num_visits_typed), |
367 request.get()); | 367 request.get()); |
368 AddFeature(features::kUrlHistoryLinkCount, | 368 AddFeature(features::kUrlHistoryLinkCount, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |