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

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

Issue 10392192: Remove content::URLFetcherDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More cleanup Created 8 years, 7 months 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 | Annotate | Revision Log
OLDNEW
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 13 matching lines...) Expand all
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/browser/notification_observer.h" 32 #include "content/public/browser/notification_observer.h"
33 #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" 34 #include "googleurl/src/gurl.h"
36 #include "net/base/net_util.h" 35 #include "net/base/net_util.h"
36 #include "net/url_request/url_fetcher_delegate.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 {
45 class RenderProcessHost; 45 class RenderProcessHost;
46 } 46 }
47 47
48 namespace net { 48 namespace net {
49 class URLFetcher;
49 class URLRequestContextGetter; 50 class URLRequestContextGetter;
50 class URLRequestStatus; 51 class URLRequestStatus;
51 typedef std::vector<std::string> ResponseCookies; 52 typedef std::vector<std::string> ResponseCookies;
52 } // namespace net 53 } // namespace net
53 54
54 namespace safe_browsing { 55 namespace safe_browsing {
55 class ClientPhishingRequest; 56 class ClientPhishingRequest;
56 class ClientPhishingResponse; 57 class ClientPhishingResponse;
57 class ClientSideModel; 58 class ClientSideModel;
58 59
59 class ClientSideDetectionService : public content::URLFetcherDelegate, 60 class ClientSideDetectionService : public net::URLFetcherDelegate,
60 public content::NotificationObserver { 61 public content::NotificationObserver {
61 public: 62 public:
62 // void(GURL phishing_url, bool is_phishing). 63 // void(GURL phishing_url, bool is_phishing).
63 typedef base::Callback<void(GURL, bool)> ClientReportPhishingRequestCallback; 64 typedef base::Callback<void(GURL, bool)> ClientReportPhishingRequestCallback;
64 65
65 virtual ~ClientSideDetectionService(); 66 virtual ~ClientSideDetectionService();
66 67
67 // Creates a client-side detection service. The service is initially 68 // Creates a client-side detection service. The service is initially
68 // disabled, use SetEnabledAndRefreshState() to start it. The caller takes 69 // disabled, use SetEnabledAndRefreshState() to start it. The caller takes
69 // ownership of the object. This function may return NULL. 70 // ownership of the object. This function may return NULL.
70 static ClientSideDetectionService* Create( 71 static ClientSideDetectionService* Create(
71 net::URLRequestContextGetter* request_context_getter); 72 net::URLRequestContextGetter* request_context_getter);
72 73
73 // Enables or disables the service, and refreshes the state of all renderers. 74 // Enables or disables the service, and refreshes the state of all renderers.
74 // This is usually called by the SafeBrowsingService, which tracks whether 75 // This is usually called by the SafeBrowsingService, which tracks whether
75 // any profile uses these services at all. Disabling cancels any pending 76 // any profile uses these services at all. Disabling cancels any pending
76 // requests; existing ClientSideDetectionHosts will have their callbacks 77 // requests; existing ClientSideDetectionHosts will have their callbacks
77 // called with "false" verdicts. Enabling starts downloading the model after 78 // 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 79 // a delay. In all cases, each render process is updated to match the state
79 // of the SafeBrowsing preference for that profile. 80 // of the SafeBrowsing preference for that profile.
80 void SetEnabledAndRefreshState(bool enabled); 81 void SetEnabledAndRefreshState(bool enabled);
81 82
82 bool enabled() const { 83 bool enabled() const {
83 return enabled_; 84 return enabled_;
84 } 85 }
85 86
86 // From the content::URLFetcherDelegate interface. 87 // From the net::URLFetcherDelegate interface.
87 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 88 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
88 89
89 // content::NotificationObserver overrides: 90 // content::NotificationObserver overrides:
90 virtual void Observe(int type, 91 virtual void Observe(int type,
91 const content::NotificationSource& source, 92 const content::NotificationSource& source,
92 const content::NotificationDetails& details) OVERRIDE; 93 const content::NotificationDetails& details) OVERRIDE;
93 94
94 // Sends a request to the SafeBrowsing servers with the ClientPhishingRequest. 95 // 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 96 // 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 97 // takes ownership of the |verdict| as well as the |callback| and calls the
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // valid hashes in the model. 252 // valid hashes in the model.
252 static bool ModelHasValidHashIds(const ClientSideModel& model); 253 static bool ModelHasValidHashIds(const ClientSideModel& model);
253 254
254 // Whether the service is running or not. When the service is not running, 255 // Whether the service is running or not. When the service is not running,
255 // it won't download the model nor report detected phishing URLs. 256 // it won't download the model nor report detected phishing URLs.
256 bool enabled_; 257 bool enabled_;
257 258
258 std::string model_str_; 259 std::string model_str_;
259 scoped_ptr<ClientSideModel> model_; 260 scoped_ptr<ClientSideModel> model_;
260 scoped_ptr<base::TimeDelta> model_max_age_; 261 scoped_ptr<base::TimeDelta> model_max_age_;
261 scoped_ptr<content::URLFetcher> model_fetcher_; 262 scoped_ptr<net::URLFetcher> model_fetcher_;
262 263
263 // Map of client report phishing request to the corresponding callback that 264 // Map of client report phishing request to the corresponding callback that
264 // has to be invoked when the request is done. 265 // has to be invoked when the request is done.
265 struct ClientReportInfo; 266 struct ClientReportInfo;
266 std::map<const net::URLFetcher*, ClientReportInfo*> 267 std::map<const net::URLFetcher*, ClientReportInfo*>
267 client_phishing_reports_; 268 client_phishing_reports_;
268 269
269 // Cache of completed requests. Used to satisfy requests for the same urls 270 // 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 271 // as long as the next request falls within our caching window (which is
271 // determined by kNegativeCacheInterval and kPositiveCacheInterval). The 272 // determined by kNegativeCacheInterval and kPositiveCacheInterval). The
(...skipping 21 matching lines...) Expand all
293 // this map to speed up lookups. 294 // this map to speed up lookups.
294 BadSubnetMap bad_subnets_; 295 BadSubnetMap bad_subnets_;
295 296
296 content::NotificationRegistrar registrar_; 297 content::NotificationRegistrar registrar_;
297 298
298 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); 299 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService);
299 }; 300 };
300 } // namepsace safe_browsing 301 } // namepsace safe_browsing
301 302
302 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ 303 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_downloader.h ('k') | chrome/browser/safe_browsing/download_protection_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698