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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 | 448 |
448 bool IsUsingLoFi(LoFiState lofi_state, | 449 bool IsUsingLoFi(LoFiState lofi_state, |
449 ResourceDispatcherHostDelegate* delegate, | 450 ResourceDispatcherHostDelegate* delegate, |
450 const net::URLRequest& request, | 451 const net::URLRequest& request, |
451 ResourceContext* resource_context) { | 452 ResourceContext* resource_context) { |
452 if (lofi_state == LOFI_UNSPECIFIED && delegate) | 453 if (lofi_state == LOFI_UNSPECIFIED && delegate) |
453 return delegate->ShouldEnableLoFiMode(request, resource_context); | 454 return delegate->ShouldEnableLoFiMode(request, resource_context); |
454 return lofi_state == LOFI_ON; | 455 return lofi_state == LOFI_ON; |
455 } | 456 } |
456 | 457 |
458 // Walk the frame tree and pick up ids for every RenderFrameHost. Note that a | |
459 // single node can have multiple RenderFrameHosts (speculative / pending). | |
460 bool CollectRenderFrameRoutingIds(std::set<GlobalFrameRoutingId>* route_ids, | |
461 FrameTreeNode* tree_node) { | |
Randy Smith (Not in Mondays)
2016/01/20 23:23:19
It looks to me like tree_node is purely an input a
Charlie Harrison
2016/01/21 18:52:55
This'll be obsolete once range-for loops for Frame
| |
462 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
463 RenderFrameHostImpl* frame_host = tree_node->current_frame_host(); | |
464 RenderFrameHostImpl* pending_frame_host = | |
465 IsBrowserSideNavigationEnabled() | |
466 ? tree_node->render_manager()->speculative_frame_host() | |
467 : tree_node->render_manager()->pending_frame_host(); | |
468 if (frame_host) | |
469 route_ids->insert(frame_host->GetGlobalFrameRoutingId()); | |
470 if (pending_frame_host) | |
471 route_ids->insert(pending_frame_host->GetGlobalFrameRoutingId()); | |
472 return true; | |
473 } | |
474 | |
475 void NotifyForRouteOnIO( | |
476 base::Callback<void(ResourceDispatcherHostImpl*, | |
477 const GlobalFrameRoutingId&)> frame_callback, | |
478 const GlobalFrameRoutingId& routing_id) { | |
479 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
480 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | |
481 if (rdh) | |
482 frame_callback.Run(rdh, routing_id); | |
483 } | |
484 | |
485 void NotifyForEachFrameOnIO( | |
486 base::Callback<void(ResourceDispatcherHostImpl*, | |
487 const GlobalFrameRoutingId&)> frame_callback, | |
488 scoped_ptr<std::set<GlobalFrameRoutingId>> routing_ids) { | |
489 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
490 for (const auto& routing_id : *routing_ids) | |
491 NotifyForRouteOnIO(frame_callback, routing_id); | |
492 } | |
493 | |
457 } // namespace | 494 } // namespace |
458 | 495 |
496 LoaderIOThreadNotifier::LoaderIOThreadNotifier( | |
497 WebContents* web_contents) | |
498 : WebContentsObserver(web_contents) {} | |
499 | |
500 LoaderIOThreadNotifier::~LoaderIOThreadNotifier() {} | |
501 | |
502 void LoaderIOThreadNotifier::RenderFrameDeleted( | |
503 RenderFrameHost* render_frame_host) { | |
504 ResourceDispatcherHostImpl::NotifyForRoute( | |
505 static_cast<RenderFrameHostImpl*>(render_frame_host) | |
506 ->GetGlobalFrameRoutingId(), | |
507 base::Bind(&ResourceDispatcherHostImpl::OnRenderFrameDeleted)); | |
508 } | |
509 | |
459 // static | 510 // static |
460 ResourceDispatcherHost* ResourceDispatcherHost::Get() { | 511 ResourceDispatcherHost* ResourceDispatcherHost::Get() { |
461 return g_resource_dispatcher_host; | 512 return g_resource_dispatcher_host; |
462 } | 513 } |
463 | 514 |
464 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() | 515 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() |
465 : save_file_manager_(new SaveFileManager()), | 516 : save_file_manager_(new SaveFileManager()), |
466 request_id_(-1), | 517 request_id_(-1), |
467 is_shutdown_(false), | 518 is_shutdown_(false), |
468 num_in_flight_requests_(0), | 519 num_in_flight_requests_(0), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 DCHECK(outstanding_requests_stats_map_.empty()); | 566 DCHECK(outstanding_requests_stats_map_.empty()); |
516 DCHECK(g_resource_dispatcher_host); | 567 DCHECK(g_resource_dispatcher_host); |
517 g_resource_dispatcher_host = NULL; | 568 g_resource_dispatcher_host = NULL; |
518 } | 569 } |
519 | 570 |
520 // static | 571 // static |
521 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { | 572 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { |
522 return g_resource_dispatcher_host; | 573 return g_resource_dispatcher_host; |
523 } | 574 } |
524 | 575 |
576 // static | |
577 void ResourceDispatcherHostImpl::NotifyForRoute( | |
578 const GlobalFrameRoutingId& routing_id, | |
579 base::Callback<void(ResourceDispatcherHostImpl*, | |
580 const GlobalFrameRoutingId&)> | |
581 frame_callback) { | |
582 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
583 BrowserThread::PostTask( | |
584 BrowserThread::IO, FROM_HERE, | |
585 base::Bind(&NotifyForRouteOnIO, frame_callback, routing_id)); | |
586 } | |
587 | |
588 // static | |
589 void ResourceDispatcherHostImpl::NotifyForEachFrame( | |
590 FrameTree* frame_tree, | |
591 base::Callback<void(ResourceDispatcherHostImpl*, | |
592 const GlobalFrameRoutingId&)> | |
593 frame_callback) { | |
594 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
595 scoped_ptr<std::set<GlobalFrameRoutingId>> routing_ids( | |
596 new std::set<GlobalFrameRoutingId>()); | |
597 frame_tree->ForEach( | |
598 base::Bind(&CollectRenderFrameRoutingIds, routing_ids.get())); | |
599 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
600 base::Bind(&NotifyForEachFrameOnIO, frame_callback, | |
601 base::Passed(std::move(routing_ids)))); | |
602 } | |
603 | |
525 void ResourceDispatcherHostImpl::SetDelegate( | 604 void ResourceDispatcherHostImpl::SetDelegate( |
526 ResourceDispatcherHostDelegate* delegate) { | 605 ResourceDispatcherHostDelegate* delegate) { |
527 delegate_ = delegate; | 606 delegate_ = delegate; |
528 } | 607 } |
529 | 608 |
530 void ResourceDispatcherHostImpl::SetAllowCrossOriginAuthPrompt(bool value) { | 609 void ResourceDispatcherHostImpl::SetAllowCrossOriginAuthPrompt(bool value) { |
531 allow_cross_origin_auth_prompt_ = value; | 610 allow_cross_origin_auth_prompt_ = value; |
532 } | 611 } |
533 | 612 |
534 void ResourceDispatcherHostImpl::AddResourceContext(ResourceContext* context) { | 613 void ResourceDispatcherHostImpl::AddResourceContext(ResourceContext* context) { |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1048 | 1127 |
1049 // Make sure we shutdown the timer now, otherwise by the time our destructor | 1128 // Make sure we shutdown the timer now, otherwise by the time our destructor |
1050 // runs if the timer is still running the Task is deleted twice (once by | 1129 // runs if the timer is still running the Task is deleted twice (once by |
1051 // the MessageLoop and the second time by RepeatingTimer). | 1130 // the MessageLoop and the second time by RepeatingTimer). |
1052 update_load_states_timer_.reset(); | 1131 update_load_states_timer_.reset(); |
1053 | 1132 |
1054 // Clear blocked requests if any left. | 1133 // Clear blocked requests if any left. |
1055 // Note that we have to do this in 2 passes as we cannot call | 1134 // Note that we have to do this in 2 passes as we cannot call |
1056 // CancelBlockedRequestsForRoute while iterating over | 1135 // CancelBlockedRequestsForRoute while iterating over |
1057 // blocked_loaders_map_, as it modifies it. | 1136 // blocked_loaders_map_, as it modifies it. |
1058 std::set<GlobalRoutingID> ids; | 1137 std::set<GlobalFrameRoutingId> ids; |
1059 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); | 1138 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); |
1060 iter != blocked_loaders_map_.end(); ++iter) { | 1139 iter != blocked_loaders_map_.end(); ++iter) { |
1061 std::pair<std::set<GlobalRoutingID>::iterator, bool> result = | 1140 std::pair<std::set<GlobalFrameRoutingId>::iterator, bool> result = |
1062 ids.insert(iter->first); | 1141 ids.insert(iter->first); |
1063 // We should not have duplicates. | 1142 // We should not have duplicates. |
1064 DCHECK(result.second); | 1143 DCHECK(result.second); |
1065 } | 1144 } |
1066 for (std::set<GlobalRoutingID>::const_iterator iter = ids.begin(); | 1145 for (std::set<GlobalFrameRoutingId>::const_iterator iter = ids.begin(); |
1067 iter != ids.end(); ++iter) { | 1146 iter != ids.end(); ++iter) { |
1068 CancelBlockedRequestsForRoute(iter->child_id, iter->route_id); | 1147 CancelBlockedRequestsForRoute(*iter); |
1069 } | 1148 } |
1070 | 1149 |
1071 scheduler_.reset(); | 1150 scheduler_.reset(); |
1072 } | 1151 } |
1073 | 1152 |
1074 bool ResourceDispatcherHostImpl::OnMessageReceived( | 1153 bool ResourceDispatcherHostImpl::OnMessageReceived( |
1075 const IPC::Message& message, | 1154 const IPC::Message& message, |
1076 ResourceMessageFilter* filter) { | 1155 ResourceMessageFilter* filter) { |
1077 filter_ = filter; | 1156 filter_ = filter; |
1078 bool handled = true; | 1157 bool handled = true; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1154 sync_result->routing_id()); | 1233 sync_result->routing_id()); |
1155 } | 1234 } |
1156 | 1235 |
1157 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( | 1236 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( |
1158 int child_id, | 1237 int child_id, |
1159 int route_id, | 1238 int route_id, |
1160 int request_id, | 1239 int request_id, |
1161 const ResourceHostMsg_Request& request_data, | 1240 const ResourceHostMsg_Request& request_data, |
1162 const linked_ptr<ResourceLoader>& loader) { | 1241 const linked_ptr<ResourceLoader>& loader) { |
1163 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 1242 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
1164 GlobalRoutingID old_routing_id( | 1243 GlobalFrameRoutingId old_routing_id(request_data.transferred_request_child_id, |
1165 request_data.transferred_request_child_id, info->GetRouteID()); | 1244 info->GetRenderFrameID()); |
1166 GlobalRequestID old_request_id(request_data.transferred_request_child_id, | 1245 GlobalRequestID old_request_id(request_data.transferred_request_child_id, |
1167 request_data.transferred_request_request_id); | 1246 request_data.transferred_request_request_id); |
1168 GlobalRoutingID new_routing_id(child_id, route_id); | 1247 GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id); |
1169 GlobalRequestID new_request_id(child_id, request_id); | 1248 GlobalRequestID new_request_id(child_id, request_id); |
1170 | 1249 |
1171 // Clear out data that depends on |info| before updating it. | 1250 // Clear out data that depends on |info| before updating it. |
1172 // We always need to move the memory stats to the new process. In contrast, | 1251 // We always need to move the memory stats to the new process. In contrast, |
1173 // stats.num_requests is only tracked for some requests (those that require | 1252 // stats.num_requests is only tracked for some requests (those that require |
1174 // file descriptors for their shared memory buffer). | 1253 // file descriptors for their shared memory buffer). |
1175 IncrementOutstandingRequestsMemory(-1, *info); | 1254 IncrementOutstandingRequestsMemory(-1, *info); |
1176 bool should_update_count = info->counted_as_in_flight_request(); | 1255 bool should_update_count = info->counted_as_in_flight_request(); |
1177 if (should_update_count) | 1256 if (should_update_count) |
1178 IncrementOutstandingRequestsCount(-1, info); | 1257 IncrementOutstandingRequestsCount(-1, info); |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1724 blink::WebReferrerPolicyDefault, | 1803 blink::WebReferrerPolicyDefault, |
1725 blink::WebPageVisibilityStateVisible, | 1804 blink::WebPageVisibilityStateVisible, |
1726 context, | 1805 context, |
1727 base::WeakPtr<ResourceMessageFilter>(), // filter | 1806 base::WeakPtr<ResourceMessageFilter>(), // filter |
1728 false, // report_raw_headers | 1807 false, // report_raw_headers |
1729 true, // is_async | 1808 true, // is_async |
1730 false, // is_using_lofi | 1809 false, // is_using_lofi |
1731 std::string()); // original_headers | 1810 std::string()); // original_headers |
1732 } | 1811 } |
1733 | 1812 |
1813 void ResourceDispatcherHostImpl::OnRenderFrameDeleted( | |
1814 const GlobalFrameRoutingId& routing_id) { | |
1815 CancelRequestsForRoute(routing_id); | |
1816 } | |
1817 | |
1734 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, | 1818 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, |
1735 int route_id, | 1819 int route_id, |
1736 bool is_visible, | 1820 bool is_visible, |
1737 bool is_audible) { | 1821 bool is_audible) { |
1738 scheduler_->OnClientCreated(child_id, route_id, is_visible, is_audible); | 1822 scheduler_->OnClientCreated(child_id, route_id, is_visible, is_audible); |
1739 } | 1823 } |
1740 | 1824 |
1741 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted( | 1825 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id, |
1742 int child_id, | 1826 int route_id) { |
1743 int route_id) { | |
1744 scheduler_->OnClientDeleted(child_id, route_id); | 1827 scheduler_->OnClientDeleted(child_id, route_id); |
Randy Smith (Not in Mondays)
2016/01/20 23:23:19
I thought this was going to be removed; planning t
Charlie Harrison
2016/01/21 18:52:55
Yeah this CL doesn't affect ResourceScheduler at a
| |
1745 CancelRequestsForRoute(child_id, route_id); | |
1746 } | 1828 } |
1747 | 1829 |
1748 void ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading(int child_id, | 1830 void ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading(int child_id, |
1749 int route_id, | 1831 int route_id, |
1750 bool is_loading) { | 1832 bool is_loading) { |
1751 scheduler_->OnLoadingStateChanged(child_id, route_id, !is_loading); | 1833 scheduler_->OnLoadingStateChanged(child_id, route_id, !is_loading); |
1752 } | 1834 } |
1753 | 1835 |
1754 void ResourceDispatcherHostImpl::OnRenderViewHostWasHidden( | 1836 void ResourceDispatcherHostImpl::OnRenderViewHostWasHidden( |
1755 int child_id, | 1837 int child_id, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1844 ResourceLoader* loader = GetLoader(id); | 1926 ResourceLoader* loader = GetLoader(id); |
1845 // The response we were meant to resume could have already been canceled. | 1927 // The response we were meant to resume could have already been canceled. |
1846 if (loader) | 1928 if (loader) |
1847 loader->CompleteTransfer(); | 1929 loader->CompleteTransfer(); |
1848 } | 1930 } |
1849 | 1931 |
1850 // The object died, so cancel and detach all requests associated with it except | 1932 // The object died, so cancel and detach all requests associated with it except |
1851 // for downloads and detachable resources, which belong to the browser process | 1933 // for downloads and detachable resources, which belong to the browser process |
1852 // even if initiated via a renderer. | 1934 // even if initiated via a renderer. |
1853 void ResourceDispatcherHostImpl::CancelRequestsForProcess(int child_id) { | 1935 void ResourceDispatcherHostImpl::CancelRequestsForProcess(int child_id) { |
1854 CancelRequestsForRoute(child_id, -1 /* cancel all */); | 1936 CancelRequestsForRoute( |
1937 GlobalFrameRoutingId(child_id, MSG_ROUTING_NONE /* cancel all */)); | |
1855 registered_temp_files_.erase(child_id); | 1938 registered_temp_files_.erase(child_id); |
1856 } | 1939 } |
1857 | 1940 |
1858 void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id, | 1941 void ResourceDispatcherHostImpl::CancelRequestsForRoute( |
1859 int route_id) { | 1942 const GlobalFrameRoutingId& routing_id) { |
1860 // Since pending_requests_ is a map, we first build up a list of all of the | 1943 // Since pending_requests_ is a map, we first build up a list of all of the |
1861 // matching requests to be cancelled, and then we cancel them. Since there | 1944 // matching requests to be cancelled, and then we cancel them. Since there |
1862 // may be more than one request to cancel, we cannot simply hold onto the map | 1945 // may be more than one request to cancel, we cannot simply hold onto the map |
1863 // iterators found in the first loop. | 1946 // iterators found in the first loop. |
1864 | 1947 |
1865 // Find the global ID of all matching elements. | 1948 // Find the global ID of all matching elements. |
1949 int child_id = routing_id.child_id; | |
1950 int route_id = routing_id.route_id; | |
1951 bool cancel_all_routes = route_id == MSG_ROUTING_NONE; | |
1952 | |
1866 bool any_requests_transferring = false; | 1953 bool any_requests_transferring = false; |
1867 std::vector<GlobalRequestID> matching_requests; | 1954 std::vector<GlobalRequestID> matching_requests; |
1868 for (LoaderMap::const_iterator i = pending_loaders_.begin(); | 1955 for (LoaderMap::const_iterator i = pending_loaders_.begin(); |
1869 i != pending_loaders_.end(); ++i) { | 1956 i != pending_loaders_.end(); ++i) { |
1870 if (i->first.child_id != child_id) | 1957 if (i->first.child_id != child_id) |
1871 continue; | 1958 continue; |
1872 | 1959 |
1873 ResourceRequestInfoImpl* info = i->second->GetRequestInfo(); | 1960 ResourceRequestInfoImpl* info = i->second->GetRequestInfo(); |
1874 | 1961 |
1875 GlobalRequestID id(child_id, i->first.request_id); | 1962 GlobalRequestID id(child_id, i->first.request_id); |
1876 DCHECK(id == i->first); | 1963 DCHECK(id == i->first); |
1877 // Don't cancel navigations that are expected to live beyond this process. | 1964 // Don't cancel navigations that are expected to live beyond this process. |
1878 if (IsTransferredNavigation(id)) | 1965 if (IsTransferredNavigation(id)) |
1879 any_requests_transferring = true; | 1966 any_requests_transferring = true; |
1880 if (info->detachable_handler()) { | 1967 if (info->detachable_handler()) { |
1881 info->detachable_handler()->Detach(); | 1968 info->detachable_handler()->Detach(); |
1882 } else if (!info->IsDownload() && !info->is_stream() && | 1969 } else if (!info->IsDownload() && !info->is_stream() && |
1883 !IsTransferredNavigation(id) && | 1970 !IsTransferredNavigation(id) && |
1884 (route_id == -1 || route_id == info->GetRouteID())) { | 1971 (cancel_all_routes || route_id == info->GetRenderFrameID())) { |
1885 matching_requests.push_back(id); | 1972 matching_requests.push_back(id); |
1886 } | 1973 } |
1887 } | 1974 } |
1888 | 1975 |
1889 // Remove matches. | 1976 // Remove matches. |
1890 for (size_t i = 0; i < matching_requests.size(); ++i) { | 1977 for (size_t i = 0; i < matching_requests.size(); ++i) { |
1891 LoaderMap::iterator iter = pending_loaders_.find(matching_requests[i]); | 1978 LoaderMap::iterator iter = pending_loaders_.find(matching_requests[i]); |
1892 // Although every matching request was in pending_requests_ when we built | 1979 // Although every matching request was in pending_requests_ when we built |
1893 // matching_requests, it is normal for a matching request to be not found | 1980 // matching_requests, it is normal for a matching request to be not found |
1894 // in pending_requests_ after we have removed some matching requests from | 1981 // in pending_requests_ after we have removed some matching requests from |
1895 // pending_requests_. For example, deleting a net::URLRequest that has | 1982 // pending_requests_. For example, deleting a net::URLRequest that has |
1896 // exclusive (write) access to an HTTP cache entry may unblock another | 1983 // exclusive (write) access to an HTTP cache entry may unblock another |
1897 // net::URLRequest that needs exclusive access to the same cache entry, and | 1984 // net::URLRequest that needs exclusive access to the same cache entry, and |
1898 // that net::URLRequest may complete and remove itself from | 1985 // that net::URLRequest may complete and remove itself from |
1899 // pending_requests_. So we need to check that iter is not equal to | 1986 // pending_requests_. So we need to check that iter is not equal to |
1900 // pending_requests_.end(). | 1987 // pending_requests_.end(). |
1901 if (iter != pending_loaders_.end()) | 1988 if (iter != pending_loaders_.end()) |
1902 RemovePendingLoader(iter); | 1989 RemovePendingLoader(iter); |
1903 } | 1990 } |
1904 | 1991 |
1905 // Don't clear the blocked loaders or offline policy maps if any of the | 1992 // Don't clear the blocked loaders or offline policy maps if any of the |
1906 // requests in route_id are being transferred to a new process, since those | 1993 // requests in route_id are being transferred to a new process, since those |
1907 // maps will be updated with the new route_id after the transfer. Otherwise | 1994 // maps will be updated with the new route_id after the transfer. Otherwise |
1908 // we will lose track of this info when the old route goes away, before the | 1995 // we will lose track of this info when the old route goes away, before the |
1909 // new one is created. | 1996 // new one is created. |
1910 if (any_requests_transferring) | 1997 if (any_requests_transferring) |
1911 return; | 1998 return; |
1912 | 1999 |
1913 // Now deal with blocked requests if any. | 2000 // Now deal with blocked requests if any. |
1914 if (route_id != -1) { | 2001 if (!cancel_all_routes) { |
1915 if (blocked_loaders_map_.find(GlobalRoutingID(child_id, route_id)) != | 2002 if (blocked_loaders_map_.find(routing_id) != blocked_loaders_map_.end()) { |
1916 blocked_loaders_map_.end()) { | 2003 CancelBlockedRequestsForRoute(routing_id); |
1917 CancelBlockedRequestsForRoute(child_id, route_id); | |
1918 } | 2004 } |
1919 } else { | 2005 } else { |
1920 // We have to do all render views for the process |child_id|. | 2006 // We have to do all render frames for the process |child_id|. |
1921 // Note that we have to do this in 2 passes as we cannot call | 2007 // Note that we have to do this in 2 passes as we cannot call |
1922 // CancelBlockedRequestsForRoute while iterating over | 2008 // CancelBlockedRequestsForRoute while iterating over |
1923 // blocked_loaders_map_, as it modifies it. | 2009 // blocked_loaders_map_, as blocking requests modifies the map. |
1924 std::set<int> route_ids; | 2010 std::set<GlobalFrameRoutingId> routing_ids; |
1925 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); | 2011 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); |
1926 iter != blocked_loaders_map_.end(); ++iter) { | 2012 iter != blocked_loaders_map_.end(); ++iter) { |
1927 if (iter->first.child_id == child_id) | 2013 if (iter->first.child_id == child_id) |
1928 route_ids.insert(iter->first.route_id); | 2014 routing_ids.insert(iter->first); |
1929 } | 2015 } |
1930 for (std::set<int>::const_iterator iter = route_ids.begin(); | 2016 for (std::set<GlobalFrameRoutingId>::const_iterator iter = |
1931 iter != route_ids.end(); ++iter) { | 2017 routing_ids.begin(); |
1932 CancelBlockedRequestsForRoute(child_id, *iter); | 2018 iter != routing_ids.end(); ++iter) { |
2019 CancelBlockedRequestsForRoute(*iter); | |
1933 } | 2020 } |
1934 } | 2021 } |
1935 } | 2022 } |
1936 | 2023 |
1937 // Cancels the request and removes it from the list. | 2024 // Cancels the request and removes it from the list. |
1938 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, | 2025 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, |
1939 int request_id) { | 2026 int request_id) { |
1940 LoaderMap::iterator i = pending_loaders_.find( | 2027 LoaderMap::iterator i = pending_loaders_.find( |
1941 GlobalRequestID(child_id, request_id)); | 2028 GlobalRequestID(child_id, request_id)); |
1942 if (i == pending_loaders_.end()) { | 2029 if (i == pending_loaders_.end()) { |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2268 IncrementOutstandingRequestsMemory(-1, *info); | 2355 IncrementOutstandingRequestsMemory(-1, *info); |
2269 | 2356 |
2270 // A ResourceHandler must not outlive its associated URLRequest. | 2357 // A ResourceHandler must not outlive its associated URLRequest. |
2271 handler.reset(); | 2358 handler.reset(); |
2272 return; | 2359 return; |
2273 } | 2360 } |
2274 | 2361 |
2275 linked_ptr<ResourceLoader> loader( | 2362 linked_ptr<ResourceLoader> loader( |
2276 new ResourceLoader(std::move(request), std::move(handler), this)); | 2363 new ResourceLoader(std::move(request), std::move(handler), this)); |
2277 | 2364 |
2278 GlobalRoutingID id(info->GetGlobalRoutingID()); | 2365 GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID()); |
2279 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); | 2366 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); |
2280 if (iter != blocked_loaders_map_.end()) { | 2367 if (iter != blocked_loaders_map_.end()) { |
2281 // The request should be blocked. | 2368 // The request should be blocked. |
2282 iter->second->push_back(loader); | 2369 iter->second->push_back(loader); |
2283 return; | 2370 return; |
2284 } | 2371 } |
2285 | 2372 |
2286 StartLoading(info, loader); | 2373 StartLoading(info, loader); |
2287 } | 2374 } |
2288 | 2375 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2390 update_load_states_timer_->Stop(); | 2477 update_load_states_timer_->Stop(); |
2391 return; | 2478 return; |
2392 } | 2479 } |
2393 | 2480 |
2394 BrowserThread::PostTask( | 2481 BrowserThread::PostTask( |
2395 BrowserThread::UI, FROM_HERE, | 2482 BrowserThread::UI, FROM_HERE, |
2396 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, | 2483 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, |
2397 base::Passed(&info_map))); | 2484 base::Passed(&info_map))); |
2398 } | 2485 } |
2399 | 2486 |
2400 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, | 2487 void ResourceDispatcherHostImpl::BlockRequestsForRoute( |
2401 int route_id) { | 2488 const GlobalFrameRoutingId& routing_id) { |
2402 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2489 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
2403 GlobalRoutingID key(child_id, route_id); | 2490 DCHECK(blocked_loaders_map_.find(routing_id) == blocked_loaders_map_.end()) |
2404 DCHECK(blocked_loaders_map_.find(key) == blocked_loaders_map_.end()) << | 2491 << "BlockRequestsForRoute called multiple time for the same RFH"; |
2405 "BlockRequestsForRoute called multiple time for the same RVH"; | 2492 blocked_loaders_map_[routing_id] = new BlockedLoadersList(); |
2406 blocked_loaders_map_[key] = new BlockedLoadersList(); | |
2407 } | 2493 } |
2408 | 2494 |
2409 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute(int child_id, | 2495 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute( |
2410 int route_id) { | 2496 const GlobalFrameRoutingId& routing_id) { |
2411 ProcessBlockedRequestsForRoute(child_id, route_id, false); | 2497 ProcessBlockedRequestsForRoute(routing_id, false); |
2412 } | 2498 } |
2413 | 2499 |
2414 void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute(int child_id, | 2500 void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute( |
2415 int route_id) { | 2501 const GlobalFrameRoutingId& routing_id) { |
2416 ProcessBlockedRequestsForRoute(child_id, route_id, true); | 2502 ProcessBlockedRequestsForRoute(routing_id, true); |
2417 } | 2503 } |
2418 | 2504 |
2419 void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute( | 2505 void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute( |
2420 int child_id, | 2506 const GlobalFrameRoutingId& routing_id, |
2421 int route_id, | |
2422 bool cancel_requests) { | 2507 bool cancel_requests) { |
2423 BlockedLoadersMap::iterator iter = blocked_loaders_map_.find( | 2508 BlockedLoadersMap::iterator iter = blocked_loaders_map_.find(routing_id); |
2424 GlobalRoutingID(child_id, route_id)); | |
2425 if (iter == blocked_loaders_map_.end()) { | 2509 if (iter == blocked_loaders_map_.end()) { |
2426 // It's possible to reach here if the renderer crashed while an interstitial | 2510 // It's possible to reach here if the renderer crashed while an interstitial |
2427 // page was showing. | 2511 // page was showing. |
2428 return; | 2512 return; |
2429 } | 2513 } |
2430 | 2514 |
2431 BlockedLoadersList* loaders = iter->second; | 2515 BlockedLoadersList* loaders = iter->second; |
2432 | 2516 |
2433 // Removing the vector from the map unblocks any subsequent requests. | 2517 // Removing the vector from the map unblocks any subsequent requests. |
2434 blocked_loaders_map_.erase(iter); | 2518 blocked_loaders_map_.erase(iter); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2533 load_flags |= net::LOAD_PREFETCH; | 2617 load_flags |= net::LOAD_PREFETCH; |
2534 } | 2618 } |
2535 | 2619 |
2536 if (is_sync_load) | 2620 if (is_sync_load) |
2537 load_flags |= net::LOAD_IGNORE_LIMITS; | 2621 load_flags |= net::LOAD_IGNORE_LIMITS; |
2538 | 2622 |
2539 return load_flags; | 2623 return load_flags; |
2540 } | 2624 } |
2541 | 2625 |
2542 } // namespace content | 2626 } // namespace content |
OLD | NEW |