OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/task.h" | 16 #include "base/task.h" |
17 #include "base/time.h" | 17 #include "base/time.h" |
18 #include "chrome/common/safe_browsing/csd.pb.h" | 18 #include "chrome/common/safe_browsing/csd.pb.h" |
19 #include "chrome/browser/history/history.h" | 19 #include "chrome/browser/history/history.h" |
20 #include "chrome/browser/history/history_types.h" | 20 #include "chrome/browser/history/history_types.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/safe_browsing/browser_features.h" | 22 #include "chrome/browser/safe_browsing/browser_features.h" |
23 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 23 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
24 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 24 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
25 #include "content/common/page_transition_types.h" | |
26 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
27 #include "content/browser/cancelable_request.h" | 26 #include "content/browser/cancelable_request.h" |
28 #include "content/browser/tab_contents/tab_contents.h" | 27 #include "content/browser/tab_contents/tab_contents.h" |
| 28 #include "content/public/common/page_transition_types.h" |
29 #include "crypto/sha2.h" | 29 #include "crypto/sha2.h" |
30 #include "googleurl/src/gurl.h" | 30 #include "googleurl/src/gurl.h" |
31 | 31 |
32 namespace safe_browsing { | 32 namespace safe_browsing { |
33 | 33 |
34 const int BrowserFeatureExtractor::kHashPrefixLength = 5; | 34 const int BrowserFeatureExtractor::kHashPrefixLength = 5; |
35 | 35 |
36 BrowseInfo::BrowseInfo() {} | 36 BrowseInfo::BrowseInfo() {} |
37 | 37 |
38 BrowseInfo::~BrowseInfo() {} | 38 BrowseInfo::~BrowseInfo() {} |
(...skipping 22 matching lines...) Expand all Loading... |
61 features::kReferrer, | 61 features::kReferrer, |
62 entry->referrer().spec().c_str()), | 62 entry->referrer().spec().c_str()), |
63 1.0, | 63 1.0, |
64 request); | 64 request); |
65 } | 65 } |
66 AddFeature(feature_prefix + features::kHasSSLReferrer, | 66 AddFeature(feature_prefix + features::kHasSSLReferrer, |
67 is_secure_referrer ? 1.0 : 0.0, | 67 is_secure_referrer ? 1.0 : 0.0, |
68 request); | 68 request); |
69 AddFeature(feature_prefix + features::kPageTransitionType, | 69 AddFeature(feature_prefix + features::kPageTransitionType, |
70 static_cast<double>( | 70 static_cast<double>( |
71 PageTransition::StripQualifier(entry->transition_type())), | 71 content::PageTransitionStripQualifier( |
| 72 entry->transition_type())), |
72 request); | 73 request); |
73 AddFeature(feature_prefix + features::kIsFirstNavigation, | 74 AddFeature(feature_prefix + features::kIsFirstNavigation, |
74 index == 0 ? 1.0 : 0.0, | 75 index == 0 ? 1.0 : 0.0, |
75 request); | 76 request); |
76 // Redirect chain should always be at least of size one, as the rendered | 77 // Redirect chain should always be at least of size one, as the rendered |
77 // url is the last element in the chain. | 78 // url is the last element in the chain. |
78 if (redirect_chain.empty()) { | 79 if (redirect_chain.empty()) { |
79 NOTREACHED(); | 80 NOTREACHED(); |
80 return; | 81 return; |
81 } | 82 } |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 AddFeature(features::kUrlHistoryVisitCount, | 289 AddFeature(features::kUrlHistoryVisitCount, |
289 static_cast<double>(row->visit_count()), | 290 static_cast<double>(row->visit_count()), |
290 request); | 291 request); |
291 | 292 |
292 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1); | 293 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1); |
293 int num_visits_24h_ago = 0; | 294 int num_visits_24h_ago = 0; |
294 int num_visits_typed = 0; | 295 int num_visits_typed = 0; |
295 int num_visits_link = 0; | 296 int num_visits_link = 0; |
296 for (history::VisitVector::const_iterator it = visits->begin(); | 297 for (history::VisitVector::const_iterator it = visits->begin(); |
297 it != visits->end(); ++it) { | 298 it != visits->end(); ++it) { |
298 if (!PageTransition::IsMainFrame(it->transition)) { | 299 if (!content::PageTransitionIsMainFrame(it->transition)) { |
299 continue; | 300 continue; |
300 } | 301 } |
301 if (it->visit_time < threshold) { | 302 if (it->visit_time < threshold) { |
302 ++num_visits_24h_ago; | 303 ++num_visits_24h_ago; |
303 } | 304 } |
304 PageTransition::Type transition = PageTransition::StripQualifier( | 305 content::PageTransition transition = content::PageTransitionStripQualifier( |
305 it->transition); | 306 it->transition); |
306 if (transition == PageTransition::TYPED) { | 307 if (transition == content::PAGE_TRANSITION_TYPED) { |
307 ++num_visits_typed; | 308 ++num_visits_typed; |
308 } else if (transition == PageTransition::LINK) { | 309 } else if (transition == content::PAGE_TRANSITION_LINK) { |
309 ++num_visits_link; | 310 ++num_visits_link; |
310 } | 311 } |
311 } | 312 } |
312 AddFeature(features::kUrlHistoryVisitCountMoreThan24hAgo, | 313 AddFeature(features::kUrlHistoryVisitCountMoreThan24hAgo, |
313 static_cast<double>(num_visits_24h_ago), | 314 static_cast<double>(num_visits_24h_ago), |
314 request); | 315 request); |
315 AddFeature(features::kUrlHistoryTypedCount, | 316 AddFeature(features::kUrlHistoryTypedCount, |
316 static_cast<double>(num_visits_typed), | 317 static_cast<double>(num_visits_typed), |
317 request); | 318 request); |
318 AddFeature(features::kUrlHistoryLinkCount, | 319 AddFeature(features::kUrlHistoryLinkCount, |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 // Remove everything that comes after the last '/'. | 481 // Remove everything that comes after the last '/'. |
481 size_t last_path = path.rfind("/"); | 482 size_t last_path = path.rfind("/"); |
482 path.erase(last_path + 1); | 483 path.erase(last_path + 1); |
483 } | 484 } |
484 | 485 |
485 request->set_hash_prefix(crypto::SHA256HashString(host + path).substr( | 486 request->set_hash_prefix(crypto::SHA256HashString(host + path).substr( |
486 0, kHashPrefixLength)); | 487 0, kHashPrefixLength)); |
487 } | 488 } |
488 | 489 |
489 }; // namespace safe_browsing | 490 }; // namespace safe_browsing |
OLD | NEW |