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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 class HistoryService; | 31 class HistoryService; |
32 | 32 |
33 namespace content { | 33 namespace content { |
34 class WebContents; | 34 class WebContents; |
35 } | 35 } |
36 | 36 |
37 namespace safe_browsing { | 37 namespace safe_browsing { |
38 class ClientMalwareRequest; | 38 class ClientMalwareRequest; |
39 class ClientPhishingRequest; | 39 class ClientPhishingRequest; |
40 class ClientSideDetectionService; | 40 class ClientSideDetectionHost; |
41 | 41 |
42 typedef std::map<std::string, std::set<std::string> > IPUrlMap; | 42 typedef std::map<std::string, std::set<std::string> > IPUrlMap; |
43 | 43 |
44 struct BrowseInfo { | 44 struct BrowseInfo { |
45 // List of IPv4 and IPv6 addresses from which content was requested | 45 // List of IPv4 and IPv6 addresses from which content was requested |
46 // together with the hosts on it, while browsing to the |url|. | 46 // together with the hosts on it, while browsing to the |url|. |
47 IPUrlMap ips; | 47 IPUrlMap ips; |
48 | 48 |
49 // If a SafeBrowsing interstitial was shown for the current URL | 49 // If a SafeBrowsing interstitial was shown for the current URL |
50 // this will contain the UnsafeResource struct for that URL. | 50 // this will contain the UnsafeResource struct for that URL. |
(...skipping 14 matching lines...) Expand all Loading... |
65 | 65 |
66 // All methods of this class must be called on the UI thread (including | 66 // All methods of this class must be called on the UI thread (including |
67 // the constructor). | 67 // the constructor). |
68 class BrowserFeatureExtractor { | 68 class BrowserFeatureExtractor { |
69 public: | 69 public: |
70 // Called when feature extraction is done. The first argument will be | 70 // Called when feature extraction is done. The first argument will be |
71 // true iff feature extraction succeeded. The second argument is the | 71 // true iff feature extraction succeeded. The second argument is the |
72 // phishing request which was modified by the feature extractor. The | 72 // phishing request which was modified by the feature extractor. The |
73 // DoneCallback takes ownership of the request object. | 73 // DoneCallback takes ownership of the request object. |
74 typedef base::Callback<void(bool, ClientPhishingRequest*)> DoneCallback; | 74 typedef base::Callback<void(bool, ClientPhishingRequest*)> DoneCallback; |
75 typedef base::Callback<void(bool, ClientMalwareRequest*)> MalwareDoneCallback; | 75 typedef base::Callback<void(bool, scoped_ptr<ClientMalwareRequest>)> |
| 76 MalwareDoneCallback; |
76 | 77 |
77 // The caller keeps ownership of the tab and service objects and is | 78 // The caller keeps ownership of the tab and host objects and is |
78 // responsible for ensuring that they stay valid for the entire | 79 // responsible for ensuring that they stay valid for the entire |
79 // lifetime of this object. | 80 // lifetime of this object. |
80 BrowserFeatureExtractor(content::WebContents* tab, | 81 BrowserFeatureExtractor(content::WebContents* tab, |
81 ClientSideDetectionService* service); | 82 ClientSideDetectionHost* host); |
82 | 83 |
83 // The destructor will cancel any pending requests. | 84 // The destructor will cancel any pending requests. |
84 virtual ~BrowserFeatureExtractor(); | 85 virtual ~BrowserFeatureExtractor(); |
85 | 86 |
86 // Begins extraction of the browser features. We take ownership | 87 // Begins extraction of the browser features. We take ownership |
87 // of the request object until |callback| is called (see DoneCallback above) | 88 // of the request object until |callback| is called (see DoneCallback above) |
88 // and will write the extracted features to the feature map. Once the | 89 // and will write the extracted features to the feature map. Once the |
89 // feature extraction is complete, |callback| is run on the UI thread. We | 90 // feature extraction is complete, |callback| is run on the UI thread. We |
90 // take ownership of the |callback| object. |info| may not be valid after | 91 // take ownership of the |callback| object. |info| may not be valid after |
91 // ExtractFeatures returns. This method must run on the UI thread. | 92 // ExtractFeatures returns. This method must run on the UI thread. |
92 virtual void ExtractFeatures(const BrowseInfo* info, | 93 virtual void ExtractFeatures(const BrowseInfo* info, |
93 ClientPhishingRequest* request, | 94 ClientPhishingRequest* request, |
94 const DoneCallback& callback); | 95 const DoneCallback& callback); |
95 | 96 |
96 // Extract the malware related features. The request object is owned by the | 97 // Begins extraction of the malware related features. We take ownership |
97 // caller. | 98 // of the request object until |callback| is called. Once feature extraction |
98 virtual void ExtractMalwareFeatures(const BrowseInfo* info, | 99 // is complete, |callback| will run on the UI thread. |info| is not expected |
99 ClientMalwareRequest* request); | 100 // to stay valid after ExtractMalwareFeatures returns. All IPs stored in |
| 101 // |info| will be cleared by calling this function. |
| 102 virtual void ExtractMalwareFeatures(BrowseInfo* info, |
| 103 ClientMalwareRequest* request, |
| 104 const MalwareDoneCallback& callback); |
100 | 105 |
101 private: | 106 private: |
102 friend class base::DeleteHelper<BrowserFeatureExtractor>; | 107 friend class base::DeleteHelper<BrowserFeatureExtractor>; |
103 typedef std::pair<ClientPhishingRequest*, DoneCallback> ExtractionData; | 108 typedef std::pair<ClientPhishingRequest*, DoneCallback> ExtractionData; |
104 typedef std::map<CancelableRequestProvider::Handle, | 109 typedef std::map<CancelableRequestProvider::Handle, |
105 ExtractionData> PendingQueriesMap; | 110 ExtractionData> PendingQueriesMap; |
106 | 111 |
107 // Synchronous browser feature extraction. | 112 // Synchronous browser feature extraction. |
108 void ExtractBrowseInfoFeatures(const BrowseInfo& info, | 113 void ExtractBrowseInfoFeatures(const BrowseInfo& info, |
109 ClientPhishingRequest* request); | 114 ClientPhishingRequest* request); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // is a pending query for the given handle it will return false and set both | 157 // is a pending query for the given handle it will return false and set both |
153 // the request and cb pointers. Otherwise, it will return false. | 158 // the request and cb pointers. Otherwise, it will return false. |
154 bool GetPendingQuery(CancelableRequestProvider::Handle handle, | 159 bool GetPendingQuery(CancelableRequestProvider::Handle handle, |
155 ClientPhishingRequest** request, | 160 ClientPhishingRequest** request, |
156 DoneCallback* callback); | 161 DoneCallback* callback); |
157 | 162 |
158 // Helper function which gets the history server if possible. If the pointer | 163 // Helper function which gets the history server if possible. If the pointer |
159 // is set it will return true and false otherwise. | 164 // is set it will return true and false otherwise. |
160 bool GetHistoryService(HistoryService** history); | 165 bool GetHistoryService(HistoryService** history); |
161 | 166 |
| 167 // Helper function which is called when we're done filtering out benign IPs |
| 168 // on the IO thread. This function is called on the UI thread. |
| 169 void FinishExtractMalwareFeatures(scoped_ptr<IPUrlMap> bad_ips, |
| 170 MalwareDoneCallback callback, |
| 171 scoped_ptr<ClientMalwareRequest> request); |
| 172 |
162 content::WebContents* tab_; | 173 content::WebContents* tab_; |
163 ClientSideDetectionService* service_; | 174 ClientSideDetectionHost* host_; |
164 CancelableRequestConsumer request_consumer_; | 175 CancelableRequestConsumer request_consumer_; |
165 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_; | 176 base::WeakPtrFactory<BrowserFeatureExtractor> weak_factory_; |
166 | 177 |
167 // Set of pending extractions (i.e. extractions for which ExtractFeatures was | 178 // Set of pending extractions (i.e. extractions for which ExtractFeatures was |
168 // called but not StartExtractFeatures). | 179 // called but not StartExtractFeatures). |
169 std::map<ClientPhishingRequest*, DoneCallback> pending_extractions_; | 180 std::map<ClientPhishingRequest*, DoneCallback> pending_extractions_; |
170 | 181 |
171 // Set of pending queries (i.e., where history->Query...() was called but | 182 // Set of pending queries (i.e., where history->Query...() was called but |
172 // the history callback hasn't been invoked yet). | 183 // the history callback hasn't been invoked yet). |
173 PendingQueriesMap pending_queries_; | 184 PendingQueriesMap pending_queries_; |
174 | 185 |
175 // Max number of malware IPs can be sent in one malware request | |
176 static const int kMaxMalwareIPPerRequest; | |
177 | |
178 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor); | 186 DISALLOW_COPY_AND_ASSIGN(BrowserFeatureExtractor); |
179 }; | 187 }; |
180 | 188 |
181 } // namespace safe_browsing | 189 } // namespace safe_browsing |
182 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ | 190 #endif // CHROME_BROWSER_SAFE_BROWSING_BROWSER_FEATURE_EXTRACTOR_H_ |
OLD | NEW |