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 // mime sniffing happens. Normally this is false. This should be set to true | |
49 // if the ResourceThrottle wants to ensure that no part of the response will | |
50 // be cached if the request is canceled in WillProcessResponse. | |
51 virtual bool MustProcessResponseBeforeMimeSniffing(); | |
mmenke
2016/07/27 19:34:01
Could name this be more general? MustProcessRespo
clamy
2016/08/17 12:47:35
Done.
To do what you suggest we have two options:
mmenke
2016/08/17 19:53:08
I don't think this is going to happen, reliably -
clamy
2016/08/18 12:01:51
Acknowledged.
| |
52 | |
45 void set_controller_for_testing(ResourceController* c) { | 53 void set_controller_for_testing(ResourceController* c) { |
46 controller_ = c; | 54 controller_ = c; |
47 } | 55 } |
48 | 56 |
49 protected: | 57 protected: |
50 ResourceThrottle() : controller_(nullptr) {} | 58 ResourceThrottle() : controller_(nullptr) {} |
51 ResourceController* controller() { return controller_; } | 59 ResourceController* controller() { return controller_; } |
52 | 60 |
53 private: | 61 private: |
54 friend class AsyncRevalidationDriver; | 62 friend class AsyncRevalidationDriver; |
55 friend class ThrottlingResourceHandler; | 63 friend class ThrottlingResourceHandler; |
56 void set_controller(ResourceController* c) { controller_ = c; } | 64 void set_controller(ResourceController* c) { controller_ = c; } |
57 | 65 |
58 ResourceController* controller_; | 66 ResourceController* controller_; |
59 }; | 67 }; |
60 | 68 |
61 } // namespace content | 69 } // namespace content |
62 | 70 |
63 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_ | 71 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_ |
OLD | NEW |