Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / loader / throttling_resource_handler.h
blob4e1b81411dc18367a3e5288738b6a0371f181897
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"
13 #include "url/gurl.h"
15 namespace net {
16 class URLRequest;
19 namespace content {
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 {
27 public:
28 // Takes ownership of the ResourceThrottle instances.
29 ThrottlingResourceHandler(scoped_ptr<ResourceHandler> next_handler,
30 net::URLRequest* request,
31 ScopedVector<ResourceThrottle> throttles);
32 virtual ~ThrottlingResourceHandler();
34 // LayeredResourceHandler overrides:
35 virtual bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
36 ResourceResponse* response,
37 bool* defer) OVERRIDE;
38 virtual bool OnResponseStarted(ResourceResponse* response,
39 bool* defer) OVERRIDE;
40 virtual bool OnWillStart(const GURL& url, bool* defer) OVERRIDE;
41 virtual bool OnBeforeNetworkStart(const GURL& url, bool* defer) OVERRIDE;
43 // ResourceController implementation:
44 virtual void Cancel() OVERRIDE;
45 virtual void CancelAndIgnore() OVERRIDE;
46 virtual void CancelWithError(int error_code) OVERRIDE;
47 virtual void Resume() OVERRIDE;
49 private:
50 void ResumeStart();
51 void ResumeNetworkStart();
52 void ResumeRedirect();
53 void ResumeResponse();
55 // Called when the throttle at |throttle_index| defers a request. Logs the
56 // name of the throttle that delayed the request.
57 void OnRequestDefered(int throttle_index);
59 enum DeferredStage {
60 DEFERRED_NONE,
61 DEFERRED_START,
62 DEFERRED_NETWORK_START,
63 DEFERRED_REDIRECT,
64 DEFERRED_RESPONSE
66 DeferredStage deferred_stage_;
68 ScopedVector<ResourceThrottle> throttles_;
69 size_t next_index_;
71 GURL deferred_url_;
72 net::RedirectInfo deferred_redirect_;
73 scoped_refptr<ResourceResponse> deferred_response_;
75 bool cancelled_by_resource_throttle_;
78 } // namespace content
80 #endif // CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_