diff options
author | xunjieli <xunjieli@chromium.org> | 2015-06-16 10:15:43 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-16 17:16:17 +0000 |
commit | 413a687892c42560986bf952590155bc65afc978 (patch) | |
tree | 82451120f2ab9998479210c13226d2ad5d0e85b0 /extensions/browser/extension_request_limiting_throttle.h | |
parent | 6d491c39b882fa2b3e27ddc785847fd21884fdce (diff) | |
download | chromium_src-413a687892c42560986bf952590155bc65afc978.zip chromium_src-413a687892c42560986bf952590155bc65afc978.tar.gz chromium_src-413a687892c42560986bf952590155bc65afc978.tar.bz2 |
Make a ResourceThrottle for extensions on top of net::URLRequestThrottlerManager.
net::URLRequestThrottlerManager is used for throttling extensions originated
requests. We would like to move it out of net/ and place it in a more appropriate
directory. Since content::ResourceThrottle is the standard way to throttle
requests, this CL makes URLRequestThrottlerManager into a extensions
ResourceThrottle and place it in extensions/browser/. Followup CLs will clean up
URLRequestThrottlerManager usage from net/.
BUG=484241
Committed: https://crrev.com/6a47d0e298a4c3050d95505f5ee18b122fdc213b
Cr-Commit-Position: refs/heads/master@{#334457}
Review URL: https://codereview.chromium.org/1171983003
Cr-Commit-Position: refs/heads/master@{#334624}
Diffstat (limited to 'extensions/browser/extension_request_limiting_throttle.h')
-rw-r--r-- | extensions/browser/extension_request_limiting_throttle.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/extensions/browser/extension_request_limiting_throttle.h b/extensions/browser/extension_request_limiting_throttle.h new file mode 100644 index 0000000..bd9dd4c --- /dev/null +++ b/extensions/browser/extension_request_limiting_throttle.h @@ -0,0 +1,52 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EXTENSIONS_BROWSER_EXTENSION_REQUEST_LIMITING_THROTTLE_H_ +#define EXTENSIONS_BROWSER_EXTENSION_REQUEST_LIMITING_THROTTLE_H_ + +#include "base/macros.h" +#include "base/memory/ref_counted.h" +#include "content/public/browser/resource_throttle.h" + +namespace net { +struct RedirectInfo; +class URLRequest; +} + +namespace extensions { + +class ExtensionThrottleEntryInterface; +class ExtensionThrottleManager; + +// This class monitors requests issued by extensions and throttles the request +// if there are too many requests made within a short time to urls with the same +// scheme, host, port and path. For the exact criteria for throttling, please +// also see extension_throttle_manager.cc. +class ExtensionRequestLimitingThrottle : public content::ResourceThrottle { + public: + ExtensionRequestLimitingThrottle(const net::URLRequest* request, + ExtensionThrottleManager* manager); + ~ExtensionRequestLimitingThrottle() override; + + // content::ResourceThrottle implementation (called on IO thread): + void WillStartRequest(bool* defer) override; + void WillRedirectRequest(const net::RedirectInfo& redirect_info, + bool* defer) override; + void WillProcessResponse(bool* defer) override; + + const char* GetNameForLogging() const override; + + private: + const net::URLRequest* request_; + ExtensionThrottleManager* manager_; + + // This is used to supervise traffic and enforce exponential back-off. + scoped_refptr<ExtensionThrottleEntryInterface> throttling_entry_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionRequestLimitingThrottle); +}; + +} // namespace extensions + +#endif // EXTENSIONS_BROWSER_EXTENSION_REQUEST_LIMITING_THROTTLE_H_ |