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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.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: Cancellation delay now settable at command line Created 7 years, 2 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" 7 #include "content/browser/loader/resource_dispatcher_host_impl.h"
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 delete loaders; 400 delete loaders;
401 } else { 401 } else {
402 ++i; 402 ++i;
403 } 403 }
404 } 404 }
405 405
406 #ifndef NDEBUG 406 #ifndef NDEBUG
407 for (LoaderList::iterator i = loaders_to_cancel.begin(); 407 for (LoaderList::iterator i = loaders_to_cancel.begin();
408 i != loaders_to_cancel.end(); ++i) { 408 i != loaders_to_cancel.end(); ++i) {
409 // There is no strict requirement that this be the case, but currently 409 // There is no strict requirement that this be the case, but currently
410 // downloads, streams and transferred requests are the only requests that 410 // downloads, streams, prefetches, and transferred requests are the only
411 // aren't cancelled when the associated processes go away. It may be OK for 411 // requests that aren't cancelled when the associated processes go away. It
412 // this invariant to change in the future, but if this assertion fires 412 // may be OK for this invariant to change in the future, but if this
413 // without the invariant changing, then it's indicative of a leak. 413 // assertion fires without the invariant changing, then it's indicative of a
414 // leak.
414 DCHECK((*i)->GetRequestInfo()->is_download() || 415 DCHECK((*i)->GetRequestInfo()->is_download() ||
415 (*i)->GetRequestInfo()->is_stream() || 416 (*i)->GetRequestInfo()->is_stream() ||
417 (*i)->GetRequestInfo()->GetResourceType() ==
418 ResourceType::PREFETCH ||
416 (*i)->is_transferring()); 419 (*i)->is_transferring());
417 } 420 }
418 #endif 421 #endif
419 422
420 loaders_to_cancel.clear(); 423 loaders_to_cancel.clear();
421 424
422 // Validate that no more requests for this context were added. 425 // Validate that no more requests for this context were added.
423 for (LoaderMap::const_iterator i = pending_loaders_.begin(); 426 for (LoaderMap::const_iterator i = pending_loaders_.begin();
424 i != pending_loaders_.end(); ++i) { 427 i != pending_loaders_.end(); ++i) {
425 // http://crbug.com/90971 428 // http://crbug.com/90971
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 // Have the appcache associate its extra info with the request. 1094 // Have the appcache associate its extra info with the request.
1092 appcache::AppCacheInterceptor::SetExtraRequestInfo( 1095 appcache::AppCacheInterceptor::SetExtraRequestInfo(
1093 request, filter_->appcache_service(), child_id, 1096 request, filter_->appcache_service(), child_id,
1094 request_data.appcache_host_id, request_data.resource_type); 1097 request_data.appcache_host_id, request_data.resource_type);
1095 1098
1096 // Construct the IPC resource handler. 1099 // Construct the IPC resource handler.
1097 scoped_ptr<ResourceHandler> handler; 1100 scoped_ptr<ResourceHandler> handler;
1098 if (sync_result) { 1101 if (sync_result) {
1099 handler.reset(new SyncResourceHandler(request, sync_result, this)); 1102 handler.reset(new SyncResourceHandler(request, sync_result, this));
1100 } else { 1103 } else {
1101 handler.reset(new AsyncResourceHandler(request, this)); 1104 AsyncResourceHandler* async_handler =
1105 new AsyncResourceHandler(request, this);
1106 if (request_data.resource_type == ResourceType::PREFETCH) {
1107 // The renderer doesn't need prefetch data notifications and the prefetch
1108 // request might live longer than the renderer, so detach reads.
1109 async_handler->DetachReads();
1110 }
1111 handler.reset(async_handler);
1102 } 1112 }
1103 1113
1104 // The RedirectToFileResourceHandler depends on being next in the chain. 1114 // The RedirectToFileResourceHandler depends on being next in the chain.
1105 if (request_data.download_to_file) { 1115 if (request_data.download_to_file) {
1106 handler.reset( 1116 handler.reset(
1107 new RedirectToFileResourceHandler(handler.Pass(), request, this)); 1117 new RedirectToFileResourceHandler(handler.Pass(), request, this));
1108 } 1118 }
1109 1119
1110 // Install a CrossSiteResourceHandler if this request is coming from a 1120 // Install a CrossSiteResourceHandler if this request is coming from a
1111 // RenderViewHost with a pending cross-site request. We only check this for 1121 // RenderViewHost with a pending cross-site request. We only check this for
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 ResourceLoader* loader = GetLoader(id); 1327 ResourceLoader* loader = GetLoader(id);
1318 if (loader) { 1328 if (loader) {
1319 // The response we were meant to resume could have already been canceled. 1329 // The response we were meant to resume could have already been canceled.
1320 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 1330 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
1321 if (info->cross_site_handler()) 1331 if (info->cross_site_handler())
1322 info->cross_site_handler()->ResumeResponse(); 1332 info->cross_site_handler()->ResumeResponse();
1323 } 1333 }
1324 } 1334 }
1325 1335
1326 // The object died, so cancel and detach all requests associated with it except 1336 // The object died, so cancel and detach all requests associated with it except
1327 // for downloads, which belong to the browser process even if initiated via a 1337 // for downloads and prefetches, which belong to the browser process even if
1328 // renderer. 1338 // initiated via a renderer.
1329 void ResourceDispatcherHostImpl::CancelRequestsForProcess(int child_id) { 1339 void ResourceDispatcherHostImpl::CancelRequestsForProcess(int child_id) {
1330 CancelRequestsForRoute(child_id, -1 /* cancel all */); 1340 CancelRequestsForRoute(child_id, -1 /* cancel all */);
1331 registered_temp_files_.erase(child_id); 1341 registered_temp_files_.erase(child_id);
1332 } 1342 }
1333 1343
1334 void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id, 1344 void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id,
1335 int route_id) { 1345 int route_id) {
1336 // Since pending_requests_ is a map, we first build up a list of all of the 1346 // Since pending_requests_ is a map, we first build up a list of all of the
1337 // matching requests to be cancelled, and then we cancel them. Since there 1347 // matching requests to be cancelled, and then we cancel them. Since there
1338 // may be more than one request to cancel, we cannot simply hold onto the map 1348 // may be more than one request to cancel, we cannot simply hold onto the map
1339 // iterators found in the first loop. 1349 // iterators found in the first loop.
1340 1350
1341 // Find the global ID of all matching elements. 1351 // Find the global ID of all matching elements.
1342 bool any_requests_transferring = false; 1352 bool any_requests_transferring = false;
1343 std::vector<GlobalRequestID> matching_requests; 1353 std::vector<GlobalRequestID> matching_requests;
1344 for (LoaderMap::const_iterator i = pending_loaders_.begin(); 1354 for (LoaderMap::const_iterator i = pending_loaders_.begin();
1345 i != pending_loaders_.end(); ++i) { 1355 i != pending_loaders_.end(); ++i) {
1346 if (i->first.child_id != child_id) 1356 if (i->first.child_id != child_id)
1347 continue; 1357 continue;
1348 1358
1349 ResourceRequestInfoImpl* info = i->second->GetRequestInfo(); 1359 ResourceRequestInfoImpl* info = i->second->GetRequestInfo();
1350 1360
1351 GlobalRequestID id(child_id, i->first.request_id); 1361 GlobalRequestID id(child_id, i->first.request_id);
1352 DCHECK(id == i->first); 1362 DCHECK(id == i->first);
1353
1354 // Don't cancel navigations that are transferring to another process, 1363 // Don't cancel navigations that are transferring to another process,
1355 // since they belong to another process now. 1364 // since they belong to another process now.
1356 if (IsTransferredNavigation(id)) 1365 if (IsTransferredNavigation(id))
1357 any_requests_transferring = true; 1366 any_requests_transferring = true;
1358 if (!info->is_download() && !info->is_stream() && 1367 if (!info->is_download() && !info->is_stream() &&
1368 info->GetResourceType() != ResourceType::PREFETCH &&
1359 !IsTransferredNavigation(id) && 1369 !IsTransferredNavigation(id) &&
1360 (route_id == -1 || route_id == info->GetRouteID())) { 1370 (route_id == -1 || route_id == info->GetRouteID())) {
1361 matching_requests.push_back(id); 1371 matching_requests.push_back(id);
1362 } 1372 }
1363 } 1373 }
1364 1374
1365 // Remove matches. 1375 // Remove matches.
1366 for (size_t i = 0; i < matching_requests.size(); ++i) { 1376 for (size_t i = 0; i < matching_requests.size(); ++i) {
1367 LoaderMap::iterator iter = pending_loaders_.find(matching_requests[i]); 1377 LoaderMap::iterator iter = pending_loaders_.find(matching_requests[i]);
1368 // Although every matching request was in pending_requests_ when we built 1378 // Although every matching request was in pending_requests_ when we built
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) 1931 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS)
1922 && !policy->CanReadRawCookies(child_id)) { 1932 && !policy->CanReadRawCookies(child_id)) {
1923 VLOG(1) << "Denied unauthorized request for raw headers"; 1933 VLOG(1) << "Denied unauthorized request for raw headers";
1924 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; 1934 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS;
1925 } 1935 }
1926 1936
1927 return load_flags; 1937 return load_flags;
1928 } 1938 }
1929 1939
1930 } // namespace content 1940 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698