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

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: Review COmments 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
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
287 // Manages our update with the next allowable update time. If 'back_off_' is 295 // 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 296 // true, we must decrease the frequency of requests of the SafeBrowsing
289 // service according to section 5 of the protocol specification. 297 // service according to section 5 of the protocol specification.
290 // When disable_auto_update_ is set, ScheduleNextUpdate will do nothing. 298 // When disable_auto_update_ is set, ScheduleNextUpdate will do nothing.
291 // ForceScheduleNextUpdate has to be called to trigger the update. 299 // ForceScheduleNextUpdate has to be called to trigger the update.
292 void ScheduleNextUpdate(bool back_off); 300 void ScheduleNextUpdate(bool back_off);
293 301
294 // Sends a request for a list of chunks we should download to the SafeBrowsing 302 // 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 303 // 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 304 // numbers for each list that we have to the server. Getting the chunk numbers
(...skipping 14 matching lines...) Expand all
311 319
312 // Runs the protocol parser on received data and update the 320 // Runs the protocol parser on received data and update the
313 // SafeBrowsingService with the new content. Returns 'true' on successful 321 // SafeBrowsingService with the new content. Returns 'true' on successful
314 // parse, 'false' on error. 322 // parse, 'false' on error.
315 bool HandleServiceResponse(const GURL& url, const char* data, size_t length); 323 bool HandleServiceResponse(const GURL& url, const char* data, size_t length);
316 324
317 // Updates internal state for each GetHash response error, assuming that the 325 // Updates internal state for each GetHash response error, assuming that the
318 // current time is |now|. 326 // current time is |now|.
319 void HandleGetHashError(const base::Time& now); 327 void HandleGetHashError(const base::Time& now);
320 328
329 // Updates internal state for each GetHash V4 response error, assuming that
330 // the current time is |now|.
331 void HandleGetHashV4Error(const base::Time& now);
332
321 // Helper function for update completion. 333 // Helper function for update completion.
322 void UpdateFinished(bool success); 334 void UpdateFinished(bool success);
323 void UpdateFinished(bool success, bool back_off); 335 void UpdateFinished(bool success, bool back_off);
324 336
325 // A callback that runs if we timeout waiting for a response to an update 337 // 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. 338 // request. We use this to properly set our update state.
327 void UpdateResponseTimeout(); 339 void UpdateResponseTimeout();
328 340
329 // Called after the chunks are added to the database. 341 // Called after the chunks are added to the database.
330 void OnAddChunksComplete(); 342 void OnAddChunksComplete();
(...skipping 18 matching lines...) Expand all
349 SafeBrowsingProtocolManagerDelegate* delegate_; 361 SafeBrowsingProtocolManagerDelegate* delegate_;
350 362
351 // Current active request (in case we need to cancel) for updates or chunks 363 // 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 364 // from the SafeBrowsing service. We can only have one of these outstanding
353 // at any given time unlike GetHash requests, which are tracked separately. 365 // at any given time unlike GetHash requests, which are tracked separately.
354 scoped_ptr<net::URLFetcher> request_; 366 scoped_ptr<net::URLFetcher> request_;
355 367
356 // The kind of request that is currently in progress. 368 // The kind of request that is currently in progress.
357 SafeBrowsingRequestType request_type_; 369 SafeBrowsingRequestType request_type_;
358 370
359 // The number of HTTP response errors, used for request backoff timing. 371 // The number of HTTP response errors, used for request backoff timing.
Nathan Parker 2016/01/12 04:14:38 number of HTTP response error since the last succe
kcarattini 2016/01/12 05:18:06 Done.
360 size_t update_error_count_; 372 size_t update_error_count_;
361 size_t gethash_error_count_; 373 size_t gethash_error_count_;
374 size_t gethash_v4_error_count_;
362 375
363 // Multipliers which double (max == 8) for each error after the second. 376 // Multipliers which double (max == 8) for each error after the second.
364 size_t update_back_off_mult_; 377 size_t update_back_off_mult_;
365 size_t gethash_back_off_mult_; 378 size_t gethash_back_off_mult_;
379 size_t gethash_v4_back_off_mult_;
366 380
367 // Multiplier between 0 and 1 to spread clients over an interval. 381 // Multiplier between 0 and 1 to spread clients over an interval.
368 float back_off_fuzz_; 382 float back_off_fuzz_;
369 383
370 // The list for which we are make a request. 384 // The list for which we are make a request.
371 std::string list_name_; 385 std::string list_name_;
372 386
373 // For managing the next earliest time to query the SafeBrowsing servers for 387 // For managing the next earliest time to query the SafeBrowsing servers for
374 // updates. 388 // updates.
375 base::TimeDelta next_update_interval_; 389 base::TimeDelta next_update_interval_;
(...skipping 11 matching lines...) Expand all
387 401
388 // True if the service has been given an add/sub chunk but it hasn't been 402 // True if the service has been given an add/sub chunk but it hasn't been
389 // added to the database yet. 403 // added to the database yet.
390 bool chunk_pending_to_write_; 404 bool chunk_pending_to_write_;
391 405
392 // The last time we successfully received an update. 406 // The last time we successfully received an update.
393 base::Time last_update_; 407 base::Time last_update_;
394 408
395 // While in GetHash backoff, we can't make another GetHash until this time. 409 // While in GetHash backoff, we can't make another GetHash until this time.
396 base::Time next_gethash_time_; 410 base::Time next_gethash_time_;
411 base::Time next_gethash_v4_time_;
Nathan Parker 2016/01/12 04:14:38 Is this the max of the prescribed min-wait-time an
kcarattini 2016/01/12 05:18:06 No, it should be one or the other. Added a comment
397 412
398 // Current product version sent in each request. 413 // Current product version sent in each request.
399 std::string version_; 414 std::string version_;
400 415
401 // Used for measuring chunk request latency. 416 // Used for measuring chunk request latency.
402 base::Time chunk_request_start_; 417 base::Time chunk_request_start_;
403 418
404 // Tracks the size of each update (in bytes). 419 // Tracks the size of each update (in bytes).
405 size_t update_size_; 420 size_t update_size_;
406 421
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 AddChunksCallback callback) = 0; 504 AddChunksCallback callback) = 0;
490 505
491 // Delete chunks from the database. 506 // Delete chunks from the database.
492 virtual void DeleteChunks( 507 virtual void DeleteChunks(
493 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) = 0; 508 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) = 0;
494 }; 509 };
495 510
496 } // namespace safe_browsing 511 } // namespace safe_browsing
497 512
498 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ 513 #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') | chrome/browser/safe_browsing/protocol_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698