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

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

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: fix unittests Created 4 years, 1 month 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_REQUEST_INFO_IMPL_H_ 5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
6 #define CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_ 6 #define CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/supports_user_data.h" 16 #include "base/supports_user_data.h"
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" 17 #include "content/browser/loader/resource_requester_info.h"
18 #include "content/common/resource_request_body_impl.h" 18 #include "content/common/resource_request_body_impl.h"
19 #include "content/public/browser/navigation_ui_data.h" 19 #include "content/public/browser/navigation_ui_data.h"
20 #include "content/public/browser/resource_request_info.h" 20 #include "content/public/browser/resource_request_info.h"
21 #include "content/public/common/referrer.h" 21 #include "content/public/common/referrer.h"
22 #include "content/public/common/resource_type.h" 22 #include "content/public/common/resource_type.h"
23 #include "net/base/load_states.h" 23 #include "net/base/load_states.h"
24 24
25 namespace content { 25 namespace content {
26 class DetachableResourceHandler; 26 class DetachableResourceHandler;
27 class ResourceContext; 27 class ResourceContext;
28 class ResourceMessageFilter; 28 class ResourceMessageFilter;
29 struct GlobalRequestID; 29 struct GlobalRequestID;
30 struct GlobalRoutingID; 30 struct GlobalRoutingID;
31 31
32 // Holds the data ResourceDispatcherHost associates with each request. 32 // Holds the data ResourceDispatcherHost associates with each request.
33 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest. 33 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest.
34 class ResourceRequestInfoImpl : public ResourceRequestInfo, 34 class ResourceRequestInfoImpl : public ResourceRequestInfo,
35 public base::SupportsUserData::Data { 35 public base::SupportsUserData::Data {
36 public: 36 public:
37 // Returns the ResourceRequestInfoImpl associated with the given URLRequest. 37 // Returns the ResourceRequestInfoImpl associated with the given URLRequest.
38 CONTENT_EXPORT static ResourceRequestInfoImpl* ForRequest( 38 CONTENT_EXPORT static ResourceRequestInfoImpl* ForRequest(
39 net::URLRequest* request); 39 net::URLRequest* request);
40 40
41 // And, a const version for cases where you only need read access. 41 // And, a const version for cases where you only need read access.
42 CONTENT_EXPORT static const ResourceRequestInfoImpl* ForRequest( 42 CONTENT_EXPORT static const ResourceRequestInfoImpl* ForRequest(
43 const net::URLRequest* request); 43 const net::URLRequest* request);
44 44
45 CONTENT_EXPORT ResourceRequestInfoImpl( 45 CONTENT_EXPORT ResourceRequestInfoImpl(
46 int process_type, 46 std::unique_ptr<ResourceRequesterInfo> requester_info,
47 int child_id,
48 int route_id, 47 int route_id,
49 int frame_tree_node_id, 48 int frame_tree_node_id,
50 int origin_pid, 49 int origin_pid,
51 int request_id, 50 int request_id,
52 int render_frame_id, 51 int render_frame_id,
53 bool is_main_frame, 52 bool is_main_frame,
54 bool parent_is_main_frame, 53 bool parent_is_main_frame,
55 ResourceType resource_type, 54 ResourceType resource_type,
56 ui::PageTransition transition_type, 55 ui::PageTransition transition_type,
57 bool should_replace_current_entry, 56 bool should_replace_current_entry,
58 bool is_download, 57 bool is_download,
59 bool is_stream, 58 bool is_stream,
60 bool allow_download, 59 bool allow_download,
61 bool has_user_gesture, 60 bool has_user_gesture,
62 bool enable_load_timing, 61 bool enable_load_timing,
63 bool enable_upload_progress, 62 bool enable_upload_progress,
64 bool do_not_prompt_for_login, 63 bool do_not_prompt_for_login,
65 blink::WebReferrerPolicy referrer_policy, 64 blink::WebReferrerPolicy referrer_policy,
66 blink::WebPageVisibilityState visibility_state, 65 blink::WebPageVisibilityState visibility_state,
67 ResourceContext* context, 66 ResourceContext* context,
68 base::WeakPtr<ResourceMessageFilter> filter,
69 bool report_raw_headers, 67 bool report_raw_headers,
70 bool is_async, 68 bool is_async,
71 bool is_using_lofi, 69 bool is_using_lofi,
72 const std::string& original_headers, 70 const std::string& original_headers,
73 const scoped_refptr<ResourceRequestBodyImpl> body, 71 const scoped_refptr<ResourceRequestBodyImpl> body,
74 bool initiated_in_secure_context); 72 bool initiated_in_secure_context);
75 ~ResourceRequestInfoImpl() override; 73 ~ResourceRequestInfoImpl() override;
76 74
77 // ResourceRequestInfo implementation: 75 // ResourceRequestInfo implementation:
78 WebContentsGetter GetWebContentsGetterForRequest() const override; 76 WebContentsGetter GetWebContentsGetterForRequest() const override;
(...skipping 24 matching lines...) Expand all
103 CONTENT_EXPORT void AssociateWithRequest(net::URLRequest* request); 101 CONTENT_EXPORT void AssociateWithRequest(net::URLRequest* request);
104 102
105 CONTENT_EXPORT int GetRequestID() const; 103 CONTENT_EXPORT int GetRequestID() const;
106 GlobalRoutingID GetGlobalRoutingID() const; 104 GlobalRoutingID GetGlobalRoutingID() const;
107 105
108 // PlzNavigate 106 // PlzNavigate
109 // The id of the FrameTreeNode that initiated this request (for a navigation 107 // The id of the FrameTreeNode that initiated this request (for a navigation
110 // request). 108 // request).
111 int frame_tree_node_id() const { return frame_tree_node_id_; } 109 int frame_tree_node_id() const { return frame_tree_node_id_; }
112 110
113 // May be NULL (e.g., if process dies during a transfer). 111 const ResourceRequesterInfo& requester_info() const {
114 ResourceMessageFilter* filter() const { 112 return *(requester_info_.get());
mmenke 2016/11/17 16:27:20 nit: Is the get actually needed?
horo 2016/11/17 17:50:27 Done.
115 return filter_.get();
116 } 113 }
117 114
118 // Updates the data associated with this request after it is is transferred 115 // Updates the data associated with this request after it is is transferred
119 // to a new renderer process. Not all data will change during a transfer. 116 // to a new renderer process. Not all data will change during a transfer.
120 // We do not expect the ResourceContext to change during navigation, so that 117 // We do not expect the ResourceContext to change during navigation, so that
121 // does not need to be updated. 118 // does not need to be updated.
122 void UpdateForTransfer(int child_id, 119 void UpdateForTransfer(int route_id,
123 int route_id,
124 int render_frame_id, 120 int render_frame_id,
125 int origin_pid, 121 int origin_pid,
126 int request_id, 122 int request_id,
127 base::WeakPtr<ResourceMessageFilter> filter); 123 std::unique_ptr<ResourceRequesterInfo> requester_info);
128 124
129 // Whether this request is part of a navigation that should replace the 125 // Whether this request is part of a navigation that should replace the
130 // current session history entry. This state is shuffled up and down the stack 126 // current session history entry. This state is shuffled up and down the stack
131 // for request transfers. 127 // for request transfers.
132 bool should_replace_current_entry() const { 128 bool should_replace_current_entry() const {
133 return should_replace_current_entry_; 129 return should_replace_current_entry_;
134 } 130 }
135 131
136 // DetachableResourceHandler for this request. May be NULL. 132 // DetachableResourceHandler for this request. May be NULL.
137 DetachableResourceHandler* detachable_handler() const { 133 DetachableResourceHandler* detachable_handler() const {
138 return detachable_handler_; 134 return detachable_handler_;
139 } 135 }
140 void set_detachable_handler(DetachableResourceHandler* h) { 136 void set_detachable_handler(DetachableResourceHandler* h) {
141 detachable_handler_ = h; 137 detachable_handler_ = h;
142 } 138 }
143 139
144 // Identifies the type of process (renderer, plugin, etc.) making the request.
145 int process_type() const { return process_type_; }
146
147 // Downloads are allowed only as a top level request. 140 // Downloads are allowed only as a top level request.
148 bool allow_download() const { return allow_download_; } 141 bool allow_download() const { return allow_download_; }
149 142
150 // Whether this is a download. 143 // Whether this is a download.
151 void set_is_download(bool download) { is_download_ = download; } 144 void set_is_download(bool download) { is_download_ = download; }
152 145
153 // Whether this is a stream. 146 // Whether this is a stream.
154 bool is_stream() const { return is_stream_; } 147 bool is_stream() const { return is_stream_; }
155 void set_is_stream(bool stream) { is_stream_ = stream; } 148 void set_is_stream(bool stream) { is_stream_ = stream; }
156 149
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 184 }
192 void set_initiated_in_secure_context_for_testing(bool secure) { 185 void set_initiated_in_secure_context_for_testing(bool secure) {
193 initiated_in_secure_context_ = secure; 186 initiated_in_secure_context_ = secure;
194 } 187 }
195 188
196 void set_navigation_ui_data( 189 void set_navigation_ui_data(
197 std::unique_ptr<NavigationUIData> navigation_ui_data) { 190 std::unique_ptr<NavigationUIData> navigation_ui_data) {
198 navigation_ui_data_ = std::move(navigation_ui_data); 191 navigation_ui_data_ = std::move(navigation_ui_data);
199 } 192 }
200 193
201 // PlzNavigate: used in navigations to store the ServiceWorkerContext, since
202 // the ResourceMessageFilter will be null in this case. All other requests
203 // should access the ServiceWorkerContext through the ResourceMessageFilter.
204 void set_service_worker_context(
205 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
206 service_worker_context_ = service_worker_context;
207 }
208 ServiceWorkerContextWrapper* service_worker_context() const {
209 return service_worker_context_.get();
210 }
211
212 private: 194 private:
213 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 195 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
214 DeletedFilterDetached); 196 DeletedFilterDetached);
215 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest, 197 FRIEND_TEST_ALL_PREFIXES(ResourceDispatcherHostTest,
216 DeletedFilterDetachedRedirect); 198 DeletedFilterDetachedRedirect);
217 // Non-owning, may be NULL. 199 // Non-owning, may be NULL.
218 DetachableResourceHandler* detachable_handler_; 200 DetachableResourceHandler* detachable_handler_;
219 201
220 int process_type_; 202 std::unique_ptr<ResourceRequesterInfo> requester_info_;
221 int child_id_;
222 int route_id_; 203 int route_id_;
223 const int frame_tree_node_id_; 204 const int frame_tree_node_id_;
224 int origin_pid_; 205 int origin_pid_;
225 int request_id_; 206 int request_id_;
226 int render_frame_id_; 207 int render_frame_id_;
227 bool is_main_frame_; 208 bool is_main_frame_;
228 bool parent_is_main_frame_; 209 bool parent_is_main_frame_;
229 bool should_replace_current_entry_; 210 bool should_replace_current_entry_;
230 bool is_download_; 211 bool is_download_;
231 bool is_stream_; 212 bool is_stream_;
232 bool allow_download_; 213 bool allow_download_;
233 bool has_user_gesture_; 214 bool has_user_gesture_;
234 bool enable_load_timing_; 215 bool enable_load_timing_;
235 bool enable_upload_progress_; 216 bool enable_upload_progress_;
236 bool do_not_prompt_for_login_; 217 bool do_not_prompt_for_login_;
237 bool was_ignored_by_handler_; 218 bool was_ignored_by_handler_;
238 bool counted_as_in_flight_request_; 219 bool counted_as_in_flight_request_;
239 ResourceType resource_type_; 220 ResourceType resource_type_;
240 ui::PageTransition transition_type_; 221 ui::PageTransition transition_type_;
241 int memory_cost_; 222 int memory_cost_;
242 blink::WebReferrerPolicy referrer_policy_; 223 blink::WebReferrerPolicy referrer_policy_;
243 blink::WebPageVisibilityState visibility_state_; 224 blink::WebPageVisibilityState visibility_state_;
244 ResourceContext* context_; 225 ResourceContext* context_;
245 // The filter might be deleted without deleting this object if the process
246 // exits during a transfer.
247 base::WeakPtr<ResourceMessageFilter> filter_;
248 bool report_raw_headers_; 226 bool report_raw_headers_;
249 bool is_async_; 227 bool is_async_;
250 bool is_using_lofi_; 228 bool is_using_lofi_;
251 const std::string original_headers_; 229 const std::string original_headers_;
252 scoped_refptr<ResourceRequestBodyImpl> body_; 230 scoped_refptr<ResourceRequestBodyImpl> body_;
253 bool initiated_in_secure_context_; 231 bool initiated_in_secure_context_;
254 std::unique_ptr<NavigationUIData> navigation_ui_data_; 232 std::unique_ptr<NavigationUIData> navigation_ui_data_;
255 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
256 233
257 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl); 234 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl);
258 }; 235 };
259 236
260 } // namespace content 237 } // namespace content
261 238
262 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_ 239 #endif // CONTENT_BROWSER_LOADER_RESOURCE_REQUEST_INFO_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698