url_request_throttler_entry_interface.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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
  3. // found in the LICENSE file.
  4. #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_INTERFACE_H_
  5. #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_INTERFACE_H_
  6. #include <stdint.h>
  7. #include "base/memory/ref_counted.h"
  8. #include "base/time/time.h"
  9. #include "net/base/net_export.h"
  10. namespace net {
  11. class URLRequest;
  12. // Interface provided on entries of the URL request throttler manager.
  13. class NET_EXPORT URLRequestThrottlerEntryInterface
  14. : public base::RefCountedThreadSafe<URLRequestThrottlerEntryInterface> {
  15. public:
  16. URLRequestThrottlerEntryInterface() = default;
  17. URLRequestThrottlerEntryInterface(const URLRequestThrottlerEntryInterface&) =
  18. delete;
  19. URLRequestThrottlerEntryInterface& operator=(
  20. const URLRequestThrottlerEntryInterface&) = delete;
  21. // Returns true when we have encountered server errors and are doing
  22. // exponential back-off, unless the request has load flags that mean
  23. // it is likely to be user-initiated.
  24. //
  25. // URLRequestHttpJob checks this method prior to every request; it
  26. // cancels requests if this method returns true.
  27. virtual bool ShouldRejectRequest(const URLRequest& request) const = 0;
  28. // Calculates a recommended sending time for the next request and reserves it.
  29. // The sending time is not earlier than the current exponential back-off
  30. // release time or |earliest_time|. Moreover, the previous results of
  31. // the method are taken into account, in order to make sure they are spread
  32. // properly over time.
  33. // Returns the recommended delay before sending the next request, in
  34. // milliseconds. The return value is always positive or 0.
  35. // Although it is not mandatory, respecting the value returned by this method
  36. // is helpful to avoid traffic overload.
  37. virtual int64_t ReserveSendingTimeForNextRequest(
  38. const base::TimeTicks& earliest_time) = 0;
  39. // Returns the time after which requests are allowed.
  40. virtual base::TimeTicks GetExponentialBackoffReleaseTime() const = 0;
  41. // This method needs to be called each time a response is received.
  42. virtual void UpdateWithResponse(int status_code) = 0;
  43. // Lets higher-level modules, that know how to parse particular response
  44. // bodies, notify of receiving malformed content for the given URL. This will
  45. // be handled by the throttler as if an HTTP 503 response had been received to
  46. // the request, i.e. it will count as a failure, unless the HTTP response code
  47. // indicated is already one of those that will be counted as an error.
  48. virtual void ReceivedContentWasMalformed(int response_code) = 0;
  49. protected:
  50. friend class base::RefCountedThreadSafe<URLRequestThrottlerEntryInterface>;
  51. virtual ~URLRequestThrottlerEntryInterface() = default;
  52. private:
  53. friend class base::RefCounted<URLRequestThrottlerEntryInterface>;
  54. };
  55. } // namespace net
  56. #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_INTERFACE_H_