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"
12 #include "net/url_request/redirect_info.h"
21 class ResourceThrottle
;
22 struct ResourceResponse
;
24 // Used to apply a list of ResourceThrottle instances to an URLRequest.
25 class ThrottlingResourceHandler
: public LayeredResourceHandler
,
26 public ResourceController
{
28 // Takes ownership of the ResourceThrottle instances.
29 ThrottlingResourceHandler(scoped_ptr
<ResourceHandler
> next_handler
,
30 net::URLRequest
* request
,
31 ScopedVector
<ResourceThrottle
> throttles
);
32 ~ThrottlingResourceHandler() override
;
34 // LayeredResourceHandler overrides:
35 bool OnRequestRedirected(const net::RedirectInfo
& redirect_info
,
36 ResourceResponse
* response
,
37 bool* defer
) override
;
38 bool OnResponseStarted(ResourceResponse
* response
, bool* defer
) override
;
39 bool OnWillStart(const GURL
& url
, bool* defer
) override
;
40 bool OnBeforeNetworkStart(const GURL
& url
, bool* defer
) override
;
42 // ResourceController implementation:
43 void Cancel() override
;
44 void CancelAndIgnore() override
;
45 void CancelWithError(int error_code
) override
;
46 void Resume() override
;
50 void ResumeNetworkStart();
51 void ResumeRedirect();
52 void ResumeResponse();
54 // Called when the throttle at |throttle_index| defers a request. Logs the
55 // name of the throttle that delayed the request.
56 void OnRequestDefered(int throttle_index
);
61 DEFERRED_NETWORK_START
,
65 DeferredStage deferred_stage_
;
67 ScopedVector
<ResourceThrottle
> throttles_
;
71 net::RedirectInfo deferred_redirect_
;
72 scoped_refptr
<ResourceResponse
> deferred_response_
;
74 bool cancelled_by_resource_throttle_
;
77 } // namespace content
79 #endif // CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_