Add ICU message format support
[chromium-blink-merge.git] / extensions / browser / extension_throttle_entry_interface.h
blob99989b8c5ebcefe3fc876be0aa8073b0b0750828
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 EXTENSIONS_BROWSER_EXTENSION_THROTTLE_ENTRY_INTERFACE_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_THROTTLE_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 {
16 class URLRequest;
17 } // namespace net
19 namespace extensions {
21 // Interface provided on entries of the URL request throttler manager.
22 class ExtensionThrottleEntryInterface
23 : public base::RefCountedThreadSafe<ExtensionThrottleEntryInterface> {
24 public:
25 ExtensionThrottleEntryInterface() {}
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(const net::URLRequest& request) const = 0;
36 // Calculates a recommended sending time for the next request and reserves it.
37 // The sending time is not earlier than the current exponential back-off
38 // release time or |earliest_time|. Moreover, the previous results of
39 // the method are taken into account, in order to make sure they are spread
40 // properly over time.
41 // Returns the recommended delay before sending the next request, in
42 // milliseconds. The return value is always positive or 0.
43 // Although it is not mandatory, respecting the value returned by this method
44 // is helpful to avoid traffic overload.
45 virtual int64 ReserveSendingTimeForNextRequest(
46 const base::TimeTicks& earliest_time) = 0;
48 // Returns the time after which requests are allowed.
49 virtual base::TimeTicks GetExponentialBackoffReleaseTime() const = 0;
51 // This method needs to be called each time a response is received.
52 virtual void UpdateWithResponse(int status_code) = 0;
54 // Lets higher-level modules, that know how to parse particular response
55 // bodies, notify of receiving malformed content for the given URL. This will
56 // be handled by the throttler as if an HTTP 503 response had been received to
57 // the request, i.e. it will count as a failure, unless the HTTP response code
58 // indicated is already one of those that will be counted as an error.
59 virtual void ReceivedContentWasMalformed(int response_code) = 0;
61 // Get the URL ID associated with his entry. Should only be used for debugging
62 // purpose.
63 virtual const std::string& GetURLIdForDebugging() const = 0;
65 protected:
66 friend class base::RefCountedThreadSafe<ExtensionThrottleEntryInterface>;
67 virtual ~ExtensionThrottleEntryInterface() {}
69 private:
70 friend class base::RefCounted<ExtensionThrottleEntryInterface>;
71 DISALLOW_COPY_AND_ASSIGN(ExtensionThrottleEntryInterface);
74 } // namespace extensions
76 #endif // EXTENSIONS_BROWSER_EXTENSION_THROTTLE_ENTRY_INTERFACE_H_