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

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

Issue 7119003: Create a browser feature extractor that runs after the renderer has (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address Pawel's comments Created 9 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4 //
5 // BrowserFeatureExtractor computes various browser features for client-side
6 // phishing detection. For now it does a bunch of lookups in the history
7 // service to see whether a particular URL has been visited before by the
8 // user.
9
10 #ifndef CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_
11 #define CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_
12 #pragma once
13
14 #include <map>
15 #include <set>
16 #include <utility>
17
18 #include "base/basictypes.h"
19 #include "base/callback_old.h"
20 #include "base/task.h"
21 #include "base/time.h"
22 #include "chrome/browser/history/history_types.h"
23 #include "content/browser/cancelable_request.h"
24
25 class HistoryService;
26 class TabContents;
27
28 namespace safe_browsing {
29 class ClientPhishingRequest;
30
31 namespace features {
32
33 // TODO(noelutz): move renderer/safe_browsing/features.h to common.
34 ////////////////////////////////////////////////////
35 // History featres.
mattm 2011/06/08 23:18:18 typo
noelutz 2011/06/09 19:21:39 Done.
36 ////////////////////////////////////////////////////
37
38 // Number of visits to that URL stored in the browser history.
39 // Should always be an integer larger than 1 because by the time
40 // we lookup the history the current URL should already be stored there.
41 extern const char kUrlHistoryVisitCount[];
42
43 // Number of times the URL was typed in the Omnibox.
44 extern const char kUrlHistoryTypedCount[];
45
46 // Number of times the URL was reached by clicking a link.
47 extern const char kUrlHistoryLinkCount[];
48
49 // Number of times URL was visited more than 24h ago.
50 extern const char kUrlHistoryVisitCount24hAgo[];
mattm 2011/06/08 23:18:18 Maybe this one should have MoreThan in the name to
noelutz 2011/06/09 19:21:39 Done.
51
52 // Number of user-visible visits to all URLs on the same host/port as
53 // the URL for HTTP and HTTPs.
54 extern const char kHttpHostVisitCount[];
55 extern const char kHttpsHostVisitCount[];
56
57 // Boolean feature which is true if the host was visited for the first
58 // time more than 24h ago (only considers user-visible visits like above).
59 extern const char kFirstHttpHostVisitMoreThan24hAgo[];
60 extern const char kFirstHttpsHostVisitMoreThan24hAgo[];
61 } // namespace features
62
63 // All methods of this class must be called on the UI thread (including
64 // the constructor).
65 class BrowserFeatureExtractor {
66 public:
67 // Called when feature extraction is done. The first argument will be
68 // true iff feature extraction succeeded. The second argument is the
69 // phishing request which was modified by the feature extractor. The
70 // DoneCallback takes ownership of the request object.
71 typedef Callback2<bool, ClientPhishingRequest*>::Type DoneCallback;
72
73 // The caller keeps ownership of the tab object and is responsible for
74 // ensuring that it stays valid for the entire lifetime of this object.
75 explicit BrowserFeatureExtractor(TabContents* tab);
76
77 // The destructor will cancel any pending requests.
78 ~BrowserFeatureExtractor();
79
80 // Begins extraction of the browser features. We take ownership
81 // of the request object and will write the extracted features to the
82 // feature map. Once the feature extraction is complete, |done_callback|
83 // is run on the UI thread. We take ownership of the |done_callback|
84 // object. This method must run on the UI thread.
85 void ExtractFeatures(ClientPhishingRequest* request,
86 DoneCallback* callback);
87
88 private:
89 friend class DeleteTask<BrowserFeatureExtractor>;
90 typedef std::pair<ClientPhishingRequest*, DoneCallback*> ExtractionData;
91 typedef std::map<CancelableRequestProvider::Handle,
92 ExtractionData> PendingQueriesMap;
93
94 // Actually starts feature extraction (does the real work).
95 void StartExtractFeatures(ClientPhishingRequest* request,
96 DoneCallback* callback);
97
98 // HistoryService callback which is called when we're done querying URL visits
99 // in the history.
100 void QueryUrlHistoryDone(CancelableRequestProvider::Handle handle,
101 bool success,
102 const history::URLRow* row,
103 history::VisitVector* visits);
104
105 // HistoryService callback which is called when we're done querying HTTP host
106 // visits in the history.
107 void QueryHttpHostVisitsDone(CancelableRequestProvider::Handle handle,
108 bool success,
109 int num_visits,
110 base::Time first_visit);
111
112 // HistoryService callback which is called when we're done querying HTTPS host
113 // visits in the history.
114 void QueryHttpsHostVisitsDone(CancelableRequestProvider::Handle handle,
115 bool success,
116 int num_visits,
117 base::Time first_visit);
118
119 // Helper function which sets the host history features given the
120 // number of host visits and the time of the fist host visit. Set
121 // |is_http_query| to true if the URL scheme is HTTP and to false if
122 // the scheme is HTTPS.
123 void SetHostVisitsFeatures(int num_visits,
124 base::Time first_visit,
125 bool is_http_query,
126 ClientPhishingRequest* request);
127
128 // Helper function which stores the request and callback while the history
129 // query is being processed.
130 void StorePendingQuery(CancelableRequestProvider::Handle handle,
131 ClientPhishingRequest* request,
132 DoneCallback* callback);
133
134 // Helper function which is the counterpart of StorePendingQuery. If there
135 // is a pending query for the given handle it will return false and set both
136 // the request and cb pointers. Otherwise, it will return false.
137 bool GetPendingQuery(CancelableRequestProvider::Handle handle,
138 ClientPhishingRequest** request,
139 DoneCallback** callback);
140
141 // Helper function which gets the history server if possible. If the pointer
142 // is set it will return true and false otherwise.
143 bool GetHistoryService(HistoryService** history);
144
145 TabContents* tab_;
146 CancelableRequestConsumer request_consumer_;
147 ScopedRunnableMethodFactory<BrowserFeatureExtractor> method_factory_;
148
149 // Set of pending extractions (i.e. extractions for which ExtractFeatures was
150 // called but not StartExtractFeatures).
151 std::set<ExtractionData> pending_extractions_;
152
153 // Set of pending queries (i.e., where history->Query...() was called but
154 // the history callback hasn't been invoked yet).
155 PendingQueriesMap pending_queries_;
156
157 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor);
158 };
159 } // namespace safe_browsing
160 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698