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

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

Issue 351363002: Revert of Port HistoryService::GetVisibleVisitCountToHost to CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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"
23 #include "base/task/cancelable_task_tracker.h" 24 #include "base/task/cancelable_task_tracker.h"
24 #include "base/time/time.h" 25 #include "base/time/time.h"
26 #include "chrome/browser/common/cancelable_request.h"
25 #include "chrome/browser/history/history_types.h" 27 #include "chrome/browser/history/history_types.h"
26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
27 #include "chrome/browser/safe_browsing/ui_manager.h" 29 #include "chrome/browser/safe_browsing/ui_manager.h"
28 #include "url/gurl.h" 30 #include "url/gurl.h"
29 #include "webkit/common/resource_type.h" 31 #include "webkit/common/resource_type.h"
30 32
31 33
32 class HistoryService; 34 class HistoryService;
33 35
34 namespace content { 36 namespace content {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 }; 90 };
89 91
90 // All methods of this class must be called on the UI thread (including 92 // All methods of this class must be called on the UI thread (including
91 // the constructor). 93 // the constructor).
92 class BrowserFeatureExtractor { 94 class BrowserFeatureExtractor {
93 public: 95 public:
94 // Called when feature extraction is done. The first argument will be 96 // Called when feature extraction is done. The first argument will be
95 // true iff feature extraction succeeded. The second argument is the 97 // true iff feature extraction succeeded. The second argument is the
96 // phishing request which was modified by the feature extractor. The 98 // phishing request which was modified by the feature extractor. The
97 // DoneCallback takes ownership of the request object. 99 // DoneCallback takes ownership of the request object.
98 typedef base::Callback<void(bool, scoped_ptr<ClientPhishingRequest>)> 100 typedef base::Callback<void(bool, ClientPhishingRequest*)> DoneCallback;
99 DoneCallback;
100 typedef base::Callback<void(bool, scoped_ptr<ClientMalwareRequest>)> 101 typedef base::Callback<void(bool, scoped_ptr<ClientMalwareRequest>)>
101 MalwareDoneCallback; 102 MalwareDoneCallback;
102 103
103 // The caller keeps ownership of the tab and host objects and is 104 // The caller keeps ownership of the tab and host objects and is
104 // responsible for ensuring that they stay valid for the entire 105 // responsible for ensuring that they stay valid for the entire
105 // lifetime of this object. 106 // lifetime of this object.
106 BrowserFeatureExtractor(content::WebContents* tab, 107 BrowserFeatureExtractor(content::WebContents* tab,
107 ClientSideDetectionHost* host); 108 ClientSideDetectionHost* host);
108 109
109 // The destructor will cancel any pending requests. 110 // The destructor will cancel any pending requests.
(...skipping 12 matching lines...) Expand all
122 // Begins extraction of the malware related features. We take ownership 123 // Begins extraction of the malware related features. We take ownership
123 // of the request object until |callback| is called. Once feature extraction 124 // of the request object until |callback| is called. Once feature extraction
124 // is complete, |callback| will run on the UI thread. |info| is not expected 125 // is complete, |callback| will run on the UI thread. |info| is not expected
125 // to stay valid after ExtractMalwareFeatures returns. All IPs stored in 126 // to stay valid after ExtractMalwareFeatures returns. All IPs stored in
126 // |info| will be cleared by calling this function. 127 // |info| will be cleared by calling this function.
127 virtual void ExtractMalwareFeatures(BrowseInfo* info, 128 virtual void ExtractMalwareFeatures(BrowseInfo* info,
128 ClientMalwareRequest* request, 129 ClientMalwareRequest* request,
129 const MalwareDoneCallback& callback); 130 const MalwareDoneCallback& callback);
130 131
131 private: 132 private:
133 friend class base::DeleteHelper<BrowserFeatureExtractor>;
134 typedef std::pair<ClientPhishingRequest*, DoneCallback> ExtractionData;
135 typedef std::map<CancelableRequestProvider::Handle,
136 ExtractionData> PendingQueriesMap;
137
132 // Synchronous browser feature extraction. 138 // Synchronous browser feature extraction.
133 void ExtractBrowseInfoFeatures(const BrowseInfo& info, 139 void ExtractBrowseInfoFeatures(const BrowseInfo& info,
134 ClientPhishingRequest* request); 140 ClientPhishingRequest* request);
135 141
136 // Actually starts feature extraction (does the real work). 142 // Actually starts feature extraction (does the real work).
137 void StartExtractFeatures(scoped_ptr<ClientPhishingRequest> request, 143 void StartExtractFeatures(ClientPhishingRequest* request,
138 const DoneCallback& callback); 144 const DoneCallback& callback);
139 145
140 // HistoryService callback which is called when we're done querying URL visits 146 // HistoryService callback which is called when we're done querying URL visits
141 // in the history. 147 // in the history.
142 void QueryUrlHistoryDone(scoped_ptr<ClientPhishingRequest> request, 148 void QueryUrlHistoryDone(scoped_ptr<ClientPhishingRequest> request,
143 const DoneCallback& callback, 149 const DoneCallback& callback,
144 bool success, 150 bool success,
145 const history::URLRow& row, 151 const history::URLRow& row,
146 const history::VisitVector& visits); 152 const history::VisitVector& visits);
147 153
148 // HistoryService callback which is called when we're done querying HTTP host 154 // HistoryService callback which is called when we're done querying HTTP host
149 // visits in the history. 155 // visits in the history.
150 void QueryHttpHostVisitsDone(scoped_ptr<ClientPhishingRequest> request, 156 void QueryHttpHostVisitsDone(CancelableRequestProvider::Handle handle,
151 const DoneCallback& callback,
152 bool success, 157 bool success,
153 int num_visits, 158 int num_visits,
154 base::Time first_visit); 159 base::Time first_visit);
155 160
156 // HistoryService callback which is called when we're done querying HTTPS host 161 // HistoryService callback which is called when we're done querying HTTPS host
157 // visits in the history. 162 // visits in the history.
158 void QueryHttpsHostVisitsDone(scoped_ptr<ClientPhishingRequest> request, 163 void QueryHttpsHostVisitsDone(CancelableRequestProvider::Handle handle,
159 const DoneCallback& callback,
160 bool success, 164 bool success,
161 int num_visits, 165 int num_visits,
162 base::Time first_visit); 166 base::Time first_visit);
163 167
164 // Helper function which sets the host history features given the 168 // Helper function which sets the host history features given the
165 // number of host visits and the time of the fist host visit. Set 169 // number of host visits and the time of the fist host visit. Set
166 // |is_http_query| to true if the URL scheme is HTTP and to false if 170 // |is_http_query| to true if the URL scheme is HTTP and to false if
167 // the scheme is HTTPS. 171 // the scheme is HTTPS.
168 void SetHostVisitsFeatures(int num_visits, 172 void SetHostVisitsFeatures(int num_visits,
169 base::Time first_visit, 173 base::Time first_visit,
170 bool is_http_query, 174 bool is_http_query,
171 ClientPhishingRequest* request); 175 ClientPhishingRequest* request);
172 176
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
173 // Helper function which gets the history server if possible. If the pointer 190 // Helper function which gets the history server if possible. If the pointer
174 // is set it will return true and false otherwise. 191 // is set it will return true and false otherwise.
175 bool GetHistoryService(HistoryService** history); 192 bool GetHistoryService(HistoryService** history);
176 193
177 // Helper function which is called when we're done filtering out benign IPs 194 // Helper function which is called when we're done filtering out benign IPs
178 // on the IO thread. This function is called on the UI thread. 195 // on the IO thread. This function is called on the UI thread.
179 void FinishExtractMalwareFeatures(scoped_ptr<IPUrlMap> bad_ips, 196 void FinishExtractMalwareFeatures(scoped_ptr<IPUrlMap> bad_ips,
180 MalwareDoneCallback callback, 197 MalwareDoneCallback callback,
181 scoped_ptr<ClientMalwareRequest> request); 198 scoped_ptr<ClientMalwareRequest> request);
182 199
183 content::WebContents* tab_; 200 content::WebContents* tab_;
184 ClientSideDetectionHost* host_; 201 ClientSideDetectionHost* host_;
202 CancelableRequestConsumer request_consumer_;
185 base::CancelableTaskTracker cancelable_task_tracker_; 203 base::CancelableTaskTracker cancelable_task_tracker_;
186 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_; 204 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_;
187 205
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
188 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor); 214 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor);
189 }; 215 };
190 216
191 } // namespace safe_browsing 217 } // namespace safe_browsing
192 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ 218 #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