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 "content/common/content_export.h" |
| 9 |
8 namespace net { | 10 namespace net { |
9 struct RedirectInfo; | 11 struct RedirectInfo; |
10 } | 12 } |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 | 15 |
14 class AsyncRevalidationDriver; | 16 class AsyncRevalidationDriver; |
15 class ResourceController; | 17 class ResourceController; |
16 class ThrottlingResourceHandler; | 18 class ThrottlingResourceHandler; |
17 | 19 |
18 // A ResourceThrottle gets notified at various points during the process of | 20 // A ResourceThrottle gets notified at various points during the process of |
19 // 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 |
20 // resource load. The ResourceController interface may be used to resume a | 22 // resource load. The ResourceController interface may be used to resume a |
21 // 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 |
22 // time. | 24 // time. |
23 class ResourceThrottle { | 25 class CONTENT_EXPORT ResourceThrottle { |
24 public: | 26 public: |
25 virtual ~ResourceThrottle() {} | 27 virtual ~ResourceThrottle() {} |
26 | 28 |
27 // Called before the resource request is started. | 29 // Called before the resource request is started. |
28 virtual void WillStartRequest(bool* defer) {} | 30 virtual void WillStartRequest(bool* defer) {} |
29 | 31 |
30 // Called when the request was redirected. |redirect_info| contains the | 32 // Called when the request was redirected. |redirect_info| contains the |
31 // redirect responses's HTTP status code and some information about the new | 33 // redirect responses's HTTP status code and some information about the new |
32 // request that will be sent if the redirect is followed, including the new | 34 // request that will be sent if the redirect is followed, including the new |
33 // URL and new method. | 35 // URL and new method. |
34 virtual void WillRedirectRequest(const net::RedirectInfo& redirect_info, | 36 virtual void WillRedirectRequest(const net::RedirectInfo& redirect_info, |
35 bool* defer) {} | 37 bool* defer) {} |
36 | 38 |
37 // Called when the response headers and meta data are available. | 39 // Called when the response headers and meta data are available. |
38 virtual void WillProcessResponse(bool* defer) {} | 40 virtual void WillProcessResponse(bool* defer) {} |
39 | 41 |
40 // Returns the name of the throttle, as a UTF-8 C-string, for logging | 42 // Returns the name of the throttle, as a UTF-8 C-string, for logging |
41 // purposes. nullptr is not allowed. Caller does *not* take ownership of the | 43 // purposes. nullptr is not allowed. Caller does *not* take ownership of the |
42 // returned string. | 44 // returned string. |
43 virtual const char* GetNameForLogging() const = 0; | 45 virtual const char* GetNameForLogging() const = 0; |
44 | 46 |
| 47 // Whether this ResourceThrottle needs to execute WillProcessResponse before |
| 48 // any part of the response body is read. Normally this is false. This should |
| 49 // be set to true if the ResourceThrottle wants to ensure that no part of the |
| 50 // response body will be cached if the request is canceled in |
| 51 // WillProcessResponse. |
| 52 virtual bool MustProcessResponseBeforeReadingBody(); |
| 53 |
45 void set_controller_for_testing(ResourceController* c) { | 54 void set_controller_for_testing(ResourceController* c) { |
46 controller_ = c; | 55 controller_ = c; |
47 } | 56 } |
48 | 57 |
49 protected: | 58 protected: |
50 ResourceThrottle() : controller_(nullptr) {} | 59 ResourceThrottle() : controller_(nullptr) {} |
51 ResourceController* controller() { return controller_; } | 60 ResourceController* controller() { return controller_; } |
52 | 61 |
53 private: | 62 private: |
54 friend class AsyncRevalidationDriver; | 63 friend class AsyncRevalidationDriver; |
55 friend class ThrottlingResourceHandler; | 64 friend class ThrottlingResourceHandler; |
56 void set_controller(ResourceController* c) { controller_ = c; } | 65 void set_controller(ResourceController* c) { controller_ = c; } |
57 | 66 |
58 ResourceController* controller_; | 67 ResourceController* controller_; |
59 }; | 68 }; |
60 | 69 |
61 } // namespace content | 70 } // namespace content |
62 | 71 |
63 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_ | 72 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_ |
OLD | NEW |