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. 4 5 #ifndef CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_ 6 #define CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_ 7 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 "url/gurl.h" 13 14 namespace content { 15 16 class ResourceThrottle; 17 struct ResourceResponse; 18 19 // Used to apply a list of ResourceThrottle instances to an URLRequest. 20 class ThrottlingResourceHandler : public LayeredResourceHandler, 21 public ResourceController { 22 public: 23 // Takes ownership of the ResourceThrottle instances. 24 ThrottlingResourceHandler(scoped_ptr<ResourceHandler> next_handler, 25 int child_id, 26 int request_id, 27 ScopedVector<ResourceThrottle> throttles); 28 virtual ~ThrottlingResourceHandler(); 29 30 // LayeredResourceHandler overrides: 31 virtual bool OnRequestRedirected(int request_id, const GURL& url, 32 ResourceResponse* response, 33 bool* defer) OVERRIDE; 34 virtual bool OnResponseStarted(int request_id, 35 ResourceResponse* response, 36 bool* defer) OVERRIDE; 37 virtual bool OnWillStart(int request_id, const GURL& url, 38 bool* defer) OVERRIDE; 39 40 // ResourceThrottleController implementation: 41 virtual void Cancel() OVERRIDE; 42 virtual void CancelAndIgnore() OVERRIDE; 43 virtual void CancelWithError(int error_code) OVERRIDE; 44 virtual void Resume() OVERRIDE; 45 46 private: 47 void ResumeStart(); 48 void ResumeRedirect(); 49 void ResumeResponse(); 50 51 enum DeferredStage { 52 DEFERRED_NONE, 53 DEFERRED_START, 54 DEFERRED_REDIRECT, 55 DEFERRED_RESPONSE 56 }; 57 DeferredStage deferred_stage_; 58 59 int request_id_; 60 61 ScopedVector<ResourceThrottle> throttles_; 62 size_t index_; 63 64 GURL deferred_url_; 65 scoped_refptr<ResourceResponse> deferred_response_; 66 67 bool cancelled_by_resource_throttle_; 68 }; 69 70 } // namespace content 71 72 #endif // CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_ 73