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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 1542743002: [RDHI] Refactored blocked_loaders_map_ to key by render frame route id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace FrameTree::ForEach with a for loop Created 4 years, 11 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 <stddef.h> 9 #include <stddef.h>
10 #include <algorithm> 10 #include <algorithm>
(...skipping 21 matching lines...) Expand all
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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // slow bucket because a shocking number of aborts happen under 100ms. 459 // slow bucket because a shocking number of aborts happen under 100ms.
459 void RecordAbortRapporOnUI(const GURL& url, 460 void RecordAbortRapporOnUI(const GURL& url,
460 base::TimeDelta request_loading_time) { 461 base::TimeDelta request_loading_time) {
461 DCHECK_CURRENTLY_ON(BrowserThread::UI); 462 DCHECK_CURRENTLY_ON(BrowserThread::UI);
462 if (request_loading_time.InMilliseconds() < 100) 463 if (request_loading_time.InMilliseconds() < 100)
463 GetContentClient()->browser()->RecordURLMetric("Net.ErrAborted.Fast", url); 464 GetContentClient()->browser()->RecordURLMetric("Net.ErrAborted.Fast", url);
464 else 465 else
465 GetContentClient()->browser()->RecordURLMetric("Net.ErrAborted.Slow", url); 466 GetContentClient()->browser()->RecordURLMetric("Net.ErrAborted.Slow", url);
466 } 467 }
467 468
469 // Walk the frame tree and pick up ids for every RenderFrameHost. Note that a
470 // single node can have multiple RenderFrameHosts (speculative / pending).
471 void NotifyForRouteOnIO(
472 base::Callback<void(ResourceDispatcherHostImpl*,
473 const GlobalFrameRoutingId&)> frame_callback,
474 const GlobalFrameRoutingId& routing_id) {
475 DCHECK_CURRENTLY_ON(BrowserThread::IO);
nasko 2016/01/20 22:22:09 You can't walk the frame tree on the IO thread. It
Charlie Harrison 2016/01/21 18:52:55 Ah yes, this is a dead comment. Removing.
Charlie Harrison 2016/01/21 18:52:55 You're right, the comment is obsolete. Sorry about
476 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
477 if (rdh)
478 frame_callback.Run(rdh, routing_id);
479 }
480
481 void NotifyForEachFrameOnIO(
482 base::Callback<void(ResourceDispatcherHostImpl*,
483 const GlobalFrameRoutingId&)> frame_callback,
484 scoped_ptr<std::set<GlobalFrameRoutingId>> routing_ids) {
485 DCHECK_CURRENTLY_ON(BrowserThread::IO);
486 for (const auto& routing_id : *routing_ids)
487 NotifyForRouteOnIO(frame_callback, routing_id);
488 }
489
468 } // namespace 490 } // namespace
469 491
492 LoaderIOThreadNotifier::LoaderIOThreadNotifier(
493 WebContents* web_contents)
494 : WebContentsObserver(web_contents) {}
495
496 LoaderIOThreadNotifier::~LoaderIOThreadNotifier() {}
497
498 void LoaderIOThreadNotifier::RenderFrameDeleted(
499 RenderFrameHost* render_frame_host) {
500 ResourceDispatcherHostImpl::NotifyForRoute(
501 static_cast<RenderFrameHostImpl*>(render_frame_host)
502 ->GetGlobalFrameRoutingId(),
503 base::Bind(&ResourceDispatcherHostImpl::OnRenderFrameDeleted));
504 }
505
470 // static 506 // static
471 ResourceDispatcherHost* ResourceDispatcherHost::Get() { 507 ResourceDispatcherHost* ResourceDispatcherHost::Get() {
472 return g_resource_dispatcher_host; 508 return g_resource_dispatcher_host;
473 } 509 }
474 510
475 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() 511 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl()
476 : save_file_manager_(new SaveFileManager()), 512 : save_file_manager_(new SaveFileManager()),
477 request_id_(-1), 513 request_id_(-1),
478 is_shutdown_(false), 514 is_shutdown_(false),
479 num_in_flight_requests_(0), 515 num_in_flight_requests_(0),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 DCHECK(outstanding_requests_stats_map_.empty()); 562 DCHECK(outstanding_requests_stats_map_.empty());
527 DCHECK(g_resource_dispatcher_host); 563 DCHECK(g_resource_dispatcher_host);
528 g_resource_dispatcher_host = NULL; 564 g_resource_dispatcher_host = NULL;
529 } 565 }
530 566
531 // static 567 // static
532 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { 568 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() {
533 return g_resource_dispatcher_host; 569 return g_resource_dispatcher_host;
534 } 570 }
535 571
572 // static
573 void ResourceDispatcherHostImpl::NotifyForRoute(
574 const GlobalFrameRoutingId& routing_id,
575 base::Callback<void(ResourceDispatcherHostImpl*,
576 const GlobalFrameRoutingId&)>
577 frame_callback) {
578 DCHECK_CURRENTLY_ON(BrowserThread::UI);
579 BrowserThread::PostTask(
580 BrowserThread::IO, FROM_HERE,
581 base::Bind(&NotifyForRouteOnIO, frame_callback, routing_id));
582 }
583
584 // static
585 void ResourceDispatcherHostImpl::NotifyForEachFrame(
586 FrameTree* frame_tree,
587 base::Callback<void(ResourceDispatcherHostImpl*,
588 const GlobalFrameRoutingId&)> frame_callback) {
589 DCHECK_CURRENTLY_ON(BrowserThread::UI);
590 scoped_ptr<std::set<GlobalFrameRoutingId>> routing_ids(
591 new std::set<GlobalFrameRoutingId>());
592 for (FrameTreeNode* node : frame_tree->Nodes()) {
593 RenderFrameHostImpl* frame_host = node->current_frame_host();
594 RenderFrameHostImpl* pending_frame_host =
595 IsBrowserSideNavigationEnabled()
596 ? node->render_manager()->speculative_frame_host()
597 : node->render_manager()->pending_frame_host();
598 if (frame_host)
599 routing_ids->insert(frame_host->GetGlobalFrameRoutingId());
600 if (pending_frame_host)
601 routing_ids->insert(pending_frame_host->GetGlobalFrameRoutingId());
602 }
603 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
604 base::Bind(&NotifyForEachFrameOnIO, frame_callback,
605 base::Passed(std::move(routing_ids))));
606 }
607
536 void ResourceDispatcherHostImpl::SetDelegate( 608 void ResourceDispatcherHostImpl::SetDelegate(
537 ResourceDispatcherHostDelegate* delegate) { 609 ResourceDispatcherHostDelegate* delegate) {
538 delegate_ = delegate; 610 delegate_ = delegate;
539 } 611 }
540 612
541 void ResourceDispatcherHostImpl::SetAllowCrossOriginAuthPrompt(bool value) { 613 void ResourceDispatcherHostImpl::SetAllowCrossOriginAuthPrompt(bool value) {
542 allow_cross_origin_auth_prompt_ = value; 614 allow_cross_origin_auth_prompt_ = value;
543 } 615 }
544 616
545 void ResourceDispatcherHostImpl::AddResourceContext(ResourceContext* context) { 617 void ResourceDispatcherHostImpl::AddResourceContext(ResourceContext* context) {
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 1153
1082 // Make sure we shutdown the timer now, otherwise by the time our destructor 1154 // Make sure we shutdown the timer now, otherwise by the time our destructor
1083 // runs if the timer is still running the Task is deleted twice (once by 1155 // runs if the timer is still running the Task is deleted twice (once by
1084 // the MessageLoop and the second time by RepeatingTimer). 1156 // the MessageLoop and the second time by RepeatingTimer).
1085 update_load_states_timer_.reset(); 1157 update_load_states_timer_.reset();
1086 1158
1087 // Clear blocked requests if any left. 1159 // Clear blocked requests if any left.
1088 // Note that we have to do this in 2 passes as we cannot call 1160 // Note that we have to do this in 2 passes as we cannot call
1089 // CancelBlockedRequestsForRoute while iterating over 1161 // CancelBlockedRequestsForRoute while iterating over
1090 // blocked_loaders_map_, as it modifies it. 1162 // blocked_loaders_map_, as it modifies it.
1091 std::set<GlobalRoutingID> ids; 1163 std::set<GlobalFrameRoutingId> ids;
1092 for (const auto& blocked_loaders : blocked_loaders_map_) { 1164 for (const auto& blocked_loaders : blocked_loaders_map_) {
1093 std::pair<std::set<GlobalRoutingID>::iterator, bool> result = 1165 std::pair<std::set<GlobalFrameRoutingId>::iterator, bool> result =
1094 ids.insert(blocked_loaders.first); 1166 ids.insert(blocked_loaders.first);
1095 // We should not have duplicates. 1167 // We should not have duplicates.
1096 DCHECK(result.second); 1168 DCHECK(result.second);
1097 } 1169 }
1098 for (const auto& routing_id : ids) { 1170 for (const auto& routing_id : ids) {
1099 CancelBlockedRequestsForRoute(routing_id.child_id, routing_id.route_id); 1171 CancelBlockedRequestsForRoute(routing_id);
1100 } 1172 }
1101 1173
1102 scheduler_.reset(); 1174 scheduler_.reset();
1103 } 1175 }
1104 1176
1105 bool ResourceDispatcherHostImpl::OnMessageReceived( 1177 bool ResourceDispatcherHostImpl::OnMessageReceived(
1106 const IPC::Message& message, 1178 const IPC::Message& message,
1107 ResourceMessageFilter* filter) { 1179 ResourceMessageFilter* filter) {
1108 filter_ = filter; 1180 filter_ = filter;
1109 bool handled = true; 1181 bool handled = true;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 sync_result->routing_id()); 1257 sync_result->routing_id());
1186 } 1258 }
1187 1259
1188 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( 1260 void ResourceDispatcherHostImpl::UpdateRequestForTransfer(
1189 int child_id, 1261 int child_id,
1190 int route_id, 1262 int route_id,
1191 int request_id, 1263 int request_id,
1192 const ResourceHostMsg_Request& request_data, 1264 const ResourceHostMsg_Request& request_data,
1193 LoaderMap::iterator iter) { 1265 LoaderMap::iterator iter) {
1194 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); 1266 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo();
1195 GlobalRoutingID old_routing_id( 1267 GlobalFrameRoutingId old_routing_id(
1196 request_data.transferred_request_child_id, info->GetRouteID()); 1268 request_data.transferred_request_child_id, info->GetRenderFrameID());
1197 GlobalRequestID old_request_id(request_data.transferred_request_child_id, 1269 GlobalRequestID old_request_id(request_data.transferred_request_child_id,
1198 request_data.transferred_request_request_id); 1270 request_data.transferred_request_request_id);
1199 GlobalRoutingID new_routing_id(child_id, route_id); 1271 GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id);
1200 GlobalRequestID new_request_id(child_id, request_id); 1272 GlobalRequestID new_request_id(child_id, request_id);
1201 1273
1202 // Clear out data that depends on |info| before updating it. 1274 // Clear out data that depends on |info| before updating it.
1203 // We always need to move the memory stats to the new process. In contrast, 1275 // We always need to move the memory stats to the new process. In contrast,
1204 // stats.num_requests is only tracked for some requests (those that require 1276 // stats.num_requests is only tracked for some requests (those that require
1205 // file descriptors for their shared memory buffer). 1277 // file descriptors for their shared memory buffer).
1206 IncrementOutstandingRequestsMemory(-1, *info); 1278 IncrementOutstandingRequestsMemory(-1, *info);
1207 bool should_update_count = info->counted_as_in_flight_request(); 1279 bool should_update_count = info->counted_as_in_flight_request();
1208 if (should_update_count) 1280 if (should_update_count)
1209 IncrementOutstandingRequestsCount(-1, info); 1281 IncrementOutstandingRequestsCount(-1, info);
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 blink::WebReferrerPolicyDefault, 1832 blink::WebReferrerPolicyDefault,
1761 blink::WebPageVisibilityStateVisible, 1833 blink::WebPageVisibilityStateVisible,
1762 context, 1834 context,
1763 base::WeakPtr<ResourceMessageFilter>(), // filter 1835 base::WeakPtr<ResourceMessageFilter>(), // filter
1764 false, // report_raw_headers 1836 false, // report_raw_headers
1765 true, // is_async 1837 true, // is_async
1766 false, // is_using_lofi 1838 false, // is_using_lofi
1767 std::string()); // original_headers 1839 std::string()); // original_headers
1768 } 1840 }
1769 1841
1842 void ResourceDispatcherHostImpl::OnRenderFrameDeleted(
1843 const GlobalFrameRoutingId& routing_id) {
1844 CancelRequestsForRoute(routing_id);
1845 }
1846
1770 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, 1847 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id,
1771 int route_id, 1848 int route_id,
1772 bool is_visible, 1849 bool is_visible,
1773 bool is_audible) { 1850 bool is_audible) {
1774 scheduler_->OnClientCreated(child_id, route_id, is_visible, is_audible); 1851 scheduler_->OnClientCreated(child_id, route_id, is_visible, is_audible);
1775 } 1852 }
1776 1853
1777 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted( 1854 void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id,
nasko 2016/01/20 22:22:09 Hmm, this doesn't seem style guide compatible. Did
Charlie Harrison 2016/01/21 18:52:55 Yeah it did (or at least, it didn't change this).
1778 int child_id, 1855 int route_id) {
1779 int route_id) {
1780 scheduler_->OnClientDeleted(child_id, route_id); 1856 scheduler_->OnClientDeleted(child_id, route_id);
1781 CancelRequestsForRoute(child_id, route_id);
1782 } 1857 }
1783 1858
1784 void ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading(int child_id, 1859 void ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading(int child_id,
1785 int route_id, 1860 int route_id,
1786 bool is_loading) { 1861 bool is_loading) {
1787 scheduler_->OnLoadingStateChanged(child_id, route_id, !is_loading); 1862 scheduler_->OnLoadingStateChanged(child_id, route_id, !is_loading);
1788 } 1863 }
1789 1864
1790 void ResourceDispatcherHostImpl::OnRenderViewHostWasHidden( 1865 void ResourceDispatcherHostImpl::OnRenderViewHostWasHidden(
1791 int child_id, 1866 int child_id,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 ResourceLoader* loader = GetLoader(id); 1955 ResourceLoader* loader = GetLoader(id);
1881 // The response we were meant to resume could have already been canceled. 1956 // The response we were meant to resume could have already been canceled.
1882 if (loader) 1957 if (loader)
1883 loader->CompleteTransfer(); 1958 loader->CompleteTransfer();
1884 } 1959 }
1885 1960
1886 // The object died, so cancel and detach all requests associated with it except 1961 // The object died, so cancel and detach all requests associated with it except
1887 // for downloads and detachable resources, which belong to the browser process 1962 // for downloads and detachable resources, which belong to the browser process
1888 // even if initiated via a renderer. 1963 // even if initiated via a renderer.
1889 void ResourceDispatcherHostImpl::CancelRequestsForProcess(int child_id) { 1964 void ResourceDispatcherHostImpl::CancelRequestsForProcess(int child_id) {
1890 CancelRequestsForRoute(child_id, -1 /* cancel all */); 1965 CancelRequestsForRoute(
1966 GlobalFrameRoutingId(child_id, MSG_ROUTING_NONE /* cancel all */));
1891 registered_temp_files_.erase(child_id); 1967 registered_temp_files_.erase(child_id);
1892 } 1968 }
1893 1969
1894 void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id, 1970 void ResourceDispatcherHostImpl::CancelRequestsForRoute(
1895 int route_id) { 1971 const GlobalFrameRoutingId& routing_id) {
1896 // Since pending_requests_ is a map, we first build up a list of all of the 1972 // Since pending_requests_ is a map, we first build up a list of all of the
1897 // matching requests to be cancelled, and then we cancel them. Since there 1973 // matching requests to be cancelled, and then we cancel them. Since there
1898 // may be more than one request to cancel, we cannot simply hold onto the map 1974 // may be more than one request to cancel, we cannot simply hold onto the map
1899 // iterators found in the first loop. 1975 // iterators found in the first loop.
1900 1976
1901 // Find the global ID of all matching elements. 1977 // Find the global ID of all matching elements.
1978 int child_id = routing_id.child_id;
1979 int route_id = routing_id.route_id;
1980 bool cancel_all_routes = route_id == MSG_ROUTING_NONE;
nasko 2016/01/20 22:22:09 (route_id == MSG_ROUTING_NONE) < a bit more readab
Charlie Harrison 2016/01/21 18:52:55 Done.
Charlie Harrison 2016/01/21 18:52:55 Done.
1981
1902 bool any_requests_transferring = false; 1982 bool any_requests_transferring = false;
1903 std::vector<GlobalRequestID> matching_requests; 1983 std::vector<GlobalRequestID> matching_requests;
1904 for (const auto& loader : pending_loaders_) { 1984 for (const auto& loader : pending_loaders_) {
1905 if (loader.first.child_id != child_id) 1985 if (loader.first.child_id != child_id)
1906 continue; 1986 continue;
1907 1987
1908 ResourceRequestInfoImpl* info = loader.second->GetRequestInfo(); 1988 ResourceRequestInfoImpl* info = loader.second->GetRequestInfo();
1909 1989
1910 GlobalRequestID id(child_id, loader.first.request_id); 1990 GlobalRequestID id(child_id, loader.first.request_id);
1911 DCHECK(id == loader.first); 1991 DCHECK(id == loader.first);
1912 // Don't cancel navigations that are expected to live beyond this process. 1992 // Don't cancel navigations that are expected to live beyond this process.
1913 if (IsTransferredNavigation(id)) 1993 if (IsTransferredNavigation(id))
1914 any_requests_transferring = true; 1994 any_requests_transferring = true;
1915 if (info->detachable_handler()) { 1995 if (info->detachable_handler()) {
1916 info->detachable_handler()->Detach(); 1996 info->detachable_handler()->Detach();
1917 } else if (!info->IsDownload() && !info->is_stream() && 1997 } else if (!info->IsDownload() && !info->is_stream() &&
1918 !IsTransferredNavigation(id) && 1998 !IsTransferredNavigation(id) &&
1919 (route_id == -1 || route_id == info->GetRouteID())) { 1999 (cancel_all_routes || route_id == info->GetRenderFrameID())) {
1920 matching_requests.push_back(id); 2000 matching_requests.push_back(id);
1921 } 2001 }
1922 } 2002 }
1923 2003
1924 // Remove matches. 2004 // Remove matches.
1925 for (size_t i = 0; i < matching_requests.size(); ++i) { 2005 for (size_t i = 0; i < matching_requests.size(); ++i) {
1926 LoaderMap::iterator iter = pending_loaders_.find(matching_requests[i]); 2006 LoaderMap::iterator iter = pending_loaders_.find(matching_requests[i]);
1927 // Although every matching request was in pending_requests_ when we built 2007 // Although every matching request was in pending_requests_ when we built
1928 // matching_requests, it is normal for a matching request to be not found 2008 // matching_requests, it is normal for a matching request to be not found
1929 // in pending_requests_ after we have removed some matching requests from 2009 // in pending_requests_ after we have removed some matching requests from
1930 // pending_requests_. For example, deleting a net::URLRequest that has 2010 // pending_requests_. For example, deleting a net::URLRequest that has
1931 // exclusive (write) access to an HTTP cache entry may unblock another 2011 // exclusive (write) access to an HTTP cache entry may unblock another
1932 // net::URLRequest that needs exclusive access to the same cache entry, and 2012 // net::URLRequest that needs exclusive access to the same cache entry, and
1933 // that net::URLRequest may complete and remove itself from 2013 // that net::URLRequest may complete and remove itself from
1934 // pending_requests_. So we need to check that iter is not equal to 2014 // pending_requests_. So we need to check that iter is not equal to
1935 // pending_requests_.end(). 2015 // pending_requests_.end().
1936 if (iter != pending_loaders_.end()) 2016 if (iter != pending_loaders_.end())
1937 RemovePendingLoader(iter); 2017 RemovePendingLoader(iter);
1938 } 2018 }
1939 2019
1940 // Don't clear the blocked loaders or offline policy maps if any of the 2020 // Don't clear the blocked loaders or offline policy maps if any of the
1941 // requests in route_id are being transferred to a new process, since those 2021 // requests in route_id are being transferred to a new process, since those
1942 // maps will be updated with the new route_id after the transfer. Otherwise 2022 // maps will be updated with the new route_id after the transfer. Otherwise
1943 // we will lose track of this info when the old route goes away, before the 2023 // we will lose track of this info when the old route goes away, before the
1944 // new one is created. 2024 // new one is created.
1945 if (any_requests_transferring) 2025 if (any_requests_transferring)
1946 return; 2026 return;
1947 2027
1948 // Now deal with blocked requests if any. 2028 // Now deal with blocked requests if any.
1949 if (route_id != -1) { 2029 if (!cancel_all_routes) {
1950 if (blocked_loaders_map_.find(GlobalRoutingID(child_id, route_id)) != 2030 if (blocked_loaders_map_.find(routing_id) != blocked_loaders_map_.end()) {
1951 blocked_loaders_map_.end()) { 2031 CancelBlockedRequestsForRoute(routing_id);
1952 CancelBlockedRequestsForRoute(child_id, route_id);
1953 } 2032 }
1954 } else { 2033 } else {
1955 // We have to do all render views for the process |child_id|. 2034 // We have to do all render frames for the process |child_id|.
1956 // Note that we have to do this in 2 passes as we cannot call 2035 // Note that we have to do this in 2 passes as we cannot call
1957 // CancelBlockedRequestsForRoute while iterating over 2036 // CancelBlockedRequestsForRoute while iterating over
1958 // blocked_loaders_map_, as it modifies it. 2037 // blocked_loaders_map_, as blocking requests modifies the map.
1959 std::set<int> route_ids; 2038 std::set<GlobalFrameRoutingId> routing_ids;
1960 for (const auto& blocked_loaders : blocked_loaders_map_) { 2039 for (const auto& blocked_loaders : blocked_loaders_map_) {
1961 if (blocked_loaders.first.child_id == child_id) 2040 if (blocked_loaders.first.child_id == child_id)
1962 route_ids.insert(blocked_loaders.first.route_id); 2041 routing_ids.insert(blocked_loaders.first);
1963 } 2042 }
1964 for (int route_id : route_ids) { 2043 for (const GlobalFrameRoutingId& route_id : routing_ids) {
1965 CancelBlockedRequestsForRoute(child_id, route_id); 2044 CancelBlockedRequestsForRoute(route_id);
1966 } 2045 }
1967 } 2046 }
1968 } 2047 }
1969 2048
1970 // Cancels the request and removes it from the list. 2049 // Cancels the request and removes it from the list.
1971 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, 2050 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id,
1972 int request_id) { 2051 int request_id) {
1973 LoaderMap::iterator i = pending_loaders_.find( 2052 LoaderMap::iterator i = pending_loaders_.find(
1974 GlobalRequestID(child_id, request_id)); 2053 GlobalRequestID(child_id, request_id));
1975 if (i == pending_loaders_.end()) { 2054 if (i == pending_loaders_.end()) {
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
2302 IncrementOutstandingRequestsMemory(-1, *info); 2381 IncrementOutstandingRequestsMemory(-1, *info);
2303 2382
2304 // A ResourceHandler must not outlive its associated URLRequest. 2383 // A ResourceHandler must not outlive its associated URLRequest.
2305 handler.reset(); 2384 handler.reset();
2306 return; 2385 return;
2307 } 2386 }
2308 2387
2309 scoped_ptr<ResourceLoader> loader( 2388 scoped_ptr<ResourceLoader> loader(
2310 new ResourceLoader(std::move(request), std::move(handler), this)); 2389 new ResourceLoader(std::move(request), std::move(handler), this));
2311 2390
2312 GlobalRoutingID id(info->GetGlobalRoutingID()); 2391 GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID());
2313 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); 2392 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id);
2314 if (iter != blocked_loaders_map_.end()) { 2393 if (iter != blocked_loaders_map_.end()) {
2315 // The request should be blocked. 2394 // The request should be blocked.
2316 iter->second->push_back(std::move(loader)); 2395 iter->second->push_back(std::move(loader));
2317 return; 2396 return;
2318 } 2397 }
2319 2398
2320 StartLoading(info, std::move(loader)); 2399 StartLoading(info, std::move(loader));
2321 } 2400 }
2322 2401
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2426 update_load_states_timer_->Stop(); 2505 update_load_states_timer_->Stop();
2427 return; 2506 return;
2428 } 2507 }
2429 2508
2430 BrowserThread::PostTask( 2509 BrowserThread::PostTask(
2431 BrowserThread::UI, FROM_HERE, 2510 BrowserThread::UI, FROM_HERE,
2432 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, 2511 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread,
2433 base::Passed(&info_map))); 2512 base::Passed(&info_map)));
2434 } 2513 }
2435 2514
2436 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, 2515 void ResourceDispatcherHostImpl::BlockRequestsForRoute(
2437 int route_id) { 2516 const GlobalFrameRoutingId& routing_id) {
2438 DCHECK_CURRENTLY_ON(BrowserThread::IO); 2517 DCHECK_CURRENTLY_ON(BrowserThread::IO);
2439 GlobalRoutingID key(child_id, route_id); 2518 DCHECK(blocked_loaders_map_.find(routing_id) == blocked_loaders_map_.end())
2440 DCHECK(blocked_loaders_map_.find(key) == blocked_loaders_map_.end()) << 2519 << "BlockRequestsForRoute called multiple time for the same RFH";
2441 "BlockRequestsForRoute called multiple time for the same RVH"; 2520 blocked_loaders_map_[routing_id] = make_scoped_ptr(new BlockedLoadersList());
2442 blocked_loaders_map_[key] = make_scoped_ptr(new BlockedLoadersList());
2443 } 2521 }
2444 2522
2445 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute(int child_id, 2523 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute(
2446 int route_id) { 2524 const GlobalFrameRoutingId& routing_id) {
2447 ProcessBlockedRequestsForRoute(child_id, route_id, false); 2525 ProcessBlockedRequestsForRoute(routing_id, false);
2448 } 2526 }
2449 2527
2450 void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute(int child_id, 2528 void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute(
2451 int route_id) { 2529 const GlobalFrameRoutingId& routing_id) {
2452 ProcessBlockedRequestsForRoute(child_id, route_id, true); 2530 ProcessBlockedRequestsForRoute(routing_id, true);
2453 } 2531 }
2454 2532
2455 void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute( 2533 void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute(
2456 int child_id, 2534 const GlobalFrameRoutingId& routing_id,
2457 int route_id,
2458 bool cancel_requests) { 2535 bool cancel_requests) {
2459 BlockedLoadersMap::iterator iter = blocked_loaders_map_.find( 2536 BlockedLoadersMap::iterator iter = blocked_loaders_map_.find(routing_id);
2460 GlobalRoutingID(child_id, route_id));
2461 if (iter == blocked_loaders_map_.end()) { 2537 if (iter == blocked_loaders_map_.end()) {
2462 // It's possible to reach here if the renderer crashed while an interstitial 2538 // It's possible to reach here if the renderer crashed while an interstitial
2463 // page was showing. 2539 // page was showing.
2464 return; 2540 return;
2465 } 2541 }
2466 2542
2467 BlockedLoadersList* loaders = iter->second.get(); 2543 BlockedLoadersList* loaders = iter->second.get();
2468 scoped_ptr<BlockedLoadersList> deleter(std::move(iter->second)); 2544 scoped_ptr<BlockedLoadersList> deleter(std::move(iter->second));
2469 2545
2470 // Removing the vector from the map unblocks any subsequent requests. 2546 // Removing the vector from the map unblocks any subsequent requests.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2566 load_flags |= net::LOAD_PREFETCH; 2642 load_flags |= net::LOAD_PREFETCH;
2567 } 2643 }
2568 2644
2569 if (is_sync_load) 2645 if (is_sync_load)
2570 load_flags |= net::LOAD_IGNORE_LIMITS; 2646 load_flags |= net::LOAD_IGNORE_LIMITS;
2571 2647
2572 return load_flags; 2648 return load_flags;
2573 } 2649 }
2574 2650
2575 } // namespace content 2651 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698