Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: content/public/browser/resource_throttle.h

Issue 2535723005: Stop using ResourceController in ResourceThrottle (Closed)
Patch Set: Addressed #48 Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 8 #include "content/common/content_export.h"
9 9
10 namespace net { 10 namespace net {
11 struct RedirectInfo; 11 struct RedirectInfo;
12 } 12 }
13 13
14 namespace content { 14 namespace content {
15 15
16 class AsyncRevalidationDriver; 16 class AsyncRevalidationDriver;
17 class ResourceController; 17 class ResourceController;
18 class ThrottlingResourceHandler; 18 class ThrottlingResourceHandler;
19 19
20 // A ResourceThrottle gets notified at various points during the process of 20 // A ResourceThrottle gets notified at various points during the process of
21 // 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
22 // resource load. The ResourceController interface may be used to resume a 22 // resource load. The ResourceController interface may be used to resume a
23 // 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
24 // time. 24 // time.
25 class CONTENT_EXPORT ResourceThrottle { 25 class CONTENT_EXPORT ResourceThrottle {
26 public: 26 public:
27 // An interface to get notified when the throttle implementation considers
28 // it's ready to resume the deferred resource load. The throttle
29 // implementation may also tell the delegate to cancel the resource loading.
30 class CONTENT_EXPORT Delegate {
31 public:
32 // Cancels the resource load.
33 virtual void Cancel() = 0;
34 // Marks the resource load as ignored by the resource handler, and then
35 // cancels the resource load.
36 virtual void CancelAndIgnore() = 0;
37 // Cancels the resource load with the specified error code.
38 virtual void CancelWithError(int error_code) = 0;
39 // Tells the delegate to resume the deferred resource load.
40 virtual void Resume() = 0;
41
42 protected:
43 virtual ~Delegate() {}
44 };
45
27 virtual ~ResourceThrottle() {} 46 virtual ~ResourceThrottle() {}
28 47
29 // Called before the resource request is started. 48 // Called before the resource request is started.
30 virtual void WillStartRequest(bool* defer) {} 49 virtual void WillStartRequest(bool* defer) {}
31 50
32 // Called when the request was redirected. |redirect_info| contains the 51 // Called when the request was redirected. |redirect_info| contains the
33 // redirect responses's HTTP status code and some information about the new 52 // redirect responses's HTTP status code and some information about the new
34 // request that will be sent if the redirect is followed, including the new 53 // request that will be sent if the redirect is followed, including the new
35 // URL and new method. 54 // URL and new method.
36 virtual void WillRedirectRequest(const net::RedirectInfo& redirect_info, 55 virtual void WillRedirectRequest(const net::RedirectInfo& redirect_info,
37 bool* defer) {} 56 bool* defer) {}
38 57
39 // Called when the response headers and meta data are available. 58 // Called when the response headers and meta data are available.
40 virtual void WillProcessResponse(bool* defer) {} 59 virtual void WillProcessResponse(bool* defer) {}
41 60
42 // Returns the name of the throttle, as a UTF-8 C-string, for logging 61 // Returns the name of the throttle, as a UTF-8 C-string, for logging
43 // purposes. nullptr is not allowed. Caller does *not* take ownership of the 62 // purposes. nullptr is not allowed. Caller does *not* take ownership of the
44 // returned string. 63 // returned string.
45 virtual const char* GetNameForLogging() const = 0; 64 virtual const char* GetNameForLogging() const = 0;
46 65
47 // Whether this ResourceThrottle needs to execute WillProcessResponse before 66 // Whether this ResourceThrottle needs to execute WillProcessResponse before
48 // any part of the response body is read. Normally this is false. This should 67 // 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 68 // 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 69 // response body will be cached if the request is canceled in
51 // WillProcessResponse. 70 // WillProcessResponse.
52 virtual bool MustProcessResponseBeforeReadingBody(); 71 virtual bool MustProcessResponseBeforeReadingBody();
53 72
54 void set_controller_for_testing(ResourceController* c) { 73 void set_delegate_for_testing(Delegate* delegate) { delegate_ = delegate; }
55 controller_ = c;
56 }
57 74
58 protected: 75 protected:
59 ResourceThrottle() : controller_(nullptr) {} 76 ResourceThrottle() : delegate_(nullptr) {}
60 ResourceController* controller() { return controller_; } 77
78 // Helper methods for subclasses. When these methods are called, methods with
79 // the same name on |delegate_| are called.
80 void Cancel();
81 void CancelAndIgnore();
82 void CancelWithError(int error_code);
83 void Resume();
61 84
62 private: 85 private:
63 friend class AsyncRevalidationDriver; 86 friend class AsyncRevalidationDriver;
64 friend class ThrottlingResourceHandler; 87 friend class ThrottlingResourceHandler;
65 void set_controller(ResourceController* c) { controller_ = c; }
66 88
67 ResourceController* controller_; 89 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
90
91 Delegate* delegate_;
mmenke 2016/12/06 20:16:42 With the ResourceController dependency removed, yo
tyoshino (SeeGerritForStatus) 2016/12/07 05:52:15 OK. Let me do it in the next CL.
tyoshino (SeeGerritForStatus) 2016/12/07 08:34:24 Created https://codereview.chromium.org/2554273002
68 }; 92 };
69 93
70 } // namespace content 94 } // namespace content
71 95
72 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_ 96 #endif // CONTENT_PUBLIC_BROWSER_RESOURCE_THROTTLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698