Home | History | Annotate | Download | only in url_request
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_INTERFACE_H_
      6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_INTERFACE_H_
      7 #pragma once
      8 
      9 #include "base/basictypes.h"
     10 #include "base/memory/ref_counted.h"
     11 #include "base/time.h"
     12 
     13 namespace net {
     14 
     15 class URLRequestThrottlerHeaderInterface;
     16 
     17 // Interface provided on entries of the URL request throttler manager.
     18 class URLRequestThrottlerEntryInterface
     19     : public base::RefCountedThreadSafe<URLRequestThrottlerEntryInterface> {
     20  public:
     21   URLRequestThrottlerEntryInterface() {}
     22 
     23   // Returns true when we have encountered server errors and are doing
     24   // exponential back-off.
     25   // URLRequestHttpJob checks this method prior to every request; it
     26   // cancels requests if this method returns true.
     27   virtual bool IsDuringExponentialBackoff() const = 0;
     28 
     29   // Calculates a recommended sending time for the next request and reserves it.
     30   // The sending time is not earlier than the current exponential back-off
     31   // release time or |earliest_time|. Moreover, the previous results of
     32   // the method are taken into account, in order to make sure they are spread
     33   // properly over time.
     34   // Returns the recommended delay before sending the next request, in
     35   // milliseconds. The return value is always positive or 0.
     36   // Although it is not mandatory, respecting the value returned by this method
     37   // is helpful to avoid traffic overload.
     38   virtual int64 ReserveSendingTimeForNextRequest(
     39       const base::TimeTicks& earliest_time) = 0;
     40 
     41   // Returns the time after which requests are allowed.
     42   virtual base::TimeTicks GetExponentialBackoffReleaseTime() const = 0;
     43 
     44   // This method needs to be called each time a response is received.
     45   virtual void UpdateWithResponse(
     46       const std::string& host,
     47       const URLRequestThrottlerHeaderInterface* response) = 0;
     48 
     49   // Lets higher-level modules, that know how to parse particular response
     50   // bodies, notify of receiving malformed content for the given URL. This will
     51   // be handled by the throttler as if an HTTP 5xx response had been received to
     52   // the request, i.e. it will count as a failure.
     53   virtual void ReceivedContentWasMalformed() = 0;
     54 
     55  protected:
     56   friend class base::RefCountedThreadSafe<URLRequestThrottlerEntryInterface>;
     57   virtual ~URLRequestThrottlerEntryInterface() {}
     58 
     59  private:
     60   friend class base::RefCounted<URLRequestThrottlerEntryInterface>;
     61   DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerEntryInterface);
     62 };
     63 
     64 }  // namespace net
     65 
     66 #endif  // NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_INTERFACE_H_
     67