OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Helper class which handles communication with the SafeBrowsing backends for | 5 // Helper class which handles communication with the SafeBrowsing backends for |
6 // client-side phishing detection. This class is used to fetch the client-side | 6 // client-side phishing detection. This class is used to fetch the client-side |
7 // model and send it to all renderers. This class is also used to send a ping | 7 // model and send it to all renderers. This class is also used to send a ping |
8 // back to Google to verify if a particular site is really phishing or not. | 8 // back to Google to verify if a particular site is really phishing or not. |
9 // | 9 // |
10 // This class is not thread-safe and expects all calls to be made on the UI | 10 // This class is not thread-safe and expects all calls to be made on the UI |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include <vector> | 22 #include <vector> |
23 | 23 |
24 #include "base/basictypes.h" | 24 #include "base/basictypes.h" |
25 #include "base/callback_forward.h" | 25 #include "base/callback_forward.h" |
26 #include "base/gtest_prod_util.h" | 26 #include "base/gtest_prod_util.h" |
27 #include "base/memory/linked_ptr.h" | 27 #include "base/memory/linked_ptr.h" |
28 #include "base/memory/ref_counted.h" | 28 #include "base/memory/ref_counted.h" |
29 #include "base/memory/scoped_ptr.h" | 29 #include "base/memory/scoped_ptr.h" |
30 #include "base/memory/weak_ptr.h" | 30 #include "base/memory/weak_ptr.h" |
31 #include "base/time.h" | 31 #include "base/time.h" |
32 #include "content/public/common/url_fetcher_delegate.h" | |
33 #include "content/public/browser/notification_observer.h" | 32 #include "content/public/browser/notification_observer.h" |
34 #include "content/public/browser/notification_registrar.h" | 33 #include "content/public/browser/notification_registrar.h" |
| 34 #include "content/public/common/url_fetcher_delegate.h" |
35 #include "googleurl/src/gurl.h" | 35 #include "googleurl/src/gurl.h" |
36 #include "net/base/net_util.h" | 36 #include "net/base/net_util.h" |
37 | 37 |
38 class SafeBrowsingService; | 38 class SafeBrowsingService; |
39 | 39 |
40 namespace base { | 40 namespace base { |
41 class TimeDelta; | 41 class TimeDelta; |
42 } | 42 } |
43 | 43 |
44 namespace content { | 44 namespace content { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // called with "false" verdicts. Enabling starts downloading the model after | 77 // called with "false" verdicts. Enabling starts downloading the model after |
78 // a delay. In all cases, each render process is updated to match the state | 78 // a delay. In all cases, each render process is updated to match the state |
79 // of the SafeBrowsing preference for that profile. | 79 // of the SafeBrowsing preference for that profile. |
80 void SetEnabledAndRefreshState(bool enabled); | 80 void SetEnabledAndRefreshState(bool enabled); |
81 | 81 |
82 bool enabled() const { | 82 bool enabled() const { |
83 return enabled_; | 83 return enabled_; |
84 } | 84 } |
85 | 85 |
86 // From the content::URLFetcherDelegate interface. | 86 // From the content::URLFetcherDelegate interface. |
87 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 87 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
88 | 88 |
89 // content::NotificationObserver overrides: | 89 // content::NotificationObserver overrides: |
90 virtual void Observe(int type, | 90 virtual void Observe(int type, |
91 const content::NotificationSource& source, | 91 const content::NotificationSource& source, |
92 const content::NotificationDetails& details) OVERRIDE; | 92 const content::NotificationDetails& details) OVERRIDE; |
93 | 93 |
94 // Sends a request to the SafeBrowsing servers with the ClientPhishingRequest. | 94 // Sends a request to the SafeBrowsing servers with the ClientPhishingRequest. |
95 // The URL scheme of the |url()| in the request should be HTTP. This method | 95 // The URL scheme of the |url()| in the request should be HTTP. This method |
96 // takes ownership of the |verdict| as well as the |callback| and calls the | 96 // takes ownership of the |verdict| as well as the |callback| and calls the |
97 // the callback once the result has come back from the server or if an error | 97 // the callback once the result has come back from the server or if an error |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 static const int kPositiveCacheIntervalMinutes; | 201 static const int kPositiveCacheIntervalMinutes; |
202 | 202 |
203 // Starts sending the request to the client-side detection frontends. | 203 // Starts sending the request to the client-side detection frontends. |
204 // This method takes ownership of both pointers. | 204 // This method takes ownership of both pointers. |
205 void StartClientReportPhishingRequest( | 205 void StartClientReportPhishingRequest( |
206 ClientPhishingRequest* verdict, | 206 ClientPhishingRequest* verdict, |
207 const ClientReportPhishingRequestCallback& callback); | 207 const ClientReportPhishingRequestCallback& callback); |
208 | 208 |
209 // Called by OnURLFetchComplete to handle the response from fetching the | 209 // Called by OnURLFetchComplete to handle the response from fetching the |
210 // model. | 210 // model. |
211 void HandleModelResponse(const content::URLFetcher* source, | 211 void HandleModelResponse(const net::URLFetcher* source, |
212 const GURL& url, | 212 const GURL& url, |
213 const net::URLRequestStatus& status, | 213 const net::URLRequestStatus& status, |
214 int response_code, | 214 int response_code, |
215 const net::ResponseCookies& cookies, | 215 const net::ResponseCookies& cookies, |
216 const std::string& data); | 216 const std::string& data); |
217 | 217 |
218 // Called by OnURLFetchComplete to handle the server response from | 218 // Called by OnURLFetchComplete to handle the server response from |
219 // sending the client-side phishing request. | 219 // sending the client-side phishing request. |
220 void HandlePhishingVerdict(const content::URLFetcher* source, | 220 void HandlePhishingVerdict(const net::URLFetcher* source, |
221 const GURL& url, | 221 const GURL& url, |
222 const net::URLRequestStatus& status, | 222 const net::URLRequestStatus& status, |
223 int response_code, | 223 int response_code, |
224 const net::ResponseCookies& cookies, | 224 const net::ResponseCookies& cookies, |
225 const std::string& data); | 225 const std::string& data); |
226 | 226 |
227 // Invalidate cache results which are no longer useful. | 227 // Invalidate cache results which are no longer useful. |
228 void UpdateCache(); | 228 void UpdateCache(); |
229 | 229 |
230 // Get the number of phishing reports that we have sent over kReportsInterval | 230 // Get the number of phishing reports that we have sent over kReportsInterval |
(...skipping 25 matching lines...) Expand all Loading... |
256 bool enabled_; | 256 bool enabled_; |
257 | 257 |
258 std::string model_str_; | 258 std::string model_str_; |
259 scoped_ptr<ClientSideModel> model_; | 259 scoped_ptr<ClientSideModel> model_; |
260 scoped_ptr<base::TimeDelta> model_max_age_; | 260 scoped_ptr<base::TimeDelta> model_max_age_; |
261 scoped_ptr<content::URLFetcher> model_fetcher_; | 261 scoped_ptr<content::URLFetcher> model_fetcher_; |
262 | 262 |
263 // Map of client report phishing request to the corresponding callback that | 263 // Map of client report phishing request to the corresponding callback that |
264 // has to be invoked when the request is done. | 264 // has to be invoked when the request is done. |
265 struct ClientReportInfo; | 265 struct ClientReportInfo; |
266 std::map<const content::URLFetcher*, ClientReportInfo*> | 266 std::map<const net::URLFetcher*, ClientReportInfo*> |
267 client_phishing_reports_; | 267 client_phishing_reports_; |
268 | 268 |
269 // Cache of completed requests. Used to satisfy requests for the same urls | 269 // Cache of completed requests. Used to satisfy requests for the same urls |
270 // as long as the next request falls within our caching window (which is | 270 // as long as the next request falls within our caching window (which is |
271 // determined by kNegativeCacheInterval and kPositiveCacheInterval). The | 271 // determined by kNegativeCacheInterval and kPositiveCacheInterval). The |
272 // size of this cache is limited by kMaxReportsPerDay * | 272 // size of this cache is limited by kMaxReportsPerDay * |
273 // ceil(InDays(max(kNegativeCacheInterval, kPositiveCacheInterval))). | 273 // ceil(InDays(max(kNegativeCacheInterval, kPositiveCacheInterval))). |
274 // TODO(gcasto): Serialize this so that it doesn't reset on browser restart. | 274 // TODO(gcasto): Serialize this so that it doesn't reset on browser restart. |
275 PhishingCache cache_; | 275 PhishingCache cache_; |
276 | 276 |
(...skipping 16 matching lines...) Expand all Loading... |
293 // this map to speed up lookups. | 293 // this map to speed up lookups. |
294 BadSubnetMap bad_subnets_; | 294 BadSubnetMap bad_subnets_; |
295 | 295 |
296 content::NotificationRegistrar registrar_; | 296 content::NotificationRegistrar registrar_; |
297 | 297 |
298 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); | 298 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); |
299 }; | 299 }; |
300 } // namepsace safe_browsing | 300 } // namepsace safe_browsing |
301 | 301 |
302 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ | 302 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ |
OLD | NEW |