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

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

Issue 8573018: Convert to base::Callback in safe_browsing client-side-detection code. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Don't call Run() on null callbacks. Created 9 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/browser_feature_extractor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #pragma once 12 #pragma once
13 13
14 #include <map> 14 #include <map>
15 #include <set> 15 #include <set>
16 #include <string> 16 #include <string>
17 #include <utility> 17 #include <utility>
18 #include <vector> 18 #include <vector>
19 19
20 #include "base/basictypes.h" 20 #include "base/basictypes.h"
21 #include "base/callback_old.h" 21 #include "base/callback.h"
22 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
23 #include "base/task.h" 23 #include "base/task.h"
24 #include "base/time.h" 24 #include "base/time.h"
25 #include "chrome/browser/history/history_types.h" 25 #include "chrome/browser/history/history_types.h"
26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
27 #include "content/browser/cancelable_request.h" 27 #include "content/browser/cancelable_request.h"
28 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
29 29
30 class HistoryService; 30 class HistoryService;
31 class TabContents; 31 class TabContents;
(...skipping 25 matching lines...) Expand all
57 }; 57 };
58 58
59 // All methods of this class must be called on the UI thread (including 59 // All methods of this class must be called on the UI thread (including
60 // the constructor). 60 // the constructor).
61 class BrowserFeatureExtractor { 61 class BrowserFeatureExtractor {
62 public: 62 public:
63 // Called when feature extraction is done. The first argument will be 63 // Called when feature extraction is done. The first argument will be
64 // true iff feature extraction succeeded. The second argument is the 64 // true iff feature extraction succeeded. The second argument is the
65 // phishing request which was modified by the feature extractor. The 65 // phishing request which was modified by the feature extractor. The
66 // DoneCallback takes ownership of the request object. 66 // DoneCallback takes ownership of the request object.
67 typedef Callback2<bool, ClientPhishingRequest*>::Type DoneCallback; 67 typedef base::Callback<void(bool, ClientPhishingRequest*)> DoneCallback;
68 68
69 // The caller keeps ownership of the tab and service objects and is 69 // The caller keeps ownership of the tab and service objects and is
70 // responsible for ensuring that they stay valid for the entire 70 // responsible for ensuring that they stay valid for the entire
71 // lifetime of this object. 71 // lifetime of this object.
72 BrowserFeatureExtractor(TabContents* tab, 72 BrowserFeatureExtractor(TabContents* tab,
73 ClientSideDetectionService* service); 73 ClientSideDetectionService* service);
74 74
75 // The destructor will cancel any pending requests. 75 // The destructor will cancel any pending requests.
76 virtual ~BrowserFeatureExtractor(); 76 virtual ~BrowserFeatureExtractor();
77 77
78 // Begins extraction of the browser features. We take ownership 78 // Begins extraction of the browser features. We take ownership
79 // of the request object until |callback| is called (see DoneCallback above) 79 // of the request object until |callback| is called (see DoneCallback above)
80 // and will write the extracted features to the feature map. Once the 80 // and will write the extracted features to the feature map. Once the
81 // feature extraction is complete, |callback| is run on the UI thread. We 81 // feature extraction is complete, |callback| is run on the UI thread. We
82 // take ownership of the |callback| object. |info| may not be valid after 82 // take ownership of the |callback| object. |info| may not be valid after
83 // ExtractFeatures returns. This method must run on the UI thread. 83 // ExtractFeatures returns. This method must run on the UI thread.
84 virtual void ExtractFeatures(const BrowseInfo* info, 84 virtual void ExtractFeatures(const BrowseInfo* info,
85 ClientPhishingRequest* request, 85 ClientPhishingRequest* request,
86 DoneCallback* callback); 86 const DoneCallback& callback);
87 87
88 private: 88 private:
89 friend class DeleteTask<BrowserFeatureExtractor>; 89 friend class DeleteTask<BrowserFeatureExtractor>;
90 typedef std::pair<ClientPhishingRequest*, DoneCallback*> ExtractionData; 90 typedef std::pair<ClientPhishingRequest*, DoneCallback> ExtractionData;
91 typedef std::map<CancelableRequestProvider::Handle, 91 typedef std::map<CancelableRequestProvider::Handle,
92 ExtractionData> PendingQueriesMap; 92 ExtractionData> PendingQueriesMap;
93 93
94 // Synchronous browser feature extraction. 94 // Synchronous browser feature extraction.
95 void ExtractBrowseInfoFeatures(const BrowseInfo& info, 95 void ExtractBrowseInfoFeatures(const BrowseInfo& info,
96 ClientPhishingRequest* request); 96 ClientPhishingRequest* request);
97 97
98 // Actually starts feature extraction (does the real work). 98 // Actually starts feature extraction (does the real work).
99 void StartExtractFeatures(ClientPhishingRequest* request, 99 void StartExtractFeatures(ClientPhishingRequest* request,
100 DoneCallback* callback); 100 const DoneCallback& callback);
101 101
102 // HistoryService callback which is called when we're done querying URL visits 102 // HistoryService callback which is called when we're done querying URL visits
103 // in the history. 103 // in the history.
104 void QueryUrlHistoryDone(CancelableRequestProvider::Handle handle, 104 void QueryUrlHistoryDone(CancelableRequestProvider::Handle handle,
105 bool success, 105 bool success,
106 const history::URLRow* row, 106 const history::URLRow* row,
107 history::VisitVector* visits); 107 history::VisitVector* visits);
108 108
109 // HistoryService callback which is called when we're done querying HTTP host 109 // HistoryService callback which is called when we're done querying HTTP host
110 // visits in the history. 110 // visits in the history.
(...skipping 15 matching lines...) Expand all
126 // the scheme is HTTPS. 126 // the scheme is HTTPS.
127 void SetHostVisitsFeatures(int num_visits, 127 void SetHostVisitsFeatures(int num_visits,
128 base::Time first_visit, 128 base::Time first_visit,
129 bool is_http_query, 129 bool is_http_query,
130 ClientPhishingRequest* request); 130 ClientPhishingRequest* request);
131 131
132 // Helper function which stores the request and callback while the history 132 // Helper function which stores the request and callback while the history
133 // query is being processed. 133 // query is being processed.
134 void StorePendingQuery(CancelableRequestProvider::Handle handle, 134 void StorePendingQuery(CancelableRequestProvider::Handle handle,
135 ClientPhishingRequest* request, 135 ClientPhishingRequest* request,
136 DoneCallback* callback); 136 const DoneCallback& callback);
137 137
138 // Helper function which is the counterpart of StorePendingQuery. If there 138 // Helper function which is the counterpart of StorePendingQuery. If there
139 // is a pending query for the given handle it will return false and set both 139 // is a pending query for the given handle it will return false and set both
140 // the request and cb pointers. Otherwise, it will return false. 140 // the request and cb pointers. Otherwise, it will return false.
141 bool GetPendingQuery(CancelableRequestProvider::Handle handle, 141 bool GetPendingQuery(CancelableRequestProvider::Handle handle,
142 ClientPhishingRequest** request, 142 ClientPhishingRequest** request,
143 DoneCallback** callback); 143 DoneCallback* callback);
144 144
145 // Helper function which gets the history server if possible. If the pointer 145 // Helper function which gets the history server if possible. If the pointer
146 // is set it will return true and false otherwise. 146 // is set it will return true and false otherwise.
147 bool GetHistoryService(HistoryService** history); 147 bool GetHistoryService(HistoryService** history);
148 148
149 TabContents* tab_; 149 TabContents* tab_;
150 ClientSideDetectionService* service_; 150 ClientSideDetectionService* service_;
151 CancelableRequestConsumer request_consumer_; 151 CancelableRequestConsumer request_consumer_;
152 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_; 152 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_;
153 153
154 // Set of pending extractions (i.e. extractions for which ExtractFeatures was 154 // Set of pending extractions (i.e. extractions for which ExtractFeatures was
155 // called but not StartExtractFeatures). 155 // called but not StartExtractFeatures).
156 std::set<ExtractionData> pending_extractions_; 156 std::map<ClientPhishingRequest*, DoneCallback> pending_extractions_;
157 157
158 // Set of pending queries (i.e., where history->Query...() was called but 158 // Set of pending queries (i.e., where history->Query...() was called but
159 // the history callback hasn't been invoked yet). 159 // the history callback hasn't been invoked yet).
160 PendingQueriesMap pending_queries_; 160 PendingQueriesMap pending_queries_;
161 161
162 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor); 162 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor);
163 }; 163 };
164
164 } // namespace safe_browsing 165 } // namespace safe_browsing
165 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ 166 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/browser_feature_extractor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698