[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / net / url_request / url_request_throttler_entry_interface.h
blob8487bb98431bb313a6f1c09044c4ed51ea7c0d22
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.
5 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_INTERFACE_H_
6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_INTERFACE_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/time/time.h"
13 #include "net/base/net_export.h"
15 namespace net {
17 class NetworkDelegate;
18 class URLRequest;
19 class URLRequestThrottlerHeaderInterface;
21 // Interface provided on entries of the URL request throttler manager.
22 class NET_EXPORT URLRequestThrottlerEntryInterface
23 : public base::RefCountedThreadSafe<URLRequestThrottlerEntryInterface> {
24 public:
25 URLRequestThrottlerEntryInterface() {}
27 // Returns true when we have encountered server errors and are doing
28 // exponential back-off, unless the request has load flags that mean
29 // it is likely to be user-initiated, or the NetworkDelegate returns
30 // false for |CanThrottleRequest(request)|.
32 // URLRequestHttpJob checks this method prior to every request; it
33 // cancels requests if this method returns true.
34 virtual bool ShouldRejectRequest(
35 const URLRequest& request,
36 NetworkDelegate* network_delegate) const = 0;
38 // Calculates a recommended sending time for the next request and reserves it.
39 // The sending time is not earlier than the current exponential back-off
40 // release time or |earliest_time|. Moreover, the previous results of
41 // the method are taken into account, in order to make sure they are spread
42 // properly over time.
43 // Returns the recommended delay before sending the next request, in
44 // milliseconds. The return value is always positive or 0.
45 // Although it is not mandatory, respecting the value returned by this method
46 // is helpful to avoid traffic overload.
47 virtual int64 ReserveSendingTimeForNextRequest(
48 const base::TimeTicks& earliest_time) = 0;
50 // Returns the time after which requests are allowed.
51 virtual base::TimeTicks GetExponentialBackoffReleaseTime() const = 0;
53 // This method needs to be called each time a response is received.
54 virtual void UpdateWithResponse(int status_code) = 0;
56 // Lets higher-level modules, that know how to parse particular response
57 // bodies, notify of receiving malformed content for the given URL. This will
58 // be handled by the throttler as if an HTTP 503 response had been received to
59 // the request, i.e. it will count as a failure, unless the HTTP response code
60 // indicated is already one of those that will be counted as an error.
61 virtual void ReceivedContentWasMalformed(int response_code) = 0;
63 protected:
64 friend class base::RefCountedThreadSafe<URLRequestThrottlerEntryInterface>;
65 virtual ~URLRequestThrottlerEntryInterface() {}
67 private:
68 friend class base::RefCounted<URLRequestThrottlerEntryInterface>;
69 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerEntryInterface);
72 } // namespace net
74 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_ENTRY_INTERFACE_H_