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

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

Issue 7635010: Add support for client-side phishing detection for non-UMA users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename method Created 9 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 | Annotate | Revision Log
OLDNEW
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/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/task.h" 12 #include "base/task.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "chrome/common/safe_browsing/csd.pb.h" 14 #include "chrome/common/safe_browsing/csd.pb.h"
15 #include "chrome/browser/history/history.h" 15 #include "chrome/browser/history/history.h"
16 #include "chrome/browser/history/history_types.h" 16 #include "chrome/browser/history/history_types.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/safe_browsing/browser_features.h"
18 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 19 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
20 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
19 #include "content/common/page_transition_types.h" 21 #include "content/common/page_transition_types.h"
20 #include "content/browser/browser_thread.h" 22 #include "content/browser/browser_thread.h"
21 #include "content/browser/cancelable_request.h" 23 #include "content/browser/cancelable_request.h"
22 #include "content/browser/tab_contents/tab_contents.h" 24 #include "content/browser/tab_contents/tab_contents.h"
25 #include "crypto/sha2.h"
23 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
24 27
25 namespace safe_browsing { 28 namespace safe_browsing {
26 namespace features {
27 const char kUrlHistoryVisitCount[] = "UrlHistoryVisitCount";
28 const char kUrlHistoryTypedCount[] = "UrlHistoryTypedCount";
29 const char kUrlHistoryLinkCount[] = "UrlHistoryLinkCount";
30 const char kUrlHistoryVisitCountMoreThan24hAgo[] =
31 "UrlHistoryVisitCountMoreThan24hAgo";
32 const char kHttpHostVisitCount[] = "HttpHostVisitCount";
33 const char kHttpsHostVisitCount[] = "HttpsHostVisitCount";
34 const char kFirstHttpHostVisitMoreThan24hAgo[] =
35 "FirstHttpHostVisitMoreThan24hAgo";
36 const char kFirstHttpsHostVisitMoreThan24hAgo[] =
37 "FirstHttpsHostVisitMoreThan24hAgo";
38 29
39 const char kHostPrefix[] = "Host"; 30 const int BrowserFeatureExtractor::kSuffixPrefixHashLength = 5;
40 const char kRedirectPrefix[] = "Redirect";
41 const char kReferrer[] = "Referrer";
42 const char kHasSSLReferrer[] = "HasSSLReferrer";
43 const char kPageTransitionType[] = "PageTransitionType";
44 const char kIsFirstNavigation[] = "IsFirstNavigation";
45 const char kBadIpFetch[] = "BadIpFetch=";
46 const char kSafeBrowsingMaliciousUrl[] = "SafeBrowsingMaliciousUrl=";
47 const char kSafeBrowsingOriginalUrl[] = "SafeBrowsingOriginalUrl=";
48 const char kSafeBrowsingIsSubresource[] = "SafeBrowsingIsSubresource";
49 const char kSafeBrowsingThreatType[] = "SafeBrowsingThreatType";
50 } // namespace features
51 31
52 BrowseInfo::BrowseInfo() {} 32 BrowseInfo::BrowseInfo() {}
53 33
54 BrowseInfo::~BrowseInfo() {} 34 BrowseInfo::~BrowseInfo() {}
55 35
56 static void AddFeature(const std::string& feature_name, 36 static void AddFeature(const std::string& feature_name,
57 double feature_value, 37 double feature_value,
58 ClientPhishingRequest* request) { 38 ClientPhishingRequest* request) {
59 DCHECK(request); 39 DCHECK(request);
60 ClientPhishingRequest::Feature* feature = 40 ClientPhishingRequest::Feature* feature =
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 controller, 184 controller,
205 first_host_index, 185 first_host_index,
206 request); 186 request);
207 PossiblyAddRedirectNavigationFeatures(features::kHostPrefix, 187 PossiblyAddRedirectNavigationFeatures(features::kHostPrefix,
208 controller, 188 controller,
209 first_host_index, 189 first_host_index,
210 request); 190 request);
211 } 191 }
212 192
213 ExtractBrowseInfoFeatures(*info, request); 193 ExtractBrowseInfoFeatures(*info, request);
194 ComputeURLHash(request);
214 pending_extractions_.insert(std::make_pair(request, callback)); 195 pending_extractions_.insert(std::make_pair(request, callback));
215 MessageLoop::current()->PostTask( 196 MessageLoop::current()->PostTask(
216 FROM_HERE, 197 FROM_HERE,
217 method_factory_.NewRunnableMethod( 198 method_factory_.NewRunnableMethod(
218 &BrowserFeatureExtractor::StartExtractFeatures, 199 &BrowserFeatureExtractor::StartExtractFeatures,
219 request, callback)); 200 request, callback));
220 } 201 }
221 202
222 void BrowserFeatureExtractor::ExtractBrowseInfoFeatures( 203 void BrowserFeatureExtractor::ExtractBrowseInfoFeatures(
223 const BrowseInfo& info, 204 const BrowseInfo& info,
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 Profile* profile = Profile::FromBrowserContext(tab_->browser_context()); 437 Profile* profile = Profile::FromBrowserContext(tab_->browser_context());
457 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); 438 *history = profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
458 if (*history) { 439 if (*history) {
459 return true; 440 return true;
460 } 441 }
461 } 442 }
462 VLOG(2) << "Unable to query history. No history service available."; 443 VLOG(2) << "Unable to query history. No history service available.";
463 return false; 444 return false;
464 } 445 }
465 446
447 void BrowserFeatureExtractor::ComputeURLHash(
448 ClientPhishingRequest* request) {
449 // Put the url into SafeBrowsing host suffix / path prefix format, with
450 // query parameters stripped.
451 std::string host, path, query;
452 safe_browsing_util::CanonicalizeUrl(GURL(request->url()),
453 &host, &path, &query);
454 DCHECK(!host.empty()) << request->url();
455 DCHECK(!path.empty()) << request->url();
456 request->set_suffix_prefix_hash(
457 crypto::SHA256HashString(host + path).substr(
458 0, kSuffixPrefixHashLength));
459 }
460
466 }; // namespace safe_browsing 461 }; // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698