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

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

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

Powered by Google App Engine
This is Rietveld 408576698