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

Side by Side Diff: content/browser/loader/async_resource_handler.cc

Issue 25772002: Allows prefetch requests to live beyond the renderer by delaying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created a detached state. Data is sent to renderer until detached. Fixed up tests. Created 7 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 #include "content/browser/loader/async_resource_handler.h" 5 #include "content/browser/loader/async_resource_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (buffer_->CanAllocate()) 130 if (buffer_->CanAllocate())
131 ResumeIfDeferred(); 131 ResumeIfDeferred();
132 } 132 }
133 } 133 }
134 134
135 bool AsyncResourceHandler::OnUploadProgress(int request_id, 135 bool AsyncResourceHandler::OnUploadProgress(int request_id,
136 uint64 position, 136 uint64 position,
137 uint64 size) { 137 uint64 size) {
138 const ResourceRequestInfoImpl* info = 138 const ResourceRequestInfoImpl* info =
139 ResourceRequestInfoImpl::ForRequest(request_); 139 ResourceRequestInfoImpl::ForRequest(request_);
140 // Cancel the request if the renderer is gone unless it's detachable.
140 if (!info->filter()) 141 if (!info->filter())
141 return false; 142 return info->is_detached();
142 return info->filter()->Send( 143 return info->filter()->Send(
143 new ResourceMsg_UploadProgress(request_id, position, size)); 144 new ResourceMsg_UploadProgress(request_id, position, size));
144 } 145 }
145 146
146 bool AsyncResourceHandler::OnRequestRedirected(int request_id, 147 bool AsyncResourceHandler::OnRequestRedirected(int request_id,
147 const GURL& new_url, 148 const GURL& new_url,
148 ResourceResponse* response, 149 ResourceResponse* response,
149 bool* defer) { 150 bool* defer) {
150 const ResourceRequestInfoImpl* info = 151 const ResourceRequestInfoImpl* info =
151 ResourceRequestInfoImpl::ForRequest(request_); 152 ResourceRequestInfoImpl::ForRequest(request_);
153 // Cancel the request if the renderer is gone unless it's detached.
152 if (!info->filter()) 154 if (!info->filter())
153 return false; 155 return info->is_detached();
154 156
155 *defer = did_defer_ = true; 157 *defer = did_defer_ = true;
156 158
157 if (rdh_->delegate()) { 159 if (rdh_->delegate()) {
158 rdh_->delegate()->OnRequestRedirected( 160 rdh_->delegate()->OnRequestRedirected(
159 new_url, request_, info->GetContext(), response); 161 new_url, request_, info->GetContext(), response);
160 } 162 }
161 163
162 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); 164 DevToolsNetLogObserver::PopulateResponseInfo(request_, response);
163 response->head.request_start = request_->creation_time(); 165 response->head.request_start = request_->creation_time();
164 response->head.response_start = TimeTicks::Now(); 166 response->head.response_start = TimeTicks::Now();
165 return info->filter()->Send(new ResourceMsg_ReceivedRedirect( 167 return info->filter()->Send(new ResourceMsg_ReceivedRedirect(
166 request_id, new_url, response->head)); 168 request_id, new_url, response->head));
167 } 169 }
168 170
169 bool AsyncResourceHandler::OnResponseStarted(int request_id, 171 bool AsyncResourceHandler::OnResponseStarted(int request_id,
170 ResourceResponse* response, 172 ResourceResponse* response,
171 bool* defer) { 173 bool* defer) {
172 // For changes to the main frame, inform the renderer of the new URL's 174 // For changes to the main frame, inform the renderer of the new URL's
173 // per-host settings before the request actually commits. This way the 175 // per-host settings before the request actually commits. This way the
174 // renderer will be able to set these precisely at the time the 176 // renderer will be able to set these precisely at the time the
175 // request commits, avoiding the possibility of e.g. zooming the old content 177 // request commits, avoiding the possibility of e.g. zooming the old content
176 // or of having to layout the new content twice. 178 // or of having to layout the new content twice.
177 179
178 const ResourceRequestInfoImpl* info = 180 const ResourceRequestInfoImpl* info =
179 ResourceRequestInfoImpl::ForRequest(request_); 181 ResourceRequestInfoImpl::ForRequest(request_);
182 // Cancel the request if the renderer is gone unless it's detachable.
180 if (!info->filter()) 183 if (!info->filter())
181 return false; 184 return info->is_detached();
182 185
183 if (rdh_->delegate()) { 186 if (rdh_->delegate()) {
184 rdh_->delegate()->OnResponseStarted( 187 rdh_->delegate()->OnResponseStarted(
185 request_, info->GetContext(), response, info->filter()); 188 request_, info->GetContext(), response, info->filter());
186 } 189 }
187 190
188 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); 191 DevToolsNetLogObserver::PopulateResponseInfo(request_, response);
189 192
190 HostZoomMap* host_zoom_map = 193 HostZoomMap* host_zoom_map =
191 GetHostZoomMapForResourceContext(info->GetContext()); 194 GetHostZoomMapForResourceContext(info->GetContext());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 return true; 245 return true;
243 } 246 }
244 247
245 bool AsyncResourceHandler::OnReadCompleted(int request_id, int bytes_read, 248 bool AsyncResourceHandler::OnReadCompleted(int request_id, int bytes_read,
246 bool* defer) { 249 bool* defer) {
247 if (!bytes_read) 250 if (!bytes_read)
248 return true; 251 return true;
249 252
250 const ResourceRequestInfoImpl* info = 253 const ResourceRequestInfoImpl* info =
251 ResourceRequestInfoImpl::ForRequest(request_); 254 ResourceRequestInfoImpl::ForRequest(request_);
252 if (!info->filter()) 255
256 // Don't send any data if the resource is detached from the renderer.
257 if (info->is_detached()) {
258 buffer_->RecycleLeastRecentlyAllocated();
259 return true;
260 }
261
262 // Cancel the request if the renderer is gone.
263 if (!info->filter()) {
264 DCHECK(!info->is_detachable());
253 return false; 265 return false;
266 }
254 267
255 buffer_->ShrinkLastAllocation(bytes_read); 268 buffer_->ShrinkLastAllocation(bytes_read);
256 269
257 UMA_HISTOGRAM_CUSTOM_COUNTS( 270 UMA_HISTOGRAM_CUSTOM_COUNTS(
258 "Net.AsyncResourceHandler_SharedIOBuffer_Used", 271 "Net.AsyncResourceHandler_SharedIOBuffer_Used",
259 bytes_read, 0, kMaxAllocationSize, 100); 272 bytes_read, 0, kMaxAllocationSize, 100);
260 UMA_HISTOGRAM_PERCENTAGE( 273 UMA_HISTOGRAM_PERCENTAGE(
261 "Net.AsyncResourceHandler_SharedIOBuffer_UsedPercentage", 274 "Net.AsyncResourceHandler_SharedIOBuffer_UsedPercentage",
262 CalcUsedPercentage(bytes_read, allocation_size_)); 275 CalcUsedPercentage(bytes_read, allocation_size_));
263 276
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 request_id, bytes_downloaded, encoded_data_length)); 317 request_id, bytes_downloaded, encoded_data_length));
305 } 318 }
306 } 319 }
307 320
308 bool AsyncResourceHandler::OnResponseCompleted( 321 bool AsyncResourceHandler::OnResponseCompleted(
309 int request_id, 322 int request_id,
310 const net::URLRequestStatus& status, 323 const net::URLRequestStatus& status,
311 const std::string& security_info) { 324 const std::string& security_info) {
312 const ResourceRequestInfoImpl* info = 325 const ResourceRequestInfoImpl* info =
313 ResourceRequestInfoImpl::ForRequest(request_); 326 ResourceRequestInfoImpl::ForRequest(request_);
327 // Cancel the request if the renderer is gone unless it's detachable.
314 if (!info->filter()) 328 if (!info->filter())
315 return false; 329 return info->is_detachable();
316 330
317 // If we crash here, figure out what URL the renderer was requesting. 331 // If we crash here, figure out what URL the renderer was requesting.
318 // http://crbug.com/107692 332 // http://crbug.com/107692
319 char url_buf[128]; 333 char url_buf[128];
320 base::strlcpy(url_buf, request_->url().spec().c_str(), arraysize(url_buf)); 334 base::strlcpy(url_buf, request_->url().spec().c_str(), arraysize(url_buf));
321 base::debug::Alias(url_buf); 335 base::debug::Alias(url_buf);
322 336
323 // TODO(gavinp): Remove this CHECK when we figure out the cause of 337 // TODO(gavinp): Remove this CHECK when we figure out the cause of
324 // http://crbug.com/124680 . This check mirrors closely check in 338 // http://crbug.com/124680 . This check mirrors closely check in
325 // WebURLLoaderImpl::OnCompletedRequest that routes this message to a WebCore 339 // WebURLLoaderImpl::OnCompletedRequest that routes this message to a WebCore
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 392 }
379 393
380 void AsyncResourceHandler::ResumeIfDeferred() { 394 void AsyncResourceHandler::ResumeIfDeferred() {
381 if (did_defer_) { 395 if (did_defer_) {
382 did_defer_ = false; 396 did_defer_ = false;
383 controller()->Resume(); 397 controller()->Resume();
384 } 398 }
385 } 399 }
386 400
387 } // namespace content 401 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698