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 <stddef.h> | 9 #include <stddef.h> |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "base/time/time.h" | 32 #include "base/time/time.h" |
33 #include "content/browser/appcache/appcache_interceptor.h" | 33 #include "content/browser/appcache/appcache_interceptor.h" |
34 #include "content/browser/appcache/chrome_appcache_service.h" | 34 #include "content/browser/appcache/chrome_appcache_service.h" |
35 #include "content/browser/bad_message.h" | 35 #include "content/browser/bad_message.h" |
36 #include "content/browser/cert_store_impl.h" | 36 #include "content/browser/cert_store_impl.h" |
37 #include "content/browser/child_process_security_policy_impl.h" | 37 #include "content/browser/child_process_security_policy_impl.h" |
38 #include "content/browser/download/download_resource_handler.h" | 38 #include "content/browser/download/download_resource_handler.h" |
39 #include "content/browser/download/save_file_manager.h" | 39 #include "content/browser/download/save_file_manager.h" |
40 #include "content/browser/download/save_file_resource_handler.h" | 40 #include "content/browser/download/save_file_resource_handler.h" |
41 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 41 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 42 #include "content/browser/frame_host/frame_tree.h" |
42 #include "content/browser/frame_host/navigation_request_info.h" | 43 #include "content/browser/frame_host/navigation_request_info.h" |
43 #include "content/browser/frame_host/navigator.h" | 44 #include "content/browser/frame_host/navigator.h" |
44 #include "content/browser/loader/async_resource_handler.h" | 45 #include "content/browser/loader/async_resource_handler.h" |
45 #include "content/browser/loader/async_revalidation_manager.h" | 46 #include "content/browser/loader/async_revalidation_manager.h" |
46 #include "content/browser/loader/cross_site_resource_handler.h" | 47 #include "content/browser/loader/cross_site_resource_handler.h" |
47 #include "content/browser/loader/detachable_resource_handler.h" | 48 #include "content/browser/loader/detachable_resource_handler.h" |
48 #include "content/browser/loader/mime_type_resource_handler.h" | 49 #include "content/browser/loader/mime_type_resource_handler.h" |
49 #include "content/browser/loader/navigation_resource_handler.h" | 50 #include "content/browser/loader/navigation_resource_handler.h" |
50 #include "content/browser/loader/navigation_resource_throttle.h" | 51 #include "content/browser/loader/navigation_resource_throttle.h" |
51 #include "content/browser/loader/navigation_url_loader_impl_core.h" | 52 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 // slow bucket because a shocking number of aborts happen under 100ms. | 460 // slow bucket because a shocking number of aborts happen under 100ms. |
460 void RecordAbortRapporOnUI(const GURL& url, | 461 void RecordAbortRapporOnUI(const GURL& url, |
461 base::TimeDelta request_loading_time) { | 462 base::TimeDelta request_loading_time) { |
462 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 463 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
463 if (request_loading_time.InMilliseconds() < 100) | 464 if (request_loading_time.InMilliseconds() < 100) |
464 GetContentClient()->browser()->RecordURLMetric("Net.ErrAborted.Fast", url); | 465 GetContentClient()->browser()->RecordURLMetric("Net.ErrAborted.Fast", url); |
465 else | 466 else |
466 GetContentClient()->browser()->RecordURLMetric("Net.ErrAborted.Slow", url); | 467 GetContentClient()->browser()->RecordURLMetric("Net.ErrAborted.Slow", url); |
467 } | 468 } |
468 | 469 |
| 470 // The following functions simplify code paths where the UI thread notifies the |
| 471 // ResourceDispatcherHostImpl of information pertaining to loading behavior of |
| 472 // frame hosts. |
| 473 void NotifyForRouteOnIO( |
| 474 base::Callback<void(ResourceDispatcherHostImpl*, |
| 475 const GlobalFrameRoutingId&)> frame_callback, |
| 476 const GlobalFrameRoutingId& global_routing_id) { |
| 477 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 478 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 479 if (rdh) |
| 480 frame_callback.Run(rdh, global_routing_id); |
| 481 } |
| 482 |
| 483 void NotifyForRouteFromUI( |
| 484 const GlobalFrameRoutingId& global_routing_id, |
| 485 base::Callback<void(ResourceDispatcherHostImpl*, |
| 486 const GlobalFrameRoutingId&)> frame_callback) { |
| 487 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 488 BrowserThread::PostTask( |
| 489 BrowserThread::IO, FROM_HERE, |
| 490 base::Bind(&NotifyForRouteOnIO, frame_callback, global_routing_id)); |
| 491 } |
| 492 |
| 493 void NotifyForRouteSetOnIO( |
| 494 base::Callback<void(ResourceDispatcherHostImpl*, |
| 495 const GlobalFrameRoutingId&)> frame_callback, |
| 496 scoped_ptr<std::set<GlobalFrameRoutingId>> routing_ids) { |
| 497 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 498 for (const auto& routing_id : *routing_ids) |
| 499 NotifyForRouteOnIO(frame_callback, routing_id); |
| 500 } |
| 501 |
| 502 void NotifyForEachFrameFromUI( |
| 503 RenderFrameHost* root_frame_host, |
| 504 base::Callback<void(ResourceDispatcherHostImpl*, |
| 505 const GlobalFrameRoutingId&)> frame_callback) { |
| 506 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 507 FrameTree* frame_tree = static_cast<RenderFrameHostImpl*>(root_frame_host) |
| 508 ->frame_tree_node() |
| 509 ->frame_tree(); |
| 510 DCHECK_EQ(root_frame_host, frame_tree->GetMainFrame()); |
| 511 scoped_ptr<std::set<GlobalFrameRoutingId>> routing_ids( |
| 512 new std::set<GlobalFrameRoutingId>()); |
| 513 for (FrameTreeNode* node : frame_tree->Nodes()) { |
| 514 RenderFrameHostImpl* frame_host = node->current_frame_host(); |
| 515 RenderFrameHostImpl* pending_frame_host = |
| 516 IsBrowserSideNavigationEnabled() |
| 517 ? node->render_manager()->speculative_frame_host() |
| 518 : node->render_manager()->pending_frame_host(); |
| 519 if (frame_host) |
| 520 routing_ids->insert(frame_host->GetGlobalFrameRoutingId()); |
| 521 if (pending_frame_host) |
| 522 routing_ids->insert(pending_frame_host->GetGlobalFrameRoutingId()); |
| 523 } |
| 524 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 525 base::Bind(&NotifyForRouteSetOnIO, frame_callback, |
| 526 base::Passed(std::move(routing_ids)))); |
| 527 } |
| 528 |
469 } // namespace | 529 } // namespace |
470 | 530 |
| 531 LoaderIOThreadNotifier::LoaderIOThreadNotifier(WebContents* web_contents) |
| 532 : WebContentsObserver(web_contents) {} |
| 533 |
| 534 LoaderIOThreadNotifier::~LoaderIOThreadNotifier() {} |
| 535 |
| 536 void LoaderIOThreadNotifier::RenderFrameDeleted( |
| 537 RenderFrameHost* render_frame_host) { |
| 538 NotifyForRouteFromUI( |
| 539 static_cast<RenderFrameHostImpl*>(render_frame_host) |
| 540 ->GetGlobalFrameRoutingId(), |
| 541 base::Bind(&ResourceDispatcherHostImpl::OnRenderFrameDeleted)); |
| 542 } |
| 543 |
471 // static | 544 // static |
472 ResourceDispatcherHost* ResourceDispatcherHost::Get() { | 545 ResourceDispatcherHost* ResourceDispatcherHost::Get() { |
473 return g_resource_dispatcher_host; | 546 return g_resource_dispatcher_host; |
474 } | 547 } |
475 | 548 |
476 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() | 549 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() |
477 : save_file_manager_(new SaveFileManager()), | 550 : save_file_manager_(new SaveFileManager()), |
478 request_id_(-1), | 551 request_id_(-1), |
479 is_shutdown_(false), | 552 is_shutdown_(false), |
480 num_in_flight_requests_(0), | 553 num_in_flight_requests_(0), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 DCHECK(outstanding_requests_stats_map_.empty()); | 600 DCHECK(outstanding_requests_stats_map_.empty()); |
528 DCHECK(g_resource_dispatcher_host); | 601 DCHECK(g_resource_dispatcher_host); |
529 g_resource_dispatcher_host = NULL; | 602 g_resource_dispatcher_host = NULL; |
530 } | 603 } |
531 | 604 |
532 // static | 605 // static |
533 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { | 606 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { |
534 return g_resource_dispatcher_host; | 607 return g_resource_dispatcher_host; |
535 } | 608 } |
536 | 609 |
| 610 // static |
| 611 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( |
| 612 const GlobalFrameRoutingId& global_routing_id) { |
| 613 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 614 NotifyForRouteFromUI( |
| 615 global_routing_id, |
| 616 base::Bind(&ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute)); |
| 617 } |
| 618 |
| 619 // static |
| 620 void ResourceDispatcherHostImpl::BlockRequestsForFrameFromUI( |
| 621 RenderFrameHost* root_frame_host) { |
| 622 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 623 NotifyForEachFrameFromUI( |
| 624 root_frame_host, |
| 625 base::Bind(&ResourceDispatcherHostImpl::BlockRequestsForRoute)); |
| 626 } |
| 627 |
| 628 // static |
| 629 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForFrameFromUI( |
| 630 RenderFrameHost* root_frame_host) { |
| 631 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 632 NotifyForEachFrameFromUI( |
| 633 root_frame_host, |
| 634 base::Bind(&ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute)); |
| 635 } |
| 636 |
| 637 // static |
| 638 void ResourceDispatcherHostImpl::CancelBlockedRequestsForFrameFromUI( |
| 639 RenderFrameHostImpl* root_frame_host) { |
| 640 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 641 NotifyForEachFrameFromUI( |
| 642 root_frame_host, |
| 643 base::Bind(&ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute)); |
| 644 } |
| 645 |
537 void ResourceDispatcherHostImpl::SetDelegate( | 646 void ResourceDispatcherHostImpl::SetDelegate( |
538 ResourceDispatcherHostDelegate* delegate) { | 647 ResourceDispatcherHostDelegate* delegate) { |
539 delegate_ = delegate; | 648 delegate_ = delegate; |
540 } | 649 } |
541 | 650 |
542 void ResourceDispatcherHostImpl::SetAllowCrossOriginAuthPrompt(bool value) { | 651 void ResourceDispatcherHostImpl::SetAllowCrossOriginAuthPrompt(bool value) { |
543 allow_cross_origin_auth_prompt_ = value; | 652 allow_cross_origin_auth_prompt_ = value; |
544 } | 653 } |
545 | 654 |
546 void ResourceDispatcherHostImpl::AddResourceContext(ResourceContext* context) { | 655 void ResourceDispatcherHostImpl::AddResourceContext(ResourceContext* context) { |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 | 1192 |
1084 // Make sure we shutdown the timer now, otherwise by the time our destructor | 1193 // Make sure we shutdown the timer now, otherwise by the time our destructor |
1085 // runs if the timer is still running the Task is deleted twice (once by | 1194 // runs if the timer is still running the Task is deleted twice (once by |
1086 // the MessageLoop and the second time by RepeatingTimer). | 1195 // the MessageLoop and the second time by RepeatingTimer). |
1087 update_load_states_timer_.reset(); | 1196 update_load_states_timer_.reset(); |
1088 | 1197 |
1089 // Clear blocked requests if any left. | 1198 // Clear blocked requests if any left. |
1090 // Note that we have to do this in 2 passes as we cannot call | 1199 // Note that we have to do this in 2 passes as we cannot call |
1091 // CancelBlockedRequestsForRoute while iterating over | 1200 // CancelBlockedRequestsForRoute while iterating over |
1092 // blocked_loaders_map_, as it modifies it. | 1201 // blocked_loaders_map_, as it modifies it. |
1093 std::set<GlobalRoutingID> ids; | 1202 std::set<GlobalFrameRoutingId> ids; |
1094 for (const auto& blocked_loaders : blocked_loaders_map_) { | 1203 for (const auto& blocked_loaders : blocked_loaders_map_) { |
1095 std::pair<std::set<GlobalRoutingID>::iterator, bool> result = | 1204 std::pair<std::set<GlobalFrameRoutingId>::iterator, bool> result = |
1096 ids.insert(blocked_loaders.first); | 1205 ids.insert(blocked_loaders.first); |
1097 // We should not have duplicates. | 1206 // We should not have duplicates. |
1098 DCHECK(result.second); | 1207 DCHECK(result.second); |
1099 } | 1208 } |
1100 for (const auto& routing_id : ids) { | 1209 for (const auto& routing_id : ids) { |
1101 CancelBlockedRequestsForRoute(routing_id.child_id, routing_id.route_id); | 1210 CancelBlockedRequestsForRoute(routing_id); |
1102 } | 1211 } |
1103 | 1212 |
1104 scheduler_.reset(); | 1213 scheduler_.reset(); |
1105 } | 1214 } |
1106 | 1215 |
1107 bool ResourceDispatcherHostImpl::OnMessageReceived( | 1216 bool ResourceDispatcherHostImpl::OnMessageReceived( |
1108 const IPC::Message& message, | 1217 const IPC::Message& message, |
1109 ResourceMessageFilter* filter) { | 1218 ResourceMessageFilter* filter) { |
1110 filter_ = filter; | 1219 filter_ = filter; |
1111 bool handled = true; | 1220 bool handled = true; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 return false; | 1310 return false; |
1202 } | 1311 } |
1203 | 1312 |
1204 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( | 1313 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( |
1205 int child_id, | 1314 int child_id, |
1206 int route_id, | 1315 int route_id, |
1207 int request_id, | 1316 int request_id, |
1208 const ResourceHostMsg_Request& request_data, | 1317 const ResourceHostMsg_Request& request_data, |
1209 LoaderMap::iterator iter) { | 1318 LoaderMap::iterator iter) { |
1210 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); | 1319 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); |
1211 GlobalRoutingID old_routing_id( | 1320 GlobalFrameRoutingId old_routing_id(request_data.transferred_request_child_id, |
1212 request_data.transferred_request_child_id, info->GetRouteID()); | 1321 info->GetRenderFrameID()); |
1213 GlobalRequestID old_request_id(request_data.transferred_request_child_id, | 1322 GlobalRequestID old_request_id(request_data.transferred_request_child_id, |
1214 request_data.transferred_request_request_id); | 1323 request_data.transferred_request_request_id); |
1215 GlobalRoutingID new_routing_id(child_id, route_id); | 1324 GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id); |
1216 GlobalRequestID new_request_id(child_id, request_id); | 1325 GlobalRequestID new_request_id(child_id, request_id); |
1217 | 1326 |
1218 // Clear out data that depends on |info| before updating it. | 1327 // Clear out data that depends on |info| before updating it. |
1219 // We always need to move the memory stats to the new process. In contrast, | 1328 // We always need to move the memory stats to the new process. In contrast, |
1220 // stats.num_requests is only tracked for some requests (those that require | 1329 // stats.num_requests is only tracked for some requests (those that require |
1221 // file descriptors for their shared memory buffer). | 1330 // file descriptors for their shared memory buffer). |
1222 IncrementOutstandingRequestsMemory(-1, *info); | 1331 IncrementOutstandingRequestsMemory(-1, *info); |
1223 bool should_update_count = info->counted_as_in_flight_request(); | 1332 bool should_update_count = info->counted_as_in_flight_request(); |
1224 if (should_update_count) | 1333 if (should_update_count) |
1225 IncrementOutstandingRequestsCount(-1, info); | 1334 IncrementOutstandingRequestsCount(-1, info); |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1780 blink::WebReferrerPolicyDefault, | 1889 blink::WebReferrerPolicyDefault, |
1781 blink::WebPageVisibilityStateVisible, | 1890 blink::WebPageVisibilityStateVisible, |
1782 context, | 1891 context, |
1783 base::WeakPtr<ResourceMessageFilter>(), // filter | 1892 base::WeakPtr<ResourceMessageFilter>(), // filter |
1784 false, // report_raw_headers | 1893 false, // report_raw_headers |
1785 true, // is_async | 1894 true, // is_async |
1786 false, // is_using_lofi | 1895 false, // is_using_lofi |
1787 std::string()); // original_headers | 1896 std::string()); // original_headers |
1788 } | 1897 } |
1789 | 1898 |
| 1899 void ResourceDispatcherHostImpl::OnRenderFrameDeleted( |
| 1900 const GlobalFrameRoutingId& global_routing_id) { |
| 1901 CancelRequestsForRoute(global_routing_id); |
| 1902 } |
| 1903 |
1790 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, | 1904 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, |
1791 int route_id) { | 1905 int route_id) { |
1792 scheduler_->OnClientCreated(child_id, route_id); | 1906 scheduler_->OnClientCreated(child_id, route_id); |
1793 } | 1907 } |
1794 | 1908 |
1795 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted( | 1909 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id, |
1796 int child_id, | 1910 int route_id) { |
1797 int route_id) { | |
1798 scheduler_->OnClientDeleted(child_id, route_id); | 1911 scheduler_->OnClientDeleted(child_id, route_id); |
1799 CancelRequestsForRoute(child_id, route_id); | |
1800 } | 1912 } |
1801 | 1913 |
1802 void ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading(int child_id, | 1914 void ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading(int child_id, |
1803 int route_id, | 1915 int route_id, |
1804 bool is_loading) { | 1916 bool is_loading) { |
1805 scheduler_->OnLoadingStateChanged(child_id, route_id, !is_loading); | 1917 scheduler_->OnLoadingStateChanged(child_id, route_id, !is_loading); |
1806 } | 1918 } |
1807 | 1919 |
1808 // This function is only used for saving feature. | 1920 // This function is only used for saving feature. |
1809 void ResourceDispatcherHostImpl::BeginSaveFile(const GURL& url, | 1921 void ResourceDispatcherHostImpl::BeginSaveFile(const GURL& url, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1875 ResourceLoader* loader = GetLoader(id); | 1987 ResourceLoader* loader = GetLoader(id); |
1876 // The response we were meant to resume could have already been canceled. | 1988 // The response we were meant to resume could have already been canceled. |
1877 if (loader) | 1989 if (loader) |
1878 loader->CompleteTransfer(); | 1990 loader->CompleteTransfer(); |
1879 } | 1991 } |
1880 | 1992 |
1881 // The object died, so cancel and detach all requests associated with it except | 1993 // The object died, so cancel and detach all requests associated with it except |
1882 // for downloads and detachable resources, which belong to the browser process | 1994 // for downloads and detachable resources, which belong to the browser process |
1883 // even if initiated via a renderer. | 1995 // even if initiated via a renderer. |
1884 void ResourceDispatcherHostImpl::CancelRequestsForProcess(int child_id) { | 1996 void ResourceDispatcherHostImpl::CancelRequestsForProcess(int child_id) { |
1885 CancelRequestsForRoute(child_id, -1 /* cancel all */); | 1997 CancelRequestsForRoute( |
| 1998 GlobalFrameRoutingId(child_id, MSG_ROUTING_NONE /* cancel all */)); |
1886 registered_temp_files_.erase(child_id); | 1999 registered_temp_files_.erase(child_id); |
1887 } | 2000 } |
1888 | 2001 |
1889 void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id, | 2002 void ResourceDispatcherHostImpl::CancelRequestsForRoute( |
1890 int route_id) { | 2003 const GlobalFrameRoutingId& global_routing_id) { |
1891 // Since pending_requests_ is a map, we first build up a list of all of the | 2004 // Since pending_requests_ is a map, we first build up a list of all of the |
1892 // matching requests to be cancelled, and then we cancel them. Since there | 2005 // matching requests to be cancelled, and then we cancel them. Since there |
1893 // may be more than one request to cancel, we cannot simply hold onto the map | 2006 // may be more than one request to cancel, we cannot simply hold onto the map |
1894 // iterators found in the first loop. | 2007 // iterators found in the first loop. |
1895 | 2008 |
1896 // Find the global ID of all matching elements. | 2009 // Find the global ID of all matching elements. |
| 2010 int child_id = global_routing_id.child_id; |
| 2011 int route_id = global_routing_id.frame_routing_id; |
| 2012 bool cancel_all_routes = (route_id == MSG_ROUTING_NONE); |
| 2013 |
1897 bool any_requests_transferring = false; | 2014 bool any_requests_transferring = false; |
1898 std::vector<GlobalRequestID> matching_requests; | 2015 std::vector<GlobalRequestID> matching_requests; |
1899 for (const auto& loader : pending_loaders_) { | 2016 for (const auto& loader : pending_loaders_) { |
1900 if (loader.first.child_id != child_id) | 2017 if (loader.first.child_id != child_id) |
1901 continue; | 2018 continue; |
1902 | 2019 |
1903 ResourceRequestInfoImpl* info = loader.second->GetRequestInfo(); | 2020 ResourceRequestInfoImpl* info = loader.second->GetRequestInfo(); |
1904 | 2021 |
1905 GlobalRequestID id(child_id, loader.first.request_id); | 2022 GlobalRequestID id(child_id, loader.first.request_id); |
1906 DCHECK(id == loader.first); | 2023 DCHECK(id == loader.first); |
1907 // Don't cancel navigations that are expected to live beyond this process. | 2024 // Don't cancel navigations that are expected to live beyond this process. |
1908 if (IsTransferredNavigation(id)) | 2025 if (IsTransferredNavigation(id)) |
1909 any_requests_transferring = true; | 2026 any_requests_transferring = true; |
1910 if (info->detachable_handler()) { | 2027 if (info->detachable_handler()) { |
1911 info->detachable_handler()->Detach(); | 2028 info->detachable_handler()->Detach(); |
1912 } else if (!info->IsDownload() && !info->is_stream() && | 2029 } else if (!info->IsDownload() && !info->is_stream() && |
1913 !IsTransferredNavigation(id) && | 2030 !IsTransferredNavigation(id) && |
1914 (route_id == -1 || route_id == info->GetRouteID())) { | 2031 (cancel_all_routes || route_id == info->GetRenderFrameID())) { |
1915 matching_requests.push_back(id); | 2032 matching_requests.push_back(id); |
1916 } | 2033 } |
1917 } | 2034 } |
1918 | 2035 |
1919 // Remove matches. | 2036 // Remove matches. |
1920 for (size_t i = 0; i < matching_requests.size(); ++i) { | 2037 for (size_t i = 0; i < matching_requests.size(); ++i) { |
1921 LoaderMap::iterator iter = pending_loaders_.find(matching_requests[i]); | 2038 LoaderMap::iterator iter = pending_loaders_.find(matching_requests[i]); |
1922 // Although every matching request was in pending_requests_ when we built | 2039 // Although every matching request was in pending_requests_ when we built |
1923 // matching_requests, it is normal for a matching request to be not found | 2040 // matching_requests, it is normal for a matching request to be not found |
1924 // in pending_requests_ after we have removed some matching requests from | 2041 // in pending_requests_ after we have removed some matching requests from |
1925 // pending_requests_. For example, deleting a net::URLRequest that has | 2042 // pending_requests_. For example, deleting a net::URLRequest that has |
1926 // exclusive (write) access to an HTTP cache entry may unblock another | 2043 // exclusive (write) access to an HTTP cache entry may unblock another |
1927 // net::URLRequest that needs exclusive access to the same cache entry, and | 2044 // net::URLRequest that needs exclusive access to the same cache entry, and |
1928 // that net::URLRequest may complete and remove itself from | 2045 // that net::URLRequest may complete and remove itself from |
1929 // pending_requests_. So we need to check that iter is not equal to | 2046 // pending_requests_. So we need to check that iter is not equal to |
1930 // pending_requests_.end(). | 2047 // pending_requests_.end(). |
1931 if (iter != pending_loaders_.end()) | 2048 if (iter != pending_loaders_.end()) |
1932 RemovePendingLoader(iter); | 2049 RemovePendingLoader(iter); |
1933 } | 2050 } |
1934 | 2051 |
1935 // Don't clear the blocked loaders or offline policy maps if any of the | 2052 // Don't clear the blocked loaders or offline policy maps if any of the |
1936 // requests in route_id are being transferred to a new process, since those | 2053 // requests in route_id are being transferred to a new process, since those |
1937 // maps will be updated with the new route_id after the transfer. Otherwise | 2054 // maps will be updated with the new route_id after the transfer. Otherwise |
1938 // we will lose track of this info when the old route goes away, before the | 2055 // we will lose track of this info when the old route goes away, before the |
1939 // new one is created. | 2056 // new one is created. |
1940 if (any_requests_transferring) | 2057 if (any_requests_transferring) |
1941 return; | 2058 return; |
1942 | 2059 |
1943 // Now deal with blocked requests if any. | 2060 // Now deal with blocked requests if any. |
1944 if (route_id != -1) { | 2061 if (!cancel_all_routes) { |
1945 if (blocked_loaders_map_.find(GlobalRoutingID(child_id, route_id)) != | 2062 if (blocked_loaders_map_.find(global_routing_id) != |
1946 blocked_loaders_map_.end()) { | 2063 blocked_loaders_map_.end()) { |
1947 CancelBlockedRequestsForRoute(child_id, route_id); | 2064 CancelBlockedRequestsForRoute(global_routing_id); |
1948 } | 2065 } |
1949 } else { | 2066 } else { |
1950 // We have to do all render views for the process |child_id|. | 2067 // We have to do all render frames for the process |child_id|. |
1951 // Note that we have to do this in 2 passes as we cannot call | 2068 // Note that we have to do this in 2 passes as we cannot call |
1952 // CancelBlockedRequestsForRoute while iterating over | 2069 // CancelBlockedRequestsForRoute while iterating over |
1953 // blocked_loaders_map_, as it modifies it. | 2070 // blocked_loaders_map_, as blocking requests modifies the map. |
1954 std::set<int> route_ids; | 2071 std::set<GlobalFrameRoutingId> routing_ids; |
1955 for (const auto& blocked_loaders : blocked_loaders_map_) { | 2072 for (const auto& blocked_loaders : blocked_loaders_map_) { |
1956 if (blocked_loaders.first.child_id == child_id) | 2073 if (blocked_loaders.first.child_id == child_id) |
1957 route_ids.insert(blocked_loaders.first.route_id); | 2074 routing_ids.insert(blocked_loaders.first); |
1958 } | 2075 } |
1959 for (int route_id : route_ids) { | 2076 for (const GlobalFrameRoutingId& route_id : routing_ids) { |
1960 CancelBlockedRequestsForRoute(child_id, route_id); | 2077 CancelBlockedRequestsForRoute(route_id); |
1961 } | 2078 } |
1962 } | 2079 } |
1963 } | 2080 } |
1964 | 2081 |
1965 // Cancels the request and removes it from the list. | 2082 // Cancels the request and removes it from the list. |
1966 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, | 2083 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, |
1967 int request_id) { | 2084 int request_id) { |
1968 LoaderMap::iterator i = pending_loaders_.find( | 2085 LoaderMap::iterator i = pending_loaders_.find( |
1969 GlobalRequestID(child_id, request_id)); | 2086 GlobalRequestID(child_id, request_id)); |
1970 if (i == pending_loaders_.end()) { | 2087 if (i == pending_loaders_.end()) { |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2297 IncrementOutstandingRequestsMemory(-1, *info); | 2414 IncrementOutstandingRequestsMemory(-1, *info); |
2298 | 2415 |
2299 // A ResourceHandler must not outlive its associated URLRequest. | 2416 // A ResourceHandler must not outlive its associated URLRequest. |
2300 handler.reset(); | 2417 handler.reset(); |
2301 return; | 2418 return; |
2302 } | 2419 } |
2303 | 2420 |
2304 scoped_ptr<ResourceLoader> loader( | 2421 scoped_ptr<ResourceLoader> loader( |
2305 new ResourceLoader(std::move(request), std::move(handler), this)); | 2422 new ResourceLoader(std::move(request), std::move(handler), this)); |
2306 | 2423 |
2307 GlobalRoutingID id(info->GetGlobalRoutingID()); | 2424 GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID()); |
2308 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); | 2425 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); |
2309 if (iter != blocked_loaders_map_.end()) { | 2426 if (iter != blocked_loaders_map_.end()) { |
2310 // The request should be blocked. | 2427 // The request should be blocked. |
2311 iter->second->push_back(std::move(loader)); | 2428 iter->second->push_back(std::move(loader)); |
2312 return; | 2429 return; |
2313 } | 2430 } |
2314 | 2431 |
2315 StartLoading(info, std::move(loader)); | 2432 StartLoading(info, std::move(loader)); |
2316 } | 2433 } |
2317 | 2434 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2421 update_load_states_timer_->Stop(); | 2538 update_load_states_timer_->Stop(); |
2422 return; | 2539 return; |
2423 } | 2540 } |
2424 | 2541 |
2425 BrowserThread::PostTask( | 2542 BrowserThread::PostTask( |
2426 BrowserThread::UI, FROM_HERE, | 2543 BrowserThread::UI, FROM_HERE, |
2427 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, | 2544 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, |
2428 base::Passed(&info_map))); | 2545 base::Passed(&info_map))); |
2429 } | 2546 } |
2430 | 2547 |
2431 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, | 2548 void ResourceDispatcherHostImpl::BlockRequestsForRoute( |
2432 int route_id) { | 2549 const GlobalFrameRoutingId& global_routing_id) { |
2433 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2550 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
2434 GlobalRoutingID key(child_id, route_id); | 2551 DCHECK(blocked_loaders_map_.find(global_routing_id) == |
2435 DCHECK(blocked_loaders_map_.find(key) == blocked_loaders_map_.end()) << | 2552 blocked_loaders_map_.end()) |
2436 "BlockRequestsForRoute called multiple time for the same RVH"; | 2553 << "BlockRequestsForRoute called multiple time for the same RFH"; |
2437 blocked_loaders_map_[key] = make_scoped_ptr(new BlockedLoadersList()); | 2554 blocked_loaders_map_[global_routing_id] = |
| 2555 make_scoped_ptr(new BlockedLoadersList()); |
2438 } | 2556 } |
2439 | 2557 |
2440 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute(int child_id, | 2558 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute( |
2441 int route_id) { | 2559 const GlobalFrameRoutingId& global_routing_id) { |
2442 ProcessBlockedRequestsForRoute(child_id, route_id, false); | 2560 ProcessBlockedRequestsForRoute(global_routing_id, false); |
2443 } | 2561 } |
2444 | 2562 |
2445 void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute(int child_id, | 2563 void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute( |
2446 int route_id) { | 2564 const GlobalFrameRoutingId& global_routing_id) { |
2447 ProcessBlockedRequestsForRoute(child_id, route_id, true); | 2565 ProcessBlockedRequestsForRoute(global_routing_id, true); |
2448 } | 2566 } |
2449 | 2567 |
2450 void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute( | 2568 void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute( |
2451 int child_id, | 2569 const GlobalFrameRoutingId& global_routing_id, |
2452 int route_id, | |
2453 bool cancel_requests) { | 2570 bool cancel_requests) { |
2454 BlockedLoadersMap::iterator iter = blocked_loaders_map_.find( | 2571 BlockedLoadersMap::iterator iter = |
2455 GlobalRoutingID(child_id, route_id)); | 2572 blocked_loaders_map_.find(global_routing_id); |
2456 if (iter == blocked_loaders_map_.end()) { | 2573 if (iter == blocked_loaders_map_.end()) { |
2457 // It's possible to reach here if the renderer crashed while an interstitial | 2574 // It's possible to reach here if the renderer crashed while an interstitial |
2458 // page was showing. | 2575 // page was showing. |
2459 return; | 2576 return; |
2460 } | 2577 } |
2461 | 2578 |
2462 BlockedLoadersList* loaders = iter->second.get(); | 2579 BlockedLoadersList* loaders = iter->second.get(); |
2463 scoped_ptr<BlockedLoadersList> deleter(std::move(iter->second)); | 2580 scoped_ptr<BlockedLoadersList> deleter(std::move(iter->second)); |
2464 | 2581 |
2465 // Removing the vector from the map unblocks any subsequent requests. | 2582 // Removing the vector from the map unblocks any subsequent requests. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2561 load_flags |= net::LOAD_PREFETCH; | 2678 load_flags |= net::LOAD_PREFETCH; |
2562 } | 2679 } |
2563 | 2680 |
2564 if (is_sync_load) | 2681 if (is_sync_load) |
2565 load_flags |= net::LOAD_IGNORE_LIMITS; | 2682 load_flags |= net::LOAD_IGNORE_LIMITS; |
2566 | 2683 |
2567 return load_flags; | 2684 return load_flags; |
2568 } | 2685 } |
2569 | 2686 |
2570 } // namespace content | 2687 } // namespace content |
OLD | NEW |