| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "content/browser/loader/layered_resource_handler.h" | 12 #include "content/browser/loader/layered_resource_handler.h" |
| 13 #include "content/public/browser/resource_controller.h" | 13 #include "content/public/browser/resource_throttle.h" |
| 14 #include "net/url_request/redirect_info.h" | 14 #include "net/url_request/redirect_info.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 class URLRequest; | 18 class URLRequest; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 class ResourceThrottle; | |
| 24 struct ResourceResponse; | 23 struct ResourceResponse; |
| 25 | 24 |
| 26 // Used to apply a list of ResourceThrottle instances to an URLRequest. | 25 // Used to apply a list of ResourceThrottle instances to an URLRequest. |
| 27 class ThrottlingResourceHandler : public LayeredResourceHandler, | 26 class ThrottlingResourceHandler : public LayeredResourceHandler, |
| 28 public ResourceController { | 27 public ResourceThrottle::Delegate { |
| 29 public: | 28 public: |
| 30 // Takes ownership of the ResourceThrottle instances. | 29 // Takes ownership of the ResourceThrottle instances. |
| 31 ThrottlingResourceHandler(std::unique_ptr<ResourceHandler> next_handler, | 30 ThrottlingResourceHandler(std::unique_ptr<ResourceHandler> next_handler, |
| 32 net::URLRequest* request, | 31 net::URLRequest* request, |
| 33 ScopedVector<ResourceThrottle> throttles); | 32 ScopedVector<ResourceThrottle> throttles); |
| 34 ~ThrottlingResourceHandler() override; | 33 ~ThrottlingResourceHandler() override; |
| 35 | 34 |
| 36 // LayeredResourceHandler overrides: | 35 // LayeredResourceHandler overrides: |
| 37 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 36 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 38 ResourceResponse* response, | 37 ResourceResponse* response, |
| 39 bool* defer) override; | 38 bool* defer) override; |
| 40 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; | 39 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
| 41 bool OnWillStart(const GURL& url, bool* defer) override; | 40 bool OnWillStart(const GURL& url, bool* defer) override; |
| 42 | 41 |
| 43 // ResourceController implementation: | 42 // ResourceThrottle::Delegate implementation: |
| 44 void Cancel() override; | 43 void Cancel() override; |
| 45 void CancelAndIgnore() override; | 44 void CancelAndIgnore() override; |
| 46 void CancelWithError(int error_code) override; | 45 void CancelWithError(int error_code) override; |
| 47 void Resume() override; | 46 void Resume() override; |
| 48 | 47 |
| 49 private: | 48 private: |
| 50 void ResumeStart(); | 49 void ResumeStart(); |
| 51 void ResumeRedirect(); | 50 void ResumeRedirect(); |
| 52 void ResumeResponse(); | 51 void ResumeResponse(); |
| 53 | 52 |
| 54 // Called when the throttle at |throttle_index| defers a request. Logs the | 53 // Called when the throttle at |throttle_index| defers a request. Logs the |
| 55 // name of the throttle that delayed the request. | 54 // name of the throttle that delayed the request. |
| 56 void OnRequestDefered(int throttle_index); | 55 void OnRequestDeferred(int throttle_index); |
| 57 | 56 |
| 58 enum DeferredStage { | 57 enum DeferredStage { |
| 59 DEFERRED_NONE, | 58 DEFERRED_NONE, |
| 60 DEFERRED_START, | 59 DEFERRED_START, |
| 61 DEFERRED_REDIRECT, | 60 DEFERRED_REDIRECT, |
| 62 DEFERRED_RESPONSE | 61 DEFERRED_RESPONSE |
| 63 }; | 62 }; |
| 64 DeferredStage deferred_stage_; | 63 DeferredStage deferred_stage_; |
| 65 | 64 |
| 66 ScopedVector<ResourceThrottle> throttles_; | 65 ScopedVector<ResourceThrottle> throttles_; |
| 67 size_t next_index_; | 66 size_t next_index_; |
| 68 | 67 |
| 69 GURL deferred_url_; | 68 GURL deferred_url_; |
| 70 net::RedirectInfo deferred_redirect_; | 69 net::RedirectInfo deferred_redirect_; |
| 71 scoped_refptr<ResourceResponse> deferred_response_; | 70 scoped_refptr<ResourceResponse> deferred_response_; |
| 72 | 71 |
| 73 bool cancelled_by_resource_throttle_; | 72 bool cancelled_by_resource_throttle_; |
| 74 }; | 73 }; |
| 75 | 74 |
| 76 } // namespace content | 75 } // namespace content |
| 77 | 76 |
| 78 #endif // CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_ | 77 #endif // CONTENT_BROWSER_LOADER_THROTTLING_RESOURCE_HANDLER_H_ |
| OLD | NEW |