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

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

Issue 351553004: Port HistoryService::GetVisibleVisitCountToHost to CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Linux ASAN tests Created 6 years, 5 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 // BrowserFeatureExtractor computes various browser features for client-side 5 // BrowserFeatureExtractor computes various browser features for client-side
6 // phishing detection. For now it does a bunch of lookups in the history 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 7 // service to see whether a particular URL has been visited before by the
8 // user. 8 // user.
9 9
10 #ifndef CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ 10 #ifndef CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_
11 #define CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ 11 #define CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_
12 12
13 #include <map> 13 #include <map>
14 #include <set> 14 #include <set>
15 #include <string> 15 #include <string>
16 #include <utility> 16 #include <utility>
17 #include <vector> 17 #include <vector>
18 18
19 #include "base/basictypes.h" 19 #include "base/basictypes.h"
20 #include "base/callback.h" 20 #include "base/callback.h"
21 #include "base/containers/hash_tables.h" 21 #include "base/containers/hash_tables.h"
22 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
23 #include "base/sequenced_task_runner_helpers.h"
24 #include "base/task/cancelable_task_tracker.h" 23 #include "base/task/cancelable_task_tracker.h"
25 #include "base/time/time.h" 24 #include "base/time/time.h"
26 #include "chrome/browser/common/cancelable_request.h"
27 #include "chrome/browser/history/history_types.h" 25 #include "chrome/browser/history/history_types.h"
28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
29 #include "chrome/browser/safe_browsing/ui_manager.h" 27 #include "chrome/browser/safe_browsing/ui_manager.h"
30 #include "url/gurl.h" 28 #include "url/gurl.h"
31 #include "webkit/common/resource_type.h" 29 #include "webkit/common/resource_type.h"
32 30
33 31
34 class HistoryService; 32 class HistoryService;
35 33
36 namespace content { 34 namespace content {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 }; 88 };
91 89
92 // All methods of this class must be called on the UI thread (including 90 // All methods of this class must be called on the UI thread (including
93 // the constructor). 91 // the constructor).
94 class BrowserFeatureExtractor { 92 class BrowserFeatureExtractor {
95 public: 93 public:
96 // Called when feature extraction is done. The first argument will be 94 // Called when feature extraction is done. The first argument will be
97 // true iff feature extraction succeeded. The second argument is the 95 // true iff feature extraction succeeded. The second argument is the
98 // phishing request which was modified by the feature extractor. The 96 // phishing request which was modified by the feature extractor. The
99 // DoneCallback takes ownership of the request object. 97 // DoneCallback takes ownership of the request object.
100 typedef base::Callback<void(bool, ClientPhishingRequest*)> DoneCallback; 98 typedef base::Callback<void(bool, scoped_ptr<ClientPhishingRequest>)>
99 DoneCallback;
101 typedef base::Callback<void(bool, scoped_ptr<ClientMalwareRequest>)> 100 typedef base::Callback<void(bool, scoped_ptr<ClientMalwareRequest>)>
102 MalwareDoneCallback; 101 MalwareDoneCallback;
103 102
104 // The caller keeps ownership of the tab and host objects and is 103 // The caller keeps ownership of the tab and host objects and is
105 // responsible for ensuring that they stay valid for the entire 104 // responsible for ensuring that they stay valid for the entire
106 // lifetime of this object. 105 // lifetime of this object.
107 BrowserFeatureExtractor(content::WebContents* tab, 106 BrowserFeatureExtractor(content::WebContents* tab,
108 ClientSideDetectionHost* host); 107 ClientSideDetectionHost* host);
109 108
110 // The destructor will cancel any pending requests. 109 // The destructor will cancel any pending requests.
(...skipping 12 matching lines...) Expand all
123 // Begins extraction of the malware related features. We take ownership 122 // Begins extraction of the malware related features. We take ownership
124 // of the request object until |callback| is called. Once feature extraction 123 // of the request object until |callback| is called. Once feature extraction
125 // is complete, |callback| will run on the UI thread. |info| is not expected 124 // is complete, |callback| will run on the UI thread. |info| is not expected
126 // to stay valid after ExtractMalwareFeatures returns. All IPs stored in 125 // to stay valid after ExtractMalwareFeatures returns. All IPs stored in
127 // |info| will be cleared by calling this function. 126 // |info| will be cleared by calling this function.
128 virtual void ExtractMalwareFeatures(BrowseInfo* info, 127 virtual void ExtractMalwareFeatures(BrowseInfo* info,
129 ClientMalwareRequest* request, 128 ClientMalwareRequest* request,
130 const MalwareDoneCallback& callback); 129 const MalwareDoneCallback& callback);
131 130
132 private: 131 private:
133 friend class base::DeleteHelper<BrowserFeatureExtractor>;
134 typedef std::pair<ClientPhishingRequest*, DoneCallback> ExtractionData;
135 typedef std::map<CancelableRequestProvider::Handle,
136 ExtractionData> PendingQueriesMap;
137
138 // Synchronous browser feature extraction. 132 // Synchronous browser feature extraction.
139 void ExtractBrowseInfoFeatures(const BrowseInfo& info, 133 void ExtractBrowseInfoFeatures(const BrowseInfo& info,
140 ClientPhishingRequest* request); 134 ClientPhishingRequest* request);
141 135
142 // Actually starts feature extraction (does the real work). 136 // Actually starts feature extraction (does the real work).
143 void StartExtractFeatures(ClientPhishingRequest* request, 137 void StartExtractFeatures(scoped_ptr<ClientPhishingRequest> request,
144 const DoneCallback& callback); 138 const DoneCallback& callback);
145 139
146 // HistoryService callback which is called when we're done querying URL visits 140 // HistoryService callback which is called when we're done querying URL visits
147 // in the history. 141 // in the history.
148 void QueryUrlHistoryDone(scoped_ptr<ClientPhishingRequest> request, 142 void QueryUrlHistoryDone(scoped_ptr<ClientPhishingRequest> request,
149 const DoneCallback& callback, 143 const DoneCallback& callback,
150 bool success, 144 bool success,
151 const history::URLRow& row, 145 const history::URLRow& row,
152 const history::VisitVector& visits); 146 const history::VisitVector& visits);
153 147
154 // HistoryService callback which is called when we're done querying HTTP host 148 // HistoryService callback which is called when we're done querying HTTP host
155 // visits in the history. 149 // visits in the history.
156 void QueryHttpHostVisitsDone(CancelableRequestProvider::Handle handle, 150 void QueryHttpHostVisitsDone(scoped_ptr<ClientPhishingRequest> request,
151 const DoneCallback& callback,
157 bool success, 152 bool success,
158 int num_visits, 153 int num_visits,
159 base::Time first_visit); 154 base::Time first_visit);
160 155
161 // HistoryService callback which is called when we're done querying HTTPS host 156 // HistoryService callback which is called when we're done querying HTTPS host
162 // visits in the history. 157 // visits in the history.
163 void QueryHttpsHostVisitsDone(CancelableRequestProvider::Handle handle, 158 void QueryHttpsHostVisitsDone(scoped_ptr<ClientPhishingRequest> request,
159 const DoneCallback& callback,
164 bool success, 160 bool success,
165 int num_visits, 161 int num_visits,
166 base::Time first_visit); 162 base::Time first_visit);
167 163
168 // Helper function which sets the host history features given the 164 // Helper function which sets the host history features given the
169 // number of host visits and the time of the fist host visit. Set 165 // number of host visits and the time of the fist host visit. Set
170 // |is_http_query| to true if the URL scheme is HTTP and to false if 166 // |is_http_query| to true if the URL scheme is HTTP and to false if
171 // the scheme is HTTPS. 167 // the scheme is HTTPS.
172 void SetHostVisitsFeatures(int num_visits, 168 void SetHostVisitsFeatures(int num_visits,
173 base::Time first_visit, 169 base::Time first_visit,
174 bool is_http_query, 170 bool is_http_query,
175 ClientPhishingRequest* request); 171 ClientPhishingRequest* request);
176 172
177 // Helper function which stores the request and callback while the history
178 // query is being processed.
179 void StorePendingQuery(CancelableRequestProvider::Handle handle,
180 ClientPhishingRequest* request,
181 const DoneCallback& callback);
182
183 // Helper function which is the counterpart of StorePendingQuery. If there
184 // is a pending query for the given handle it will return false and set both
185 // the request and cb pointers. Otherwise, it will return false.
186 bool GetPendingQuery(CancelableRequestProvider::Handle handle,
187 ClientPhishingRequest** request,
188 DoneCallback* callback);
189
190 // Helper function which gets the history server if possible. If the pointer 173 // Helper function which gets the history server if possible. If the pointer
191 // is set it will return true and false otherwise. 174 // is set it will return true and false otherwise.
192 bool GetHistoryService(HistoryService** history); 175 bool GetHistoryService(HistoryService** history);
193 176
194 // Helper function which is called when we're done filtering out benign IPs 177 // Helper function which is called when we're done filtering out benign IPs
195 // on the IO thread. This function is called on the UI thread. 178 // on the IO thread. This function is called on the UI thread.
196 void FinishExtractMalwareFeatures(scoped_ptr<IPUrlMap> bad_ips, 179 void FinishExtractMalwareFeatures(scoped_ptr<IPUrlMap> bad_ips,
197 MalwareDoneCallback callback, 180 MalwareDoneCallback callback,
198 scoped_ptr<ClientMalwareRequest> request); 181 scoped_ptr<ClientMalwareRequest> request);
199 182
200 content::WebContents* tab_; 183 content::WebContents* tab_;
201 ClientSideDetectionHost* host_; 184 ClientSideDetectionHost* host_;
202 CancelableRequestConsumer request_consumer_;
203 base::CancelableTaskTracker cancelable_task_tracker_; 185 base::CancelableTaskTracker cancelable_task_tracker_;
204 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_; 186 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_;
205 187
206 // Set of pending extractions (i.e. extractions for which ExtractFeatures was
207 // called but not StartExtractFeatures).
208 std::map<ClientPhishingRequest*, DoneCallback> pending_extractions_;
209
210 // Set of pending queries (i.e., where history->Query...() was called but
211 // the history callback hasn't been invoked yet).
212 PendingQueriesMap pending_queries_;
213
214 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor); 188 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor);
215 }; 189 };
216 190
217 } // namespace safe_browsing 191 } // namespace safe_browsing
218 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ 192 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/history/history_types.h ('k') | chrome/browser/safe_browsing/browser_feature_extractor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698