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