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

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: Addressed mmenke's comments 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_detachable();
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 detachable.
152 if (!info->filter()) 154 if (!info->filter())
153 return false; 155 return info->is_detachable();
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_detachable();
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_);
255 // Don't send any data for detachable requests.
James Simonsen 2013/10/26 02:25:00 On face value, this doesn't sound right. It seems
jkarlin2 2013/10/28 19:25:41 Done. There is now a distinct "detached" state an
256 if (info->is_detachable()) {
257 buffer_->RecycleLeastRecentlyAllocated();
258 return true;
259 }
252 if (!info->filter()) 260 if (!info->filter())
253 return false; 261 return false;
254 262
255 buffer_->ShrinkLastAllocation(bytes_read); 263 buffer_->ShrinkLastAllocation(bytes_read);
256 264
257 UMA_HISTOGRAM_CUSTOM_COUNTS( 265 UMA_HISTOGRAM_CUSTOM_COUNTS(
258 "Net.AsyncResourceHandler_SharedIOBuffer_Used", 266 "Net.AsyncResourceHandler_SharedIOBuffer_Used",
259 bytes_read, 0, kMaxAllocationSize, 100); 267 bytes_read, 0, kMaxAllocationSize, 100);
260 UMA_HISTOGRAM_PERCENTAGE( 268 UMA_HISTOGRAM_PERCENTAGE(
261 "Net.AsyncResourceHandler_SharedIOBuffer_UsedPercentage", 269 "Net.AsyncResourceHandler_SharedIOBuffer_UsedPercentage",
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 request_id, bytes_downloaded, encoded_data_length)); 312 request_id, bytes_downloaded, encoded_data_length));
305 } 313 }
306 } 314 }
307 315
308 bool AsyncResourceHandler::OnResponseCompleted( 316 bool AsyncResourceHandler::OnResponseCompleted(
309 int request_id, 317 int request_id,
310 const net::URLRequestStatus& status, 318 const net::URLRequestStatus& status,
311 const std::string& security_info) { 319 const std::string& security_info) {
312 const ResourceRequestInfoImpl* info = 320 const ResourceRequestInfoImpl* info =
313 ResourceRequestInfoImpl::ForRequest(request_); 321 ResourceRequestInfoImpl::ForRequest(request_);
322 // Cancel the request if the renderer is gone unless it's detachable.
314 if (!info->filter()) 323 if (!info->filter())
315 return false; 324 return info->is_detachable();
316 325
317 // If we crash here, figure out what URL the renderer was requesting. 326 // If we crash here, figure out what URL the renderer was requesting.
318 // http://crbug.com/107692 327 // http://crbug.com/107692
319 char url_buf[128]; 328 char url_buf[128];
320 base::strlcpy(url_buf, request_->url().spec().c_str(), arraysize(url_buf)); 329 base::strlcpy(url_buf, request_->url().spec().c_str(), arraysize(url_buf));
321 base::debug::Alias(url_buf); 330 base::debug::Alias(url_buf);
322 331
323 // TODO(gavinp): Remove this CHECK when we figure out the cause of 332 // TODO(gavinp): Remove this CHECK when we figure out the cause of
324 // http://crbug.com/124680 . This check mirrors closely check in 333 // http://crbug.com/124680 . This check mirrors closely check in
325 // WebURLLoaderImpl::OnCompletedRequest that routes this message to a WebCore 334 // WebURLLoaderImpl::OnCompletedRequest that routes this message to a WebCore
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 387 }
379 388
380 void AsyncResourceHandler::ResumeIfDeferred() { 389 void AsyncResourceHandler::ResumeIfDeferred() {
381 if (did_defer_) { 390 if (did_defer_) {
382 did_defer_ = false; 391 did_defer_ = false;
383 controller()->Resume(); 392 controller()->Resume();
384 } 393 }
385 } 394 }
386 395
387 } // namespace content 396 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698