OLD | NEW |
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_ |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/callback.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 |
| 32 namespace content { |
| 33 class WebContents; |
| 34 } |
32 | 35 |
33 namespace safe_browsing { | 36 namespace safe_browsing { |
34 class ClientPhishingRequest; | 37 class ClientPhishingRequest; |
35 class ClientSideDetectionService; | 38 class ClientSideDetectionService; |
36 | 39 |
37 struct BrowseInfo { | 40 struct BrowseInfo { |
38 // List of IPv4 and IPv6 addresses from which content was requested | 41 // List of IPv4 and IPv6 addresses from which content was requested |
39 // while browsing to the |url|. | 42 // while browsing to the |url|. |
40 std::set<std::string> ips; | 43 std::set<std::string> ips; |
41 | 44 |
(...skipping 20 matching lines...) Expand all Loading... |
62 public: | 65 public: |
63 // Called when feature extraction is done. The first argument will be | 66 // Called when feature extraction is done. The first argument will be |
64 // true iff feature extraction succeeded. The second argument is the | 67 // true iff feature extraction succeeded. The second argument is the |
65 // phishing request which was modified by the feature extractor. The | 68 // phishing request which was modified by the feature extractor. The |
66 // DoneCallback takes ownership of the request object. | 69 // DoneCallback takes ownership of the request object. |
67 typedef base::Callback<void(bool, ClientPhishingRequest*)> DoneCallback; | 70 typedef base::Callback<void(bool, ClientPhishingRequest*)> DoneCallback; |
68 | 71 |
69 // The caller keeps ownership of the tab and service objects and is | 72 // The caller keeps ownership of the tab and service objects and is |
70 // responsible for ensuring that they stay valid for the entire | 73 // responsible for ensuring that they stay valid for the entire |
71 // lifetime of this object. | 74 // lifetime of this object. |
72 BrowserFeatureExtractor(TabContents* tab, | 75 BrowserFeatureExtractor(content::WebContents* tab, |
73 ClientSideDetectionService* service); | 76 ClientSideDetectionService* service); |
74 | 77 |
75 // The destructor will cancel any pending requests. | 78 // The destructor will cancel any pending requests. |
76 virtual ~BrowserFeatureExtractor(); | 79 virtual ~BrowserFeatureExtractor(); |
77 | 80 |
78 // Begins extraction of the browser features. We take ownership | 81 // Begins extraction of the browser features. We take ownership |
79 // of the request object until |callback| is called (see DoneCallback above) | 82 // of the request object until |callback| is called (see DoneCallback above) |
80 // and will write the extracted features to the feature map. Once the | 83 // 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 | 84 // 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 | 85 // take ownership of the |callback| object. |info| may not be valid after |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // is a pending query for the given handle it will return false and set both | 142 // 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. | 143 // the request and cb pointers. Otherwise, it will return false. |
141 bool GetPendingQuery(CancelableRequestProvider::Handle handle, | 144 bool GetPendingQuery(CancelableRequestProvider::Handle handle, |
142 ClientPhishingRequest** request, | 145 ClientPhishingRequest** request, |
143 DoneCallback* callback); | 146 DoneCallback* callback); |
144 | 147 |
145 // Helper function which gets the history server if possible. If the pointer | 148 // Helper function which gets the history server if possible. If the pointer |
146 // is set it will return true and false otherwise. | 149 // is set it will return true and false otherwise. |
147 bool GetHistoryService(HistoryService** history); | 150 bool GetHistoryService(HistoryService** history); |
148 | 151 |
149 TabContents* tab_; | 152 content::WebContents* tab_; |
150 ClientSideDetectionService* service_; | 153 ClientSideDetectionService* service_; |
151 CancelableRequestConsumer request_consumer_; | 154 CancelableRequestConsumer request_consumer_; |
152 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_; | 155 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_; |
153 | 156 |
154 // Set of pending extractions (i.e. extractions for which ExtractFeatures was | 157 // Set of pending extractions (i.e. extractions for which ExtractFeatures was |
155 // called but not StartExtractFeatures). | 158 // called but not StartExtractFeatures). |
156 std::map<ClientPhishingRequest*, DoneCallback> pending_extractions_; | 159 std::map<ClientPhishingRequest*, DoneCallback> pending_extractions_; |
157 | 160 |
158 // Set of pending queries (i.e., where history->Query...() was called but | 161 // Set of pending queries (i.e., where history->Query...() was called but |
159 // the history callback hasn't been invoked yet). | 162 // the history callback hasn't been invoked yet). |
160 PendingQueriesMap pending_queries_; | 163 PendingQueriesMap pending_queries_; |
161 | 164 |
162 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor); | 165 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor); |
163 }; | 166 }; |
164 | 167 |
165 } // namespace safe_browsing | 168 } // namespace safe_browsing |
166 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ | 169 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ |
OLD | NEW |