Index: content/browser/loader/resource_dispatcher_host_impl.cc |
diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc |
index 825eaa7dfabdb810b01cb3d561696815190f5b3f..e7ec92dc8795f677615ec5c960b7dac46ffb3109 100644 |
--- a/content/browser/loader/resource_dispatcher_host_impl.cc |
+++ b/content/browser/loader/resource_dispatcher_host_impl.cc |
@@ -39,6 +39,7 @@ |
#include "content/browser/download/save_file_manager.h" |
#include "content/browser/download/save_file_resource_handler.h" |
#include "content/browser/fileapi/chrome_blob_storage_context.h" |
+#include "content/browser/frame_host/frame_tree.h" |
#include "content/browser/frame_host/navigation_request_info.h" |
#include "content/browser/frame_host/navigator.h" |
#include "content/browser/loader/async_resource_handler.h" |
@@ -454,8 +455,58 @@ bool IsUsingLoFi(LoFiState lofi_state, |
return lofi_state == LOFI_ON; |
} |
+// Walk the frame tree and pick up ids for every RenderFrameHost. Note that a |
+// single node can have multiple RenderFrameHosts (speculative / pending). |
+bool CollectRenderFrameRoutingIds(std::set<GlobalFrameRoutingId>* route_ids, |
+ 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
|
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ RenderFrameHostImpl* frame_host = tree_node->current_frame_host(); |
+ RenderFrameHostImpl* pending_frame_host = |
+ IsBrowserSideNavigationEnabled() |
+ ? tree_node->render_manager()->speculative_frame_host() |
+ : tree_node->render_manager()->pending_frame_host(); |
+ if (frame_host) |
+ route_ids->insert(frame_host->GetGlobalFrameRoutingId()); |
+ if (pending_frame_host) |
+ route_ids->insert(pending_frame_host->GetGlobalFrameRoutingId()); |
+ return true; |
+} |
+ |
+void NotifyForRouteOnIO( |
+ base::Callback<void(ResourceDispatcherHostImpl*, |
+ const GlobalFrameRoutingId&)> frame_callback, |
+ const GlobalFrameRoutingId& routing_id) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
+ if (rdh) |
+ frame_callback.Run(rdh, routing_id); |
+} |
+ |
+void NotifyForEachFrameOnIO( |
+ base::Callback<void(ResourceDispatcherHostImpl*, |
+ const GlobalFrameRoutingId&)> frame_callback, |
+ scoped_ptr<std::set<GlobalFrameRoutingId>> routing_ids) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ for (const auto& routing_id : *routing_ids) |
+ NotifyForRouteOnIO(frame_callback, routing_id); |
+} |
+ |
} // namespace |
+LoaderIOThreadNotifier::LoaderIOThreadNotifier( |
+ WebContents* web_contents) |
+ : WebContentsObserver(web_contents) {} |
+ |
+LoaderIOThreadNotifier::~LoaderIOThreadNotifier() {} |
+ |
+void LoaderIOThreadNotifier::RenderFrameDeleted( |
+ RenderFrameHost* render_frame_host) { |
+ ResourceDispatcherHostImpl::NotifyForRoute( |
+ static_cast<RenderFrameHostImpl*>(render_frame_host) |
+ ->GetGlobalFrameRoutingId(), |
+ base::Bind(&ResourceDispatcherHostImpl::OnRenderFrameDeleted)); |
+} |
+ |
// static |
ResourceDispatcherHost* ResourceDispatcherHost::Get() { |
return g_resource_dispatcher_host; |
@@ -522,6 +573,34 @@ ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { |
return g_resource_dispatcher_host; |
} |
+// static |
+void ResourceDispatcherHostImpl::NotifyForRoute( |
+ const GlobalFrameRoutingId& routing_id, |
+ base::Callback<void(ResourceDispatcherHostImpl*, |
+ const GlobalFrameRoutingId&)> |
+ frame_callback) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&NotifyForRouteOnIO, frame_callback, routing_id)); |
+} |
+ |
+// static |
+void ResourceDispatcherHostImpl::NotifyForEachFrame( |
+ FrameTree* frame_tree, |
+ base::Callback<void(ResourceDispatcherHostImpl*, |
+ const GlobalFrameRoutingId&)> |
+ frame_callback) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ scoped_ptr<std::set<GlobalFrameRoutingId>> routing_ids( |
+ new std::set<GlobalFrameRoutingId>()); |
+ frame_tree->ForEach( |
+ base::Bind(&CollectRenderFrameRoutingIds, routing_ids.get())); |
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
+ base::Bind(&NotifyForEachFrameOnIO, frame_callback, |
+ base::Passed(std::move(routing_ids)))); |
+} |
+ |
void ResourceDispatcherHostImpl::SetDelegate( |
ResourceDispatcherHostDelegate* delegate) { |
delegate_ = delegate; |
@@ -1055,17 +1134,17 @@ void ResourceDispatcherHostImpl::OnShutdown() { |
// Note that we have to do this in 2 passes as we cannot call |
// CancelBlockedRequestsForRoute while iterating over |
// blocked_loaders_map_, as it modifies it. |
- std::set<GlobalRoutingID> ids; |
+ std::set<GlobalFrameRoutingId> ids; |
for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); |
iter != blocked_loaders_map_.end(); ++iter) { |
- std::pair<std::set<GlobalRoutingID>::iterator, bool> result = |
+ std::pair<std::set<GlobalFrameRoutingId>::iterator, bool> result = |
ids.insert(iter->first); |
// We should not have duplicates. |
DCHECK(result.second); |
} |
- for (std::set<GlobalRoutingID>::const_iterator iter = ids.begin(); |
+ for (std::set<GlobalFrameRoutingId>::const_iterator iter = ids.begin(); |
iter != ids.end(); ++iter) { |
- CancelBlockedRequestsForRoute(iter->child_id, iter->route_id); |
+ CancelBlockedRequestsForRoute(*iter); |
} |
scheduler_.reset(); |
@@ -1161,11 +1240,11 @@ void ResourceDispatcherHostImpl::UpdateRequestForTransfer( |
const ResourceHostMsg_Request& request_data, |
const linked_ptr<ResourceLoader>& loader) { |
ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
- GlobalRoutingID old_routing_id( |
- request_data.transferred_request_child_id, info->GetRouteID()); |
+ GlobalFrameRoutingId old_routing_id(request_data.transferred_request_child_id, |
+ info->GetRenderFrameID()); |
GlobalRequestID old_request_id(request_data.transferred_request_child_id, |
request_data.transferred_request_request_id); |
- GlobalRoutingID new_routing_id(child_id, route_id); |
+ GlobalFrameRoutingId new_routing_id(child_id, request_data.render_frame_id); |
GlobalRequestID new_request_id(child_id, request_id); |
// Clear out data that depends on |info| before updating it. |
@@ -1731,6 +1810,11 @@ ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( |
std::string()); // original_headers |
} |
+void ResourceDispatcherHostImpl::OnRenderFrameDeleted( |
+ const GlobalFrameRoutingId& routing_id) { |
+ CancelRequestsForRoute(routing_id); |
+} |
+ |
void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, |
int route_id, |
bool is_visible, |
@@ -1738,11 +1822,9 @@ void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, |
scheduler_->OnClientCreated(child_id, route_id, is_visible, is_audible); |
} |
-void ResourceDispatcherHostImpl::OnRenderViewHostDeleted( |
- int child_id, |
- int route_id) { |
+void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id, |
+ int route_id) { |
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
|
- CancelRequestsForRoute(child_id, route_id); |
} |
void ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading(int child_id, |
@@ -1851,18 +1933,23 @@ void ResourceDispatcherHostImpl::ResumeDeferredNavigation( |
// for downloads and detachable resources, which belong to the browser process |
// even if initiated via a renderer. |
void ResourceDispatcherHostImpl::CancelRequestsForProcess(int child_id) { |
- CancelRequestsForRoute(child_id, -1 /* cancel all */); |
+ CancelRequestsForRoute( |
+ GlobalFrameRoutingId(child_id, MSG_ROUTING_NONE /* cancel all */)); |
registered_temp_files_.erase(child_id); |
} |
-void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id, |
- int route_id) { |
+void ResourceDispatcherHostImpl::CancelRequestsForRoute( |
+ const GlobalFrameRoutingId& routing_id) { |
// Since pending_requests_ is a map, we first build up a list of all of the |
// matching requests to be cancelled, and then we cancel them. Since there |
// may be more than one request to cancel, we cannot simply hold onto the map |
// iterators found in the first loop. |
// Find the global ID of all matching elements. |
+ int child_id = routing_id.child_id; |
+ int route_id = routing_id.route_id; |
+ bool cancel_all_routes = route_id == MSG_ROUTING_NONE; |
+ |
bool any_requests_transferring = false; |
std::vector<GlobalRequestID> matching_requests; |
for (LoaderMap::const_iterator i = pending_loaders_.begin(); |
@@ -1881,7 +1968,7 @@ void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id, |
info->detachable_handler()->Detach(); |
} else if (!info->IsDownload() && !info->is_stream() && |
!IsTransferredNavigation(id) && |
- (route_id == -1 || route_id == info->GetRouteID())) { |
+ (cancel_all_routes || route_id == info->GetRenderFrameID())) { |
matching_requests.push_back(id); |
} |
} |
@@ -1911,25 +1998,25 @@ void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id, |
return; |
// Now deal with blocked requests if any. |
- if (route_id != -1) { |
- if (blocked_loaders_map_.find(GlobalRoutingID(child_id, route_id)) != |
- blocked_loaders_map_.end()) { |
- CancelBlockedRequestsForRoute(child_id, route_id); |
+ if (!cancel_all_routes) { |
+ if (blocked_loaders_map_.find(routing_id) != blocked_loaders_map_.end()) { |
+ CancelBlockedRequestsForRoute(routing_id); |
} |
} else { |
- // We have to do all render views for the process |child_id|. |
+ // We have to do all render frames for the process |child_id|. |
// Note that we have to do this in 2 passes as we cannot call |
// CancelBlockedRequestsForRoute while iterating over |
- // blocked_loaders_map_, as it modifies it. |
- std::set<int> route_ids; |
+ // blocked_loaders_map_, as blocking requests modifies the map. |
+ std::set<GlobalFrameRoutingId> routing_ids; |
for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); |
iter != blocked_loaders_map_.end(); ++iter) { |
if (iter->first.child_id == child_id) |
- route_ids.insert(iter->first.route_id); |
+ routing_ids.insert(iter->first); |
} |
- for (std::set<int>::const_iterator iter = route_ids.begin(); |
- iter != route_ids.end(); ++iter) { |
- CancelBlockedRequestsForRoute(child_id, *iter); |
+ for (std::set<GlobalFrameRoutingId>::const_iterator iter = |
+ routing_ids.begin(); |
+ iter != routing_ids.end(); ++iter) { |
+ CancelBlockedRequestsForRoute(*iter); |
} |
} |
} |
@@ -2275,7 +2362,7 @@ void ResourceDispatcherHostImpl::BeginRequestInternal( |
linked_ptr<ResourceLoader> loader( |
new ResourceLoader(std::move(request), std::move(handler), this)); |
- GlobalRoutingID id(info->GetGlobalRoutingID()); |
+ GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID()); |
BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); |
if (iter != blocked_loaders_map_.end()) { |
// The request should be blocked. |
@@ -2397,31 +2484,28 @@ void ResourceDispatcherHostImpl::UpdateLoadInfo() { |
base::Passed(&info_map))); |
} |
-void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, |
- int route_id) { |
+void ResourceDispatcherHostImpl::BlockRequestsForRoute( |
+ const GlobalFrameRoutingId& routing_id) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |
- GlobalRoutingID key(child_id, route_id); |
- DCHECK(blocked_loaders_map_.find(key) == blocked_loaders_map_.end()) << |
- "BlockRequestsForRoute called multiple time for the same RVH"; |
- blocked_loaders_map_[key] = new BlockedLoadersList(); |
+ DCHECK(blocked_loaders_map_.find(routing_id) == blocked_loaders_map_.end()) |
+ << "BlockRequestsForRoute called multiple time for the same RFH"; |
+ blocked_loaders_map_[routing_id] = new BlockedLoadersList(); |
} |
-void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute(int child_id, |
- int route_id) { |
- ProcessBlockedRequestsForRoute(child_id, route_id, false); |
+void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute( |
+ const GlobalFrameRoutingId& routing_id) { |
+ ProcessBlockedRequestsForRoute(routing_id, false); |
} |
-void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute(int child_id, |
- int route_id) { |
- ProcessBlockedRequestsForRoute(child_id, route_id, true); |
+void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute( |
+ const GlobalFrameRoutingId& routing_id) { |
+ ProcessBlockedRequestsForRoute(routing_id, true); |
} |
void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute( |
- int child_id, |
- int route_id, |
+ const GlobalFrameRoutingId& routing_id, |
bool cancel_requests) { |
- BlockedLoadersMap::iterator iter = blocked_loaders_map_.find( |
- GlobalRoutingID(child_id, route_id)); |
+ BlockedLoadersMap::iterator iter = blocked_loaders_map_.find(routing_id); |
if (iter == blocked_loaders_map_.end()) { |
// It's possible to reach here if the renderer crashed while an interstitial |
// page was showing. |