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

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

Issue 7583007: Add "enabled" state to the ClientSideDetectionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 9 years, 4 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) 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 class ClientSideModel; 51 class ClientSideModel;
52 52
53 class ClientSideDetectionService : public URLFetcher::Delegate, 53 class ClientSideDetectionService : public URLFetcher::Delegate,
54 public NotificationObserver { 54 public NotificationObserver {
55 public: 55 public:
56 typedef Callback2<GURL /* phishing URL */, bool /* is phishing */>::Type 56 typedef Callback2<GURL /* phishing URL */, bool /* is phishing */>::Type
57 ClientReportPhishingRequestCallback; 57 ClientReportPhishingRequestCallback;
58 58
59 virtual ~ClientSideDetectionService(); 59 virtual ~ClientSideDetectionService();
60 60
61 // Creates a client-side detection service and starts fetching the client-side 61 // Creates a client-side detection service. The service is initially
62 // detection model if necessary. The caller takes ownership of the object. 62 // disabled, use SetEnabled() to start it. The caller takes ownership of the
63 // This function may return NULL. 63 // object. This function may return NULL.
64 static ClientSideDetectionService* Create( 64 static ClientSideDetectionService* Create(
65 net::URLRequestContextGetter* request_context_getter); 65 net::URLRequestContextGetter* request_context_getter);
66 66
67 // Enables or disables the service. This is usually called by the
68 // SafeBrowsingService, which tracks whether any profile uses these services
69 // at all. Disabling cancels any pending requests; existing
70 // ClientSideDetectionHosts will have their callbacks called with "false"
71 // verdicts. Enabling starts downloading the model after a delay.
72 void SetEnabled(bool enabled);
73
74 bool enabled() const {
75 return enabled_;
76 }
77
67 // From the URLFetcher::Delegate interface. 78 // From the URLFetcher::Delegate interface.
68 virtual void OnURLFetchComplete(const URLFetcher* source, 79 virtual void OnURLFetchComplete(const URLFetcher* source,
69 const GURL& url, 80 const GURL& url,
70 const net::URLRequestStatus& status, 81 const net::URLRequestStatus& status,
71 int response_code, 82 int response_code,
72 const net::ResponseCookies& cookies, 83 const net::ResponseCookies& cookies,
73 const std::string& data) OVERRIDE; 84 const std::string& data) OVERRIDE;
74 85
75 // NotificationObserver overrides: 86 // NotificationObserver overrides:
76 virtual void Observe(int type, 87 virtual void Observe(int type,
77 const NotificationSource& source, 88 const NotificationSource& source,
78 const NotificationDetails& details) OVERRIDE; 89 const NotificationDetails& details) OVERRIDE;
79 90
80 // Sends a request to the SafeBrowsing servers with the ClientPhishingRequest. 91 // Sends a request to the SafeBrowsing servers with the ClientPhishingRequest.
81 // 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
82 // 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
83 // 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
84 // occurs during the fetch. If an error occurs the phishing verdict will 95 // occurs during the fetch. If the service is disabled or an error occurs
85 // always be false. The callback is always called after 96 // the phishing verdict will always be false. The callback is always called
86 // SendClientReportPhishingRequest() returns and on the same thread as 97 // after SendClientReportPhishingRequest() returns and on the same thread as
87 // SendClientReportPhishingRequest() was called. You may set |callback| to 98 // SendClientReportPhishingRequest() was called. You may set |callback| to
88 // NULL if you don't care about the server verdict. 99 // NULL if you don't care about the server verdict.
89 virtual void SendClientReportPhishingRequest( 100 virtual void SendClientReportPhishingRequest(
90 ClientPhishingRequest* verdict, 101 ClientPhishingRequest* verdict,
91 ClientReportPhishingRequestCallback* callback); 102 ClientReportPhishingRequestCallback* callback);
92 103
93 // Returns true if the given IP address string falls within a private 104 // Returns true if the given IP address string falls within a private
94 // (unroutable) network block. Pages which are hosted on these IP addresses 105 // (unroutable) network block. Pages which are hosted on these IP addresses
95 // are exempt from client-side phishing detection. This is called by the 106 // are exempt from client-side phishing detection. This is called by the
96 // ClientSideDetectionHost prior to sending the renderer a 107 // ClientSideDetectionHost prior to sending the renderer a
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 MODEL_INVALID_VERSION_NUMBER, 143 MODEL_INVALID_VERSION_NUMBER,
133 MODEL_BAD_HASH_IDS, 144 MODEL_BAD_HASH_IDS,
134 MODEL_STATUS_MAX // Always add new values before this one. 145 MODEL_STATUS_MAX // Always add new values before this one.
135 }; 146 };
136 147
137 // Starts fetching the model from the network or the cache. This method 148 // Starts fetching the model from the network or the cache. This method
138 // is called periodically to check whether a new client model is available 149 // is called periodically to check whether a new client model is available
139 // for download. 150 // for download.
140 void StartFetchModel(); 151 void StartFetchModel();
141 152
153 // Schedules the next fetch of the model.
154 virtual void ScheduleFetchModel(int64 delay_ms); // Virtual for testing.
155
142 // This method is called when we're done fetching the model either because 156 // This method is called when we're done fetching the model either because
143 // we hit an error somewhere or because we're actually done fetch and 157 // we hit an error somewhere or because we're actually done fetch and
144 // validating the model. 158 // validating the model.
145 virtual void EndFetchModel(ClientModelStatus status); // Virtual for testing. 159 virtual void EndFetchModel(ClientModelStatus status); // Virtual for testing.
146 160
147 private: 161 private:
148 friend class ClientSideDetectionServiceTest; 162 friend class ClientSideDetectionServiceTest;
149 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, FetchModelTest); 163 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, FetchModelTest);
150 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetBadSubnets); 164 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetBadSubnets);
165 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetEnabled);
151 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, IsBadIpAddress); 166 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, IsBadIpAddress);
152 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, 167 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest,
153 ModelHasValidHashIds); 168 ModelHasValidHashIds);
154 169
155 // CacheState holds all information necessary to respond to a caller without 170 // CacheState holds all information necessary to respond to a caller without
156 // actually making a HTTP request. 171 // actually making a HTTP request.
157 struct CacheState { 172 struct CacheState {
158 bool is_phishing; 173 bool is_phishing;
159 base::Time timestamp; 174 base::Time timestamp;
160 175
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // |bad_subnets| for faster lookups. This method is static to simplify 240 // |bad_subnets| for faster lookups. This method is static to simplify
226 // testing. 241 // testing.
227 static void SetBadSubnets(const ClientSideModel& model, 242 static void SetBadSubnets(const ClientSideModel& model,
228 BadSubnetMap* bad_subnets); 243 BadSubnetMap* bad_subnets);
229 244
230 245
231 // Returns true iff all the hash id's in the client-side model point to 246 // Returns true iff all the hash id's in the client-side model point to
232 // valid hashes in the model. 247 // valid hashes in the model.
233 static bool ModelHasValidHashIds(const ClientSideModel& model); 248 static bool ModelHasValidHashIds(const ClientSideModel& model);
234 249
250 // Whether the service is running or not. When the service is not running,
251 // it won't download the model nor report detected phishing URLs.
252 bool enabled_;
253
235 std::string model_str_; 254 std::string model_str_;
236 scoped_ptr<ClientSideModel> model_; 255 scoped_ptr<ClientSideModel> model_;
237 scoped_ptr<base::TimeDelta> model_max_age_; 256 scoped_ptr<base::TimeDelta> model_max_age_;
238 scoped_ptr<URLFetcher> model_fetcher_; 257 scoped_ptr<URLFetcher> model_fetcher_;
239 258
240 // Map of client report phishing request to the corresponding callback that 259 // Map of client report phishing request to the corresponding callback that
241 // has to be invoked when the request is done. 260 // has to be invoked when the request is done.
242 struct ClientReportInfo; 261 struct ClientReportInfo;
243 std::map<const URLFetcher*, ClientReportInfo*> client_phishing_reports_; 262 std::map<const URLFetcher*, ClientReportInfo*> client_phishing_reports_;
244 263
(...skipping 24 matching lines...) Expand all
269 // this map to speed up lookups. 288 // this map to speed up lookups.
270 BadSubnetMap bad_subnets_; 289 BadSubnetMap bad_subnets_;
271 290
272 NotificationRegistrar registrar_; 291 NotificationRegistrar registrar_;
273 292
274 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); 293 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService);
275 }; 294 };
276 } // namepsace safe_browsing 295 } // namepsace safe_browsing
277 296
278 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ 297 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/browser_process_impl.cc ('k') | chrome/browser/safe_browsing/client_side_detection_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698