Chromium Code Reviews| Index: content/browser/loader/loader_io_thread_notifier.cc |
| diff --git a/content/browser/loader/loader_io_thread_notifier.cc b/content/browser/loader/loader_io_thread_notifier.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cf0ffe9c0e1c6a2fb56c831a1a5c1036797e7acd |
| --- /dev/null |
| +++ b/content/browser/loader/loader_io_thread_notifier.cc |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/loader/loader_io_thread_notifier.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "content/browser/loader/global_routing_id.h" |
| +#include "content/browser/loader/resource_dispatcher_host_impl.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/common/browser_side_navigation_policy.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| + |
| +void NotifyRenderFrameDeletedOnIO(int child_id, int route_id) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
|
Randy Smith (Not in Mondays)
2015/12/29 23:11:37
I'd be more aggressive on scattering these through
Charlie Harrison
2015/12/30 20:51:49
Done.
|
| + ResourceDispatcherHostImpl* dispatcher_host = |
| + ResourceDispatcherHostImpl::Get(); |
| + if (dispatcher_host) |
| + dispatcher_host->OnRenderFrameHostDeleted(child_id, route_id); |
| +} |
| + |
| +bool CollectRenderFrameRoutingIds(std::set<GlobalFrameRoutingID>* route_ids, |
| + FrameTreeNode* tree_node) { |
| + RenderFrameHost* frame_host = tree_node->current_frame_host(); |
| + if (frame_host) { |
| + route_ids->insert(GlobalFrameRoutingID(frame_host->GetProcess()->GetID(), |
| + frame_host->GetRoutingID())); |
| + } |
| + RenderFrameHost* pending_frame_host = |
| + IsBrowserSideNavigationEnabled() |
| + ? tree_node->render_manager()->speculative_frame_host() |
| + : tree_node->render_manager()->pending_frame_host(); |
| + if (pending_frame_host) { |
| + route_ids->insert( |
| + GlobalFrameRoutingID(pending_frame_host->GetProcess()->GetID(), |
| + pending_frame_host->GetRoutingID())); |
| + } |
| + return true; |
| +} |
| + |
| +void NotifyForEachFrameOnIOHelper( |
| + base::Callback<void(ResourceDispatcherHostImpl*, int ,int)> |
| + frame_callback, |
| + std::set<GlobalFrameRoutingID> |
| + routing_ids) { |
| + ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| + if (rdh) { |
| + for (const auto& routing_id : routing_ids) |
| + frame_callback.Run(rdh, routing_id.child_id, routing_id.route_id); |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +// static |
| +void LoaderIOThreadNotifer::NotifyForEachFrameOnIO( |
| + FrameTree* frame_tree, |
| + base::Callback<void(ResourceDispatcherHostImpl*, int ,int)> |
| + frame_callback) { |
| + std::set<GlobalFrameRoutingID> routing_ids; |
| + frame_tree->ForEach(base::Bind(&CollectRenderFrameRoutingIds, &routing_ids)); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&NotifyForEachFrameOnIOHelper, frame_callback, routing_ids)); |
|
Randy Smith (Not in Mondays)
2015/12/29 23:11:37
nit, suggestion: This looks like a lot of copying;
Charlie Harrison
2015/12/30 20:51:49
Done.
|
| +} |
| + |
| +LoaderIOThreadNotifer::LoaderIOThreadNotifer(WebContents* web_contents) |
| + : WebContentsObserver(web_contents) {} |
| + |
| +void LoaderIOThreadNotifer::RenderFrameDeleted( |
| + RenderFrameHost* render_frame_host) { |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| + base::Bind(&NotifyRenderFrameDeletedOnIO, |
| + render_frame_host->GetProcess()->GetID(), |
| + render_frame_host->GetRoutingID())); |
| +} |
| + |
| +} // namespace content |