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

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

Issue 1555953002: Adds backoff and Min Wait Duration compliance to Protocolmanager pver4 handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@osb-pm-2
Patch Set: Rebase Created 4 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/protocol_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_
7 7
8 // A class that implements Chrome's interface with the SafeBrowsing protocol. 8 // A class that implements Chrome's interface with the SafeBrowsing protocol.
9 // See https://developers.google.com/safe-browsing/developers_guide_v2 for 9 // See https://developers.google.com/safe-browsing/developers_guide_v2 for
10 // protocol details. 10 // protocol details.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, 209 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
210 TestParseV4HashResponse); 210 TestParseV4HashResponse);
211 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, 211 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
212 TestParseV4HashResponseWrongThreatEntryType); 212 TestParseV4HashResponseWrongThreatEntryType);
213 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, 213 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
214 TestParseV4HashResponseSocialEngineeringThreatType); 214 TestParseV4HashResponseSocialEngineeringThreatType);
215 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, 215 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
216 TestParseV4HashResponseNonPermissionMetadata); 216 TestParseV4HashResponseNonPermissionMetadata);
217 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, 217 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
218 TestGetHashBackOffTimes); 218 TestGetHashBackOffTimes);
219 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
220 TestGetV4HashBackOffTimes);
219 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl); 221 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl);
220 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl); 222 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl);
221 friend class SafeBrowsingServerTest; 223 friend class SafeBrowsingServerTest;
222 friend class SBProtocolManagerFactoryImpl; 224 friend class SBProtocolManagerFactoryImpl;
223 225
224 // Internal API for fetching information from the SafeBrowsing servers. The 226 // Internal API for fetching information from the SafeBrowsing servers. The
225 // GetHash requests are higher priority since they can block user requests 227 // GetHash requests are higher priority since they can block user requests
226 // so are handled separately. 228 // so are handled separately.
227 enum SafeBrowsingRequestType { 229 enum SafeBrowsingRequestType {
228 NO_REQUEST = 0, // No requests in progress 230 NO_REQUEST = 0, // No requests in progress
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // the time returned will increment an error count and return the appriate 279 // the time returned will increment an error count and return the appriate
278 // next time (see ScheduleNextUpdate below). 280 // next time (see ScheduleNextUpdate below).
279 base::TimeDelta GetNextUpdateInterval(bool back_off); 281 base::TimeDelta GetNextUpdateInterval(bool back_off);
280 282
281 // Worker function for calculating GetHash and Update backoff times (in 283 // Worker function for calculating GetHash and Update backoff times (in
282 // seconds). |multiplier| is doubled for each consecutive error between the 284 // seconds). |multiplier| is doubled for each consecutive error between the
283 // 2nd and 5th, and |error_count| is incremented with each call. 285 // 2nd and 5th, and |error_count| is incremented with each call.
284 base::TimeDelta GetNextBackOffInterval(size_t* error_count, 286 base::TimeDelta GetNextBackOffInterval(size_t* error_count,
285 size_t* multiplier) const; 287 size_t* multiplier) const;
286 288
289 // Worker function for calculating the V4 GetHash backoff times.
290 // |multiplier| is doubled for each consecutive error after the
291 // first, and |error_count| is incremented with each call.
292 static base::TimeDelta GetNextV4BackOffInterval(size_t* error_count,
293 size_t* multiplier);
294
295 // Resets the V4 gethash error counter and multiplier.
296 void ResetGetHashV4Errors();
297
287 // Manages our update with the next allowable update time. If 'back_off_' is 298 // Manages our update with the next allowable update time. If 'back_off_' is
288 // true, we must decrease the frequency of requests of the SafeBrowsing 299 // true, we must decrease the frequency of requests of the SafeBrowsing
289 // service according to section 5 of the protocol specification. 300 // service according to section 5 of the protocol specification.
290 // When disable_auto_update_ is set, ScheduleNextUpdate will do nothing. 301 // When disable_auto_update_ is set, ScheduleNextUpdate will do nothing.
291 // ForceScheduleNextUpdate has to be called to trigger the update. 302 // ForceScheduleNextUpdate has to be called to trigger the update.
292 void ScheduleNextUpdate(bool back_off); 303 void ScheduleNextUpdate(bool back_off);
293 304
294 // Sends a request for a list of chunks we should download to the SafeBrowsing 305 // Sends a request for a list of chunks we should download to the SafeBrowsing
295 // servers. In order to format this request, we need to send all the chunk 306 // servers. In order to format this request, we need to send all the chunk
296 // numbers for each list that we have to the server. Getting the chunk numbers 307 // numbers for each list that we have to the server. Getting the chunk numbers
(...skipping 14 matching lines...) Expand all
311 322
312 // Runs the protocol parser on received data and update the 323 // Runs the protocol parser on received data and update the
313 // SafeBrowsingService with the new content. Returns 'true' on successful 324 // SafeBrowsingService with the new content. Returns 'true' on successful
314 // parse, 'false' on error. 325 // parse, 'false' on error.
315 bool HandleServiceResponse(const GURL& url, const char* data, size_t length); 326 bool HandleServiceResponse(const GURL& url, const char* data, size_t length);
316 327
317 // Updates internal state for each GetHash response error, assuming that the 328 // Updates internal state for each GetHash response error, assuming that the
318 // current time is |now|. 329 // current time is |now|.
319 void HandleGetHashError(const base::Time& now); 330 void HandleGetHashError(const base::Time& now);
320 331
332 // Updates internal state for each GetHash V4 response error, assuming that
333 // the current time is |now|.
334 void HandleGetHashV4Error(const base::Time& now);
335
321 // Helper function for update completion. 336 // Helper function for update completion.
322 void UpdateFinished(bool success); 337 void UpdateFinished(bool success);
323 void UpdateFinished(bool success, bool back_off); 338 void UpdateFinished(bool success, bool back_off);
324 339
325 // A callback that runs if we timeout waiting for a response to an update 340 // A callback that runs if we timeout waiting for a response to an update
326 // request. We use this to properly set our update state. 341 // request. We use this to properly set our update state.
327 void UpdateResponseTimeout(); 342 void UpdateResponseTimeout();
328 343
329 // Called after the chunks are added to the database. 344 // Called after the chunks are added to the database.
330 void OnAddChunksComplete(); 345 void OnAddChunksComplete();
(...skipping 18 matching lines...) Expand all
349 SafeBrowsingProtocolManagerDelegate* delegate_; 364 SafeBrowsingProtocolManagerDelegate* delegate_;
350 365
351 // Current active request (in case we need to cancel) for updates or chunks 366 // Current active request (in case we need to cancel) for updates or chunks
352 // from the SafeBrowsing service. We can only have one of these outstanding 367 // from the SafeBrowsing service. We can only have one of these outstanding
353 // at any given time unlike GetHash requests, which are tracked separately. 368 // at any given time unlike GetHash requests, which are tracked separately.
354 scoped_ptr<net::URLFetcher> request_; 369 scoped_ptr<net::URLFetcher> request_;
355 370
356 // The kind of request that is currently in progress. 371 // The kind of request that is currently in progress.
357 SafeBrowsingRequestType request_type_; 372 SafeBrowsingRequestType request_type_;
358 373
359 // The number of HTTP response errors, used for request backoff timing. 374 // The number of HTTP response errors since the the last successful HTTP
375 // response, used for request backoff timing.
360 size_t update_error_count_; 376 size_t update_error_count_;
361 size_t gethash_error_count_; 377 size_t gethash_error_count_;
378 size_t gethash_v4_error_count_;
362 379
363 // Multipliers which double (max == 8) for each error after the second. 380 // Multipliers which double (max == 8) for each error after the second.
364 size_t update_back_off_mult_; 381 size_t update_back_off_mult_;
365 size_t gethash_back_off_mult_; 382 size_t gethash_back_off_mult_;
383 size_t gethash_v4_back_off_mult_;
366 384
367 // Multiplier between 0 and 1 to spread clients over an interval. 385 // Multiplier between 0 and 1 to spread clients over an interval.
368 float back_off_fuzz_; 386 float back_off_fuzz_;
369 387
370 // The list for which we are make a request. 388 // The list for which we are make a request.
371 std::string list_name_; 389 std::string list_name_;
372 390
373 // For managing the next earliest time to query the SafeBrowsing servers for 391 // For managing the next earliest time to query the SafeBrowsing servers for
374 // updates. 392 // updates.
375 base::TimeDelta next_update_interval_; 393 base::TimeDelta next_update_interval_;
(...skipping 11 matching lines...) Expand all
387 405
388 // True if the service has been given an add/sub chunk but it hasn't been 406 // True if the service has been given an add/sub chunk but it hasn't been
389 // added to the database yet. 407 // added to the database yet.
390 bool chunk_pending_to_write_; 408 bool chunk_pending_to_write_;
391 409
392 // The last time we successfully received an update. 410 // The last time we successfully received an update.
393 base::Time last_update_; 411 base::Time last_update_;
394 412
395 // While in GetHash backoff, we can't make another GetHash until this time. 413 // While in GetHash backoff, we can't make another GetHash until this time.
396 base::Time next_gethash_time_; 414 base::Time next_gethash_time_;
415 // For v4, the next gethash time is set to the backoff time is the last
416 // response was an error, or the minimum wait time if the last response was
417 // successful.
418 base::Time next_gethash_v4_time_;
397 419
398 // Current product version sent in each request. 420 // Current product version sent in each request.
399 std::string version_; 421 std::string version_;
400 422
401 // Used for measuring chunk request latency. 423 // Used for measuring chunk request latency.
402 base::Time chunk_request_start_; 424 base::Time chunk_request_start_;
403 425
404 // Tracks the size of each update (in bytes). 426 // Tracks the size of each update (in bytes).
405 size_t update_size_; 427 size_t update_size_;
406 428
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 AddChunksCallback callback) = 0; 511 AddChunksCallback callback) = 0;
490 512
491 // Delete chunks from the database. 513 // Delete chunks from the database.
492 virtual void DeleteChunks( 514 virtual void DeleteChunks(
493 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) = 0; 515 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) = 0;
494 }; 516 };
495 517
496 } // namespace safe_browsing 518 } // namespace safe_browsing
497 519
498 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ 520 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/protocol_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698