Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / browser / extension_request_limiting_throttle.h
blobbd9dd4c46b27e74fbb14ad828178ad9a8fb1fea9
1 // Copyright 2015 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_REQUEST_LIMITING_THROTTLE_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_REQUEST_LIMITING_THROTTLE_H_
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "content/public/browser/resource_throttle.h"
12 namespace net {
13 struct RedirectInfo;
14 class URLRequest;
17 namespace extensions {
19 class ExtensionThrottleEntryInterface;
20 class ExtensionThrottleManager;
22 // This class monitors requests issued by extensions and throttles the request
23 // if there are too many requests made within a short time to urls with the same
24 // scheme, host, port and path. For the exact criteria for throttling, please
25 // also see extension_throttle_manager.cc.
26 class ExtensionRequestLimitingThrottle : public content::ResourceThrottle {
27 public:
28 ExtensionRequestLimitingThrottle(const net::URLRequest* request,
29 ExtensionThrottleManager* manager);
30 ~ExtensionRequestLimitingThrottle() override;
32 // content::ResourceThrottle implementation (called on IO thread):
33 void WillStartRequest(bool* defer) override;
34 void WillRedirectRequest(const net::RedirectInfo& redirect_info,
35 bool* defer) override;
36 void WillProcessResponse(bool* defer) override;
38 const char* GetNameForLogging() const override;
40 private:
41 const net::URLRequest* request_;
42 ExtensionThrottleManager* manager_;
44 // This is used to supervise traffic and enforce exponential back-off.
45 scoped_refptr<ExtensionThrottleEntryInterface> throttling_entry_;
47 DISALLOW_COPY_AND_ASSIGN(ExtensionRequestLimitingThrottle);
50 } // namespace extensions
52 #endif // EXTENSIONS_BROWSER_EXTENSION_REQUEST_LIMITING_THROTTLE_H_