Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / content / browser / loader / resource_request_info_impl.cc
blob20ce8d98cea9c631dfd396e810c0934062b839ea
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
3 // found in the LICENSE file.
5 #include "content/browser/loader/resource_request_info_impl.h"
7 #include "content/browser/loader/global_routing_id.h"
8 #include "content/browser/loader/resource_message_filter.h"
9 #include "content/common/net/url_request_user_data.h"
10 #include "content/public/browser/global_request_id.h"
11 #include "content/public/common/process_type.h"
12 #include "net/url_request/url_request.h"
14 namespace content {
16 // ----------------------------------------------------------------------------
17 // ResourceRequestInfo
19 // static
20 const ResourceRequestInfo* ResourceRequestInfo::ForRequest(
21 const net::URLRequest* request) {
22 return ResourceRequestInfoImpl::ForRequest(request);
25 // static
26 void ResourceRequestInfo::AllocateForTesting(net::URLRequest* request,
27 ResourceType resource_type,
28 ResourceContext* context,
29 int render_process_id,
30 int render_view_id,
31 int render_frame_id,
32 bool is_main_frame,
33 bool parent_is_main_frame,
34 bool allow_download,
35 bool is_async) {
36 // Make sure both |is_main_frame| and |parent_is_main_frame| aren't set at the
37 // same time.
38 DCHECK(!(is_main_frame && parent_is_main_frame));
40 // Make sure RESOURCE_TYPE_MAIN_FRAME is declared as being fetched as part of
41 // the main frame.
42 DCHECK(resource_type != RESOURCE_TYPE_MAIN_FRAME || is_main_frame);
44 ResourceRequestInfoImpl* info =
45 new ResourceRequestInfoImpl(
46 PROCESS_TYPE_RENDERER, // process_type
47 render_process_id, // child_id
48 render_view_id, // route_id
49 -1, // frame_tree_node_id
50 0, // origin_pid
51 0, // request_id
52 render_frame_id, // render_frame_id
53 is_main_frame, // is_main_frame
54 parent_is_main_frame, // parent_is_main_frame
55 0, // parent_render_frame_id
56 resource_type, // resource_type
57 ui::PAGE_TRANSITION_LINK, // transition_type
58 false, // should_replace_current_entry
59 false, // is_download
60 false, // is_stream
61 allow_download, // allow_download
62 false, // has_user_gesture
63 false, // enable load timing
64 request->has_upload(), // enable upload progress
65 false, // do_not_prompt_for_login
66 blink::WebReferrerPolicyDefault, // referrer_policy
67 blink::WebPageVisibilityStateVisible, // visibility_state
68 context, // context
69 base::WeakPtr<ResourceMessageFilter>(), // filter
70 is_async); // is_async
71 info->AssociateWithRequest(request);
74 // static
75 bool ResourceRequestInfo::GetRenderFrameForRequest(
76 const net::URLRequest* request,
77 int* render_process_id,
78 int* render_frame_id) {
79 URLRequestUserData* user_data = static_cast<URLRequestUserData*>(
80 request->GetUserData(URLRequestUserData::kUserDataKey));
81 if (!user_data)
82 return false;
83 *render_process_id = user_data->render_process_id();
84 *render_frame_id = user_data->render_frame_id();
85 return true;
88 // ----------------------------------------------------------------------------
89 // ResourceRequestInfoImpl
91 // static
92 ResourceRequestInfoImpl* ResourceRequestInfoImpl::ForRequest(
93 net::URLRequest* request) {
94 return static_cast<ResourceRequestInfoImpl*>(request->GetUserData(NULL));
97 // static
98 const ResourceRequestInfoImpl* ResourceRequestInfoImpl::ForRequest(
99 const net::URLRequest* request) {
100 return ForRequest(const_cast<net::URLRequest*>(request));
103 ResourceRequestInfoImpl::ResourceRequestInfoImpl(
104 int process_type,
105 int child_id,
106 int route_id,
107 int frame_tree_node_id,
108 int origin_pid,
109 int request_id,
110 int render_frame_id,
111 bool is_main_frame,
112 bool parent_is_main_frame,
113 int parent_render_frame_id,
114 ResourceType resource_type,
115 ui::PageTransition transition_type,
116 bool should_replace_current_entry,
117 bool is_download,
118 bool is_stream,
119 bool allow_download,
120 bool has_user_gesture,
121 bool enable_load_timing,
122 bool enable_upload_progress,
123 bool do_not_prompt_for_login,
124 blink::WebReferrerPolicy referrer_policy,
125 blink::WebPageVisibilityState visibility_state,
126 ResourceContext* context,
127 base::WeakPtr<ResourceMessageFilter> filter,
128 bool is_async)
129 : cross_site_handler_(NULL),
130 detachable_handler_(NULL),
131 process_type_(process_type),
132 child_id_(child_id),
133 route_id_(route_id),
134 frame_tree_node_id_(frame_tree_node_id),
135 origin_pid_(origin_pid),
136 request_id_(request_id),
137 render_frame_id_(render_frame_id),
138 is_main_frame_(is_main_frame),
139 parent_is_main_frame_(parent_is_main_frame),
140 parent_render_frame_id_(parent_render_frame_id),
141 should_replace_current_entry_(should_replace_current_entry),
142 is_download_(is_download),
143 is_stream_(is_stream),
144 allow_download_(allow_download),
145 has_user_gesture_(has_user_gesture),
146 enable_load_timing_(enable_load_timing),
147 enable_upload_progress_(enable_upload_progress),
148 do_not_prompt_for_login_(do_not_prompt_for_login),
149 was_ignored_by_handler_(false),
150 counted_as_in_flight_request_(false),
151 resource_type_(resource_type),
152 transition_type_(transition_type),
153 memory_cost_(0),
154 referrer_policy_(referrer_policy),
155 visibility_state_(visibility_state),
156 context_(context),
157 filter_(filter),
158 is_async_(is_async) {
161 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() {
164 ResourceContext* ResourceRequestInfoImpl::GetContext() const {
165 return context_;
168 int ResourceRequestInfoImpl::GetChildID() const {
169 return child_id_;
172 int ResourceRequestInfoImpl::GetRouteID() const {
173 return route_id_;
176 int ResourceRequestInfoImpl::GetOriginPID() const {
177 return origin_pid_;
180 int ResourceRequestInfoImpl::GetRequestID() const {
181 return request_id_;
184 int ResourceRequestInfoImpl::GetRenderFrameID() const {
185 return render_frame_id_;
188 bool ResourceRequestInfoImpl::IsMainFrame() const {
189 return is_main_frame_;
192 bool ResourceRequestInfoImpl::ParentIsMainFrame() const {
193 return parent_is_main_frame_;
196 int ResourceRequestInfoImpl::GetParentRenderFrameID() const {
197 return parent_render_frame_id_;
200 ResourceType ResourceRequestInfoImpl::GetResourceType() const {
201 return resource_type_;
204 int ResourceRequestInfoImpl::GetProcessType() const {
205 return process_type_;
208 blink::WebReferrerPolicy ResourceRequestInfoImpl::GetReferrerPolicy() const {
209 return referrer_policy_;
212 blink::WebPageVisibilityState
213 ResourceRequestInfoImpl::GetVisibilityState() const {
214 return visibility_state_;
217 ui::PageTransition ResourceRequestInfoImpl::GetPageTransition() const {
218 return transition_type_;
221 bool ResourceRequestInfoImpl::HasUserGesture() const {
222 return has_user_gesture_;
225 bool ResourceRequestInfoImpl::WasIgnoredByHandler() const {
226 return was_ignored_by_handler_;
229 bool ResourceRequestInfoImpl::GetAssociatedRenderFrame(
230 int* render_process_id,
231 int* render_frame_id) const {
232 if (process_type_ == PROCESS_TYPE_PLUGIN) {
233 *render_process_id = origin_pid_;
234 *render_frame_id = render_frame_id_;
235 } else {
236 *render_process_id = child_id_;
237 *render_frame_id = render_frame_id_;
239 return true;
242 bool ResourceRequestInfoImpl::IsAsync() const {
243 return is_async_;
246 bool ResourceRequestInfoImpl::IsDownload() const {
247 return is_download_;
250 void ResourceRequestInfoImpl::AssociateWithRequest(net::URLRequest* request) {
251 request->SetUserData(NULL, this);
252 int render_process_id;
253 int render_frame_id;
254 if (GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) {
255 request->SetUserData(
256 URLRequestUserData::kUserDataKey,
257 new URLRequestUserData(render_process_id, render_frame_id));
261 GlobalRequestID ResourceRequestInfoImpl::GetGlobalRequestID() const {
262 return GlobalRequestID(child_id_, request_id_);
265 GlobalRoutingID ResourceRequestInfoImpl::GetGlobalRoutingID() const {
266 return GlobalRoutingID(child_id_, route_id_);
269 void ResourceRequestInfoImpl::UpdateForTransfer(
270 int child_id,
271 int route_id,
272 int origin_pid,
273 int request_id,
274 int parent_render_frame_id,
275 base::WeakPtr<ResourceMessageFilter> filter) {
276 child_id_ = child_id;
277 route_id_ = route_id;
278 origin_pid_ = origin_pid;
279 request_id_ = request_id;
280 parent_render_frame_id_ = parent_render_frame_id;
281 filter_ = filter;
284 } // namespace content