| 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_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_ | 6 #define CONTENT_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 class GURL; | 10 class GURL; |
| 11 | 11 |
| 12 namespace net { |
| 13 struct RedirectInfo; |
| 14 } |
| 15 |
| 12 namespace content { | 16 namespace content { |
| 13 | 17 |
| 14 class ResourceController; | 18 class ResourceController; |
| 15 | 19 |
| 16 // A ResourceThrottle gets notified at various points during the process of | 20 // A ResourceThrottle gets notified at various points during the process of |
| 17 // loading a resource. At each stage, it has the opportunity to defer the | 21 // loading a resource. At each stage, it has the opportunity to defer the |
| 18 // resource load. The ResourceController interface may be used to resume a | 22 // resource load. The ResourceController interface may be used to resume a |
| 19 // deferred resource load, or it may be used to cancel a resource load at any | 23 // deferred resource load, or it may be used to cancel a resource load at any |
| 20 // time. | 24 // time. |
| 21 class ResourceThrottle { | 25 class ResourceThrottle { |
| 22 public: | 26 public: |
| 23 virtual ~ResourceThrottle() {} | 27 virtual ~ResourceThrottle() {} |
| 24 | 28 |
| 29 // Called before the resource request is started. |
| 25 virtual void WillStartRequest(bool* defer) {} | 30 virtual void WillStartRequest(bool* defer) {} |
| 31 |
| 32 // Called before the resource request uses the network for the first time. |
| 26 virtual void WillStartUsingNetwork(bool* defer) {} | 33 virtual void WillStartUsingNetwork(bool* defer) {} |
| 27 virtual void WillRedirectRequest(const GURL& new_url, bool* defer) {} | 34 |
| 35 // Called when the request was redirected. |redirect_info| contains the |
| 36 // redirect responses's HTTP status code and some information about the new |
| 37 // request that will be sent if the redirect is followed, including the new |
| 38 // URL and new method. |
| 39 virtual void WillRedirectRequest(const net::RedirectInfo& redirect_info, |
| 40 bool* defer) {} |
| 41 |
| 42 // Called when the response headers and meta data are available. |
| 28 virtual void WillProcessResponse(bool* defer) {} | 43 virtual void WillProcessResponse(bool* defer) {} |
| 29 | 44 |
| 30 // Returns the name of the throttle, as a UTF-8 C-string, for logging | 45 // Returns the name of the throttle, as a UTF-8 C-string, for logging |
| 31 // purposes. nullptr is not allowed. Caller does *not* take ownership of the | 46 // purposes. nullptr is not allowed. Caller does *not* take ownership of the |
| 32 // returned string. | 47 // returned string. |
| 33 virtual const char* GetNameForLogging() const = 0; | 48 virtual const char* GetNameForLogging() const = 0; |
| 34 | 49 |
| 35 void set_controller_for_testing(ResourceController* c) { | 50 void set_controller_for_testing(ResourceController* c) { |
| 36 controller_ = c; | 51 controller_ = c; |
| 37 } | 52 } |
| 38 | 53 |
| 39 protected: | 54 protected: |
| 40 ResourceThrottle() : controller_(nullptr) {} | 55 ResourceThrottle() : controller_(nullptr) {} |
| 41 ResourceController* controller() { return controller_; } | 56 ResourceController* controller() { return controller_; } |
| 42 | 57 |
| 43 private: | 58 private: |
| 44 friend class ThrottlingResourceHandler; | 59 friend class ThrottlingResourceHandler; |
| 45 void set_controller(ResourceController* c) { controller_ = c; } | 60 void set_controller(ResourceController* c) { controller_ = c; } |
| 46 | 61 |
| 47 ResourceController* controller_; | 62 ResourceController* controller_; |
| 48 }; | 63 }; |
| 49 | 64 |
| 50 } // namespace content | 65 } // namespace content |
| 51 | 66 |
| 52 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_ | 67 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_ |
| OLD | NEW |