OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/loader/loader_io_thread_notifier.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
9 #include "content/browser/loader/global_routing_id.h" | |
10 #include "content/browser/loader/resource_dispatcher_host_impl.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 #include "content/public/browser/render_frame_host.h" | |
13 #include "content/public/browser/render_process_host.h" | |
14 #include "content/public/common/browser_side_navigation_policy.h" | |
15 | |
16 namespace content { | |
17 | |
18 namespace { | |
19 | |
20 void NotifyRenderFrameDeletedOnIO(int child_id, int route_id) { | |
21 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.
| |
22 ResourceDispatcherHostImpl* dispatcher_host = | |
23 ResourceDispatcherHostImpl::Get(); | |
24 if (dispatcher_host) | |
25 dispatcher_host->OnRenderFrameHostDeleted(child_id, route_id); | |
26 } | |
27 | |
28 bool CollectRenderFrameRoutingIds(std::set<GlobalFrameRoutingID>* route_ids, | |
29 FrameTreeNode* tree_node) { | |
30 RenderFrameHost* frame_host = tree_node->current_frame_host(); | |
31 if (frame_host) { | |
32 route_ids->insert(GlobalFrameRoutingID(frame_host->GetProcess()->GetID(), | |
33 frame_host->GetRoutingID())); | |
34 } | |
35 RenderFrameHost* pending_frame_host = | |
36 IsBrowserSideNavigationEnabled() | |
37 ? tree_node->render_manager()->speculative_frame_host() | |
38 : tree_node->render_manager()->pending_frame_host(); | |
39 if (pending_frame_host) { | |
40 route_ids->insert( | |
41 GlobalFrameRoutingID(pending_frame_host->GetProcess()->GetID(), | |
42 pending_frame_host->GetRoutingID())); | |
43 } | |
44 return true; | |
45 } | |
46 | |
47 void NotifyForEachFrameOnIOHelper( | |
48 base::Callback<void(ResourceDispatcherHostImpl*, int ,int)> | |
49 frame_callback, | |
50 std::set<GlobalFrameRoutingID> | |
51 routing_ids) { | |
52 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | |
53 if (rdh) { | |
54 for (const auto& routing_id : routing_ids) | |
55 frame_callback.Run(rdh, routing_id.child_id, routing_id.route_id); | |
56 } | |
57 } | |
58 | |
59 } // namespace | |
60 | |
61 // static | |
62 void LoaderIOThreadNotifer::NotifyForEachFrameOnIO( | |
63 FrameTree* frame_tree, | |
64 base::Callback<void(ResourceDispatcherHostImpl*, int ,int)> | |
65 frame_callback) { | |
66 std::set<GlobalFrameRoutingID> routing_ids; | |
67 frame_tree->ForEach(base::Bind(&CollectRenderFrameRoutingIds, &routing_ids)); | |
68 BrowserThread::PostTask( | |
69 BrowserThread::IO, FROM_HERE, | |
70 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.
| |
71 } | |
72 | |
73 LoaderIOThreadNotifer::LoaderIOThreadNotifer(WebContents* web_contents) | |
74 : WebContentsObserver(web_contents) {} | |
75 | |
76 void LoaderIOThreadNotifer::RenderFrameDeleted( | |
77 RenderFrameHost* render_frame_host) { | |
78 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
79 base::Bind(&NotifyRenderFrameDeletedOnIO, | |
80 render_frame_host->GetProcess()->GetID(), | |
81 render_frame_host->GetRoutingID())); | |
82 } | |
83 | |
84 } // namespace content | |
OLD | NEW |