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 // 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // called with "false" verdicts. Enabling starts downloading the model after | 74 // called with "false" verdicts. Enabling starts downloading the model after |
75 // a delay. In all cases, each render process is updated to match the state | 75 // a delay. In all cases, each render process is updated to match the state |
76 // of the SafeBrowsing preference for that profile. | 76 // of the SafeBrowsing preference for that profile. |
77 void SetEnabledAndRefreshState(bool enabled); | 77 void SetEnabledAndRefreshState(bool enabled); |
78 | 78 |
79 bool enabled() const { | 79 bool enabled() const { |
80 return enabled_; | 80 return enabled_; |
81 } | 81 } |
82 | 82 |
83 // From the content::URLFetcherDelegate interface. | 83 // From the content::URLFetcherDelegate interface. |
84 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 84 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
85 | 85 |
86 // content::NotificationObserver overrides: | 86 // content::NotificationObserver overrides: |
87 virtual void Observe(int type, | 87 virtual void Observe(int type, |
88 const content::NotificationSource& source, | 88 const content::NotificationSource& source, |
89 const content::NotificationDetails& details) OVERRIDE; | 89 const content::NotificationDetails& details) OVERRIDE; |
90 | 90 |
91 // Sends a request to the SafeBrowsing servers with the ClientPhishingRequest. | 91 // Sends a request to the SafeBrowsing servers with the ClientPhishingRequest. |
92 // The URL scheme of the |url()| in the request should be HTTP. This method | 92 // The URL scheme of the |url()| in the request should be HTTP. This method |
93 // takes ownership of the |verdict| as well as the |callback| and calls the | 93 // takes ownership of the |verdict| as well as the |callback| and calls the |
94 // the callback once the result has come back from the server or if an error | 94 // the callback once the result has come back from the server or if an error |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 static const base::TimeDelta kPositiveCacheInterval; | 200 static const base::TimeDelta kPositiveCacheInterval; |
201 | 201 |
202 // Starts sending the request to the client-side detection frontends. | 202 // Starts sending the request to the client-side detection frontends. |
203 // This method takes ownership of both pointers. | 203 // This method takes ownership of both pointers. |
204 void StartClientReportPhishingRequest( | 204 void StartClientReportPhishingRequest( |
205 ClientPhishingRequest* verdict, | 205 ClientPhishingRequest* verdict, |
206 ClientReportPhishingRequestCallback* callback); | 206 ClientReportPhishingRequestCallback* callback); |
207 | 207 |
208 // Called by OnURLFetchComplete to handle the response from fetching the | 208 // Called by OnURLFetchComplete to handle the response from fetching the |
209 // model. | 209 // model. |
210 void HandleModelResponse(const URLFetcher* source, | 210 void HandleModelResponse(const content::URLFetcher* source, |
211 const GURL& url, | 211 const GURL& url, |
212 const net::URLRequestStatus& status, | 212 const net::URLRequestStatus& status, |
213 int response_code, | 213 int response_code, |
214 const net::ResponseCookies& cookies, | 214 const net::ResponseCookies& cookies, |
215 const std::string& data); | 215 const std::string& data); |
216 | 216 |
217 // Called by OnURLFetchComplete to handle the server response from | 217 // Called by OnURLFetchComplete to handle the server response from |
218 // sending the client-side phishing request. | 218 // sending the client-side phishing request. |
219 void HandlePhishingVerdict(const URLFetcher* source, | 219 void HandlePhishingVerdict(const content::URLFetcher* source, |
220 const GURL& url, | 220 const GURL& url, |
221 const net::URLRequestStatus& status, | 221 const net::URLRequestStatus& status, |
222 int response_code, | 222 int response_code, |
223 const net::ResponseCookies& cookies, | 223 const net::ResponseCookies& cookies, |
224 const std::string& data); | 224 const std::string& data); |
225 | 225 |
226 // Invalidate cache results which are no longer useful. | 226 // Invalidate cache results which are no longer useful. |
227 void UpdateCache(); | 227 void UpdateCache(); |
228 | 228 |
229 // Get the number of phishing reports that we have sent over kReportsInterval | 229 // Get the number of phishing reports that we have sent over kReportsInterval |
(...skipping 26 matching lines...) Expand all Loading... |
256 static bool IsFalsePositiveResponse(const GURL& url, | 256 static bool IsFalsePositiveResponse(const GURL& url, |
257 const ClientPhishingResponse& response); | 257 const ClientPhishingResponse& response); |
258 | 258 |
259 // Whether the service is running or not. When the service is not running, | 259 // Whether the service is running or not. When the service is not running, |
260 // it won't download the model nor report detected phishing URLs. | 260 // it won't download the model nor report detected phishing URLs. |
261 bool enabled_; | 261 bool enabled_; |
262 | 262 |
263 std::string model_str_; | 263 std::string model_str_; |
264 scoped_ptr<ClientSideModel> model_; | 264 scoped_ptr<ClientSideModel> model_; |
265 scoped_ptr<base::TimeDelta> model_max_age_; | 265 scoped_ptr<base::TimeDelta> model_max_age_; |
266 scoped_ptr<URLFetcher> model_fetcher_; | 266 scoped_ptr<content::URLFetcher> model_fetcher_; |
267 | 267 |
268 // Map of client report phishing request to the corresponding callback that | 268 // Map of client report phishing request to the corresponding callback that |
269 // has to be invoked when the request is done. | 269 // has to be invoked when the request is done. |
270 struct ClientReportInfo; | 270 struct ClientReportInfo; |
271 std::map<const URLFetcher*, ClientReportInfo*> client_phishing_reports_; | 271 std::map<const content::URLFetcher*, ClientReportInfo*> |
| 272 client_phishing_reports_; |
272 | 273 |
273 // Cache of completed requests. Used to satisfy requests for the same urls | 274 // Cache of completed requests. Used to satisfy requests for the same urls |
274 // as long as the next request falls within our caching window (which is | 275 // as long as the next request falls within our caching window (which is |
275 // determined by kNegativeCacheInterval and kPositiveCacheInterval). The | 276 // determined by kNegativeCacheInterval and kPositiveCacheInterval). The |
276 // size of this cache is limited by kMaxReportsPerDay * | 277 // size of this cache is limited by kMaxReportsPerDay * |
277 // ceil(InDays(max(kNegativeCacheInterval, kPositiveCacheInterval))). | 278 // ceil(InDays(max(kNegativeCacheInterval, kPositiveCacheInterval))). |
278 // TODO(gcasto): Serialize this so that it doesn't reset on browser restart. | 279 // TODO(gcasto): Serialize this so that it doesn't reset on browser restart. |
279 PhishingCache cache_; | 280 PhishingCache cache_; |
280 | 281 |
281 // Timestamp of when we sent a phishing request. Used to limit the number | 282 // Timestamp of when we sent a phishing request. Used to limit the number |
(...skipping 15 matching lines...) Expand all Loading... |
297 // this map to speed up lookups. | 298 // this map to speed up lookups. |
298 BadSubnetMap bad_subnets_; | 299 BadSubnetMap bad_subnets_; |
299 | 300 |
300 content::NotificationRegistrar registrar_; | 301 content::NotificationRegistrar registrar_; |
301 | 302 |
302 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); | 303 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); |
303 }; | 304 }; |
304 } // namepsace safe_browsing | 305 } // namepsace safe_browsing |
305 | 306 |
306 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ | 307 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ |
OLD | NEW |