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 CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_vector.h"
10 #include "content/browser/loader/layered_resource_handler.h"
11 #include "content/public/browser/resource_controller.h"
20 class ResourceThrottle;
21 struct ResourceResponse;
23 // Used to apply a list of ResourceThrottle instances to an URLRequest.
24 class ThrottlingResourceHandler : public LayeredResourceHandler,
25 public ResourceController {
27 // Takes ownership of the ResourceThrottle instances.
28 ThrottlingResourceHandler(scoped_ptr<ResourceHandler> next_handler,
29 net::URLRequest* request,
30 ScopedVector<ResourceThrottle> throttles);
31 virtual ~ThrottlingResourceHandler();
33 // LayeredResourceHandler overrides:
34 virtual bool OnRequestRedirected(int request_id, const GURL& url,
35 ResourceResponse* response,
36 bool* defer) OVERRIDE;
37 virtual bool OnResponseStarted(int request_id,
38 ResourceResponse* response,
39 bool* defer) OVERRIDE;
40 virtual bool OnWillStart(int request_id, const GURL& url,
41 bool* defer) OVERRIDE;
43 // ResourceThrottleController implementation:
44 virtual void Cancel() OVERRIDE;
45 virtual void CancelAndIgnore() OVERRIDE;
46 virtual void CancelWithError(int error_code) OVERRIDE;
47 virtual void Resume() OVERRIDE;
51 void ResumeRedirect();
52 void ResumeResponse();
60 DeferredStage deferred_stage_;
62 ScopedVector<ResourceThrottle> throttles_;
66 scoped_refptr<ResourceResponse> deferred_response_;
68 bool cancelled_by_resource_throttle_;
71 } // namespace content
73 #endif // CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_