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

Side by Side Diff: content/browser/loader/resource_loader.h

Issue 2526983002: Refactor ResourceHandler API. (Closed)
Patch Set: Fix 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_BROWSER_LOADER_RESOURCE_LOADER_H_ 5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_
6 #define CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_ 6 #define CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback_forward.h" 10 #include "base/callback_forward.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "content/browser/loader/resource_controller.h" 14 #include "content/browser/loader/resource_controller.h"
15 #include "content/browser/loader/resource_handler.h"
15 #include "content/browser/ssl/ssl_client_auth_handler.h" 16 #include "content/browser/ssl/ssl_client_auth_handler.h"
16 #include "content/browser/ssl/ssl_error_handler.h" 17 #include "content/browser/ssl/ssl_error_handler.h"
17 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
18 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
19 20
20 namespace net { 21 namespace net {
21 class X509Certificate; 22 class X509Certificate;
22 } 23 }
23 24
24 namespace content { 25 namespace content {
25 class ResourceDispatcherHostLoginDelegate; 26 class ResourceDispatcherHostLoginDelegate;
26 class ResourceHandler; 27 class ResourceHandler;
27 class ResourceLoaderDelegate; 28 class ResourceLoaderDelegate;
28 class ResourceRequestInfoImpl; 29 class ResourceRequestInfoImpl;
29 30
30 // This class is responsible for driving the URLRequest (i.e., calling Start, 31 // This class is responsible for driving the URLRequest (i.e., calling Start,
31 // Read, and servicing events). It has a ResourceHandler, which is typically a 32 // Read, and servicing events). It has a ResourceHandler, which is typically a
32 // chain of ResourceHandlers, and is the ResourceController for its handler. 33 // chain of ResourceHandlers, and is the ResourceController for its handler.
33 class CONTENT_EXPORT ResourceLoader : public net::URLRequest::Delegate, 34 class CONTENT_EXPORT ResourceLoader : public net::URLRequest::Delegate,
34 public SSLErrorHandler::Delegate, 35 public SSLErrorHandler::Delegate,
35 public SSLClientAuthHandler::Delegate, 36 public SSLClientAuthHandler::Delegate,
36 public ResourceController { 37 public ResourceHandler::Delegate {
37 public: 38 public:
38 ResourceLoader(std::unique_ptr<net::URLRequest> request, 39 ResourceLoader(std::unique_ptr<net::URLRequest> request,
39 std::unique_ptr<ResourceHandler> handler, 40 std::unique_ptr<ResourceHandler> handler,
40 ResourceLoaderDelegate* delegate); 41 ResourceLoaderDelegate* delegate);
41 ~ResourceLoader() override; 42 ~ResourceLoader() override;
42 43
43 void StartRequest(); 44 void StartRequest();
44 void CancelRequest(bool from_renderer); 45 void CancelRequest(bool from_renderer);
45 46
46 bool is_transferring() const { return is_transferring_; } 47 bool is_transferring() const { return is_transferring_; }
47 void MarkAsTransferring(const base::Closure& on_transfer_complete_callback); 48 void MarkAsTransferring(const base::Closure& on_transfer_complete_callback);
48 void CompleteTransfer(); 49 void CompleteTransfer();
49 50
50 net::URLRequest* request() { return request_.get(); } 51 net::URLRequest* request() { return request_.get(); }
51 ResourceRequestInfoImpl* GetRequestInfo(); 52 ResourceRequestInfoImpl* GetRequestInfo();
52 53
53 void ClearLoginDelegate(); 54 void ClearLoginDelegate();
54 55
56 // ResourceHandler::Delegate implementation:
57 void OutOfBandCancel(int error_code, bool tell_renderer) override;
58
55 private: 59 private:
60 // ResourceController implementation for the ResourceLoader.
61 class Controller;
62
56 // net::URLRequest::Delegate implementation: 63 // net::URLRequest::Delegate implementation:
57 void OnReceivedRedirect(net::URLRequest* request, 64 void OnReceivedRedirect(net::URLRequest* request,
58 const net::RedirectInfo& redirect_info, 65 const net::RedirectInfo& redirect_info,
59 bool* defer) override; 66 bool* defer) override;
60 void OnAuthRequired(net::URLRequest* request, 67 void OnAuthRequired(net::URLRequest* request,
61 net::AuthChallengeInfo* info) override; 68 net::AuthChallengeInfo* info) override;
62 void OnCertificateRequested(net::URLRequest* request, 69 void OnCertificateRequested(net::URLRequest* request,
63 net::SSLCertRequestInfo* info) override; 70 net::SSLCertRequestInfo* info) override;
64 void OnSSLCertificateError(net::URLRequest* request, 71 void OnSSLCertificateError(net::URLRequest* request,
65 const net::SSLInfo& info, 72 const net::SSLInfo& info,
66 bool fatal) override; 73 bool fatal) override;
67 void OnResponseStarted(net::URLRequest* request) override; 74 void OnResponseStarted(net::URLRequest* request) override;
68 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; 75 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
69 76
70 // SSLErrorHandler::Delegate implementation: 77 // SSLErrorHandler::Delegate implementation:
71 void CancelSSLRequest(int error, const net::SSLInfo* ssl_info) override; 78 void CancelSSLRequest(int error, const net::SSLInfo* ssl_info) override;
72 void ContinueSSLRequest() override; 79 void ContinueSSLRequest() override;
73 80
74 // SSLClientAuthHandler::Delegate implementation. 81 // SSLClientAuthHandler::Delegate implementation.
75 void ContinueWithCertificate(net::X509Certificate* cert) override; 82 void ContinueWithCertificate(net::X509Certificate* cert) override;
76 void CancelCertificateSelection() override; 83 void CancelCertificateSelection() override;
77 84
78 // ResourceController implementation: 85 // These correspond to Controller's methods.
79 void Resume() override; 86 // TODO(mmenke): Seems like this could be simplified a little.
80 void Cancel() override; 87
81 void CancelAndIgnore() override; 88 // |called_from_resource_controller| is true if called directly from a
82 void CancelWithError(int error_code) override; 89 // ResourceController, in which case |resource_handler_| must not be invoked
90 // or destroyed synchronously to avoid re-entrancy issues, and false
91 // otherwise.
92 void Resume(bool called_from_resource_controller);
93 void Cancel();
94 void CancelAndIgnore();
95 void CancelWithError(int error_code);
83 96
84 void StartRequestInternal(); 97 void StartRequestInternal();
85 void CancelRequestInternal(int error, bool from_renderer); 98 void CancelRequestInternal(int error, bool from_renderer);
86 void CompleteResponseStarted(); 99 void CompleteResponseStarted();
87 void ReadMore(bool is_continuation); 100 void ReadMore(bool called_from_resource_controller);
88 void ResumeReading(); 101 void ResumeReading();
89 // Passes a read result to the handler. 102 // Passes a read result to the handler.
90 void CompleteRead(int bytes_read); 103 void CompleteRead(int bytes_read);
91 void ResponseCompleted(); 104 void ResponseCompleted();
92 void CallDidFinishLoading(); 105 void CallDidFinishLoading();
93 void RecordHistograms(); 106 void RecordHistograms();
94 107
95 bool is_deferred() const { return deferred_stage_ != DEFERRED_NONE; } 108 bool is_deferred() const { return deferred_stage_ != DEFERRED_NONE; }
96 109
97 // Used for categorizing loading of prefetches for reporting in histograms. 110 // Used for categorizing loading of prefetches for reporting in histograms.
98 // NOTE: This enumeration is used in histograms, so please do not add entries 111 // NOTE: This enumeration is used in histograms, so please do not add entries
99 // in the middle. 112 // in the middle.
100 enum PrefetchStatus { 113 enum PrefetchStatus {
101 STATUS_UNDEFINED, 114 STATUS_UNDEFINED,
102 STATUS_SUCCESS_FROM_CACHE, 115 STATUS_SUCCESS_FROM_CACHE,
103 STATUS_SUCCESS_FROM_NETWORK, 116 STATUS_SUCCESS_FROM_NETWORK,
104 STATUS_CANCELED, 117 STATUS_CANCELED,
105 STATUS_SUCCESS_ALREADY_PREFETCHED, 118 STATUS_SUCCESS_ALREADY_PREFETCHED,
106 STATUS_MAX, 119 STATUS_MAX,
107 }; 120 };
108 121
109 enum DeferredStage { 122 enum DeferredStage {
110 DEFERRED_NONE, 123 DEFERRED_NONE,
124 // Magic deferral "stage" which means that the code is currently in a
125 // recursive call from the ResourceLoader. When in this state, Resume() does
126 // nothing but update the deferral state, and when the stack is unwound back
127 // up to the ResourceLoader, the request will be continued. This is used to
128 // prevent the stack from getting too deep.
129 DEFERRED_SYNC,
111 DEFERRED_START, 130 DEFERRED_START,
112 DEFERRED_REDIRECT, 131 DEFERRED_REDIRECT,
113 DEFERRED_READ, 132 DEFERRED_READ,
114 DEFERRED_RESPONSE_COMPLETE, 133 DEFERRED_RESPONSE_COMPLETE,
115 DEFERRED_FINISH 134 DEFERRED_FINISH
116 }; 135 };
117 DeferredStage deferred_stage_; 136 DeferredStage deferred_stage_;
118 137
138 class ScopedDeferral;
139
119 std::unique_ptr<net::URLRequest> request_; 140 std::unique_ptr<net::URLRequest> request_;
120 std::unique_ptr<ResourceHandler> handler_; 141 std::unique_ptr<ResourceHandler> handler_;
121 ResourceLoaderDelegate* delegate_; 142 ResourceLoaderDelegate* delegate_;
122 143
123 scoped_refptr<ResourceDispatcherHostLoginDelegate> login_delegate_; 144 scoped_refptr<ResourceDispatcherHostLoginDelegate> login_delegate_;
124 std::unique_ptr<SSLClientAuthHandler> ssl_client_auth_handler_; 145 std::unique_ptr<SSLClientAuthHandler> ssl_client_auth_handler_;
125 146
126 base::TimeTicks read_deferral_start_time_; 147 base::TimeTicks read_deferral_start_time_;
127 148
128 // Indicates that we are in a state of being transferred to a new downstream 149 // Indicates that we are in a state of being transferred to a new downstream
(...skipping 11 matching lines...) Expand all
140 int times_cancelled_after_request_start_; 161 int times_cancelled_after_request_start_;
141 162
142 base::WeakPtrFactory<ResourceLoader> weak_ptr_factory_; 163 base::WeakPtrFactory<ResourceLoader> weak_ptr_factory_;
143 164
144 DISALLOW_COPY_AND_ASSIGN(ResourceLoader); 165 DISALLOW_COPY_AND_ASSIGN(ResourceLoader);
145 }; 166 };
146 167
147 } // namespace content 168 } // namespace content
148 169
149 #endif // CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_ 170 #endif // CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698