Chromium Code Reviews| 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_impl.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/memory/scoped_ptr.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 bool CollectRenderFrameRoutingIds(std::set<GlobalFrameRoutingId>* route_ids, | |
|
Randy Smith (Not in Mondays)
2016/01/06 21:56:29
I'd value a quick comment explaining the goal of t
Charlie Harrison
2016/01/07 22:47:05
That is the goal, we just don't want to miss any (
| |
| 21 FrameTreeNode* tree_node) { | |
|
Randy Smith (Not in Mondays)
2016/01/06 21:56:29
Style guide says parameter order is inputs, then o
Charlie Harrison
2016/01/07 22:47:05
I'm not sure the best way to reconcile this. Frame
| |
| 22 RenderFrameHostImpl* frame_host = tree_node->current_frame_host(); | |
|
Randy Smith (Not in Mondays)
2016/01/06 21:56:30
DCHECK for thread? I think it's useful being a-r
Charlie Harrison
2016/01/07 22:47:05
Done.
| |
| 23 RenderFrameHostImpl* pending_frame_host = | |
| 24 IsBrowserSideNavigationEnabled() | |
| 25 ? tree_node->render_manager()->speculative_frame_host() | |
| 26 : tree_node->render_manager()->pending_frame_host(); | |
| 27 if (frame_host) | |
| 28 route_ids->insert(frame_host->GetGlobalFrameRoutingId()); | |
| 29 if (pending_frame_host) | |
| 30 route_ids->insert(pending_frame_host->GetGlobalFrameRoutingId()); | |
| 31 return true; | |
| 32 } | |
| 33 | |
| 34 void NotifyForEachFrameOnIO( | |
| 35 base::Callback<void(ResourceDispatcherHostImpl*, | |
| 36 const GlobalFrameRoutingId&)> frame_callback, | |
| 37 scoped_ptr<std::set<GlobalFrameRoutingId>> routing_ids) { | |
| 38 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 39 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | |
|
Randy Smith (Not in Mondays)
2016/01/06 21:56:29
What are the lifetime implications here? Are you
Charlie Harrison
2016/01/07 22:47:05
Well if RDHI is torn down then won't Get() return
| |
| 40 if (rdh) { | |
| 41 for (const auto& routing_id : *routing_ids) | |
| 42 frame_callback.Run(rdh, routing_id); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void NotifyForFrameOnIO( | |
| 47 base::Callback<void(ResourceDispatcherHostImpl*, | |
| 48 const GlobalFrameRoutingId&)> frame_callback, | |
| 49 const GlobalFrameRoutingId& routing_id) { | |
|
Randy Smith (Not in Mondays)
2016/01/06 21:56:29
idea (up to you): I find myself wondering about wh
Charlie Harrison
2016/01/07 22:47:05
Yeah sgtm.
| |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 51 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | |
| 52 if (rdh) | |
| 53 frame_callback.Run(rdh, routing_id); | |
| 54 } | |
| 55 | |
| 56 } // namespace | |
| 57 | |
| 58 // static | |
| 59 void LoaderIOThreadNotifierImpl::ResumeBlockedRequestsForFrameInternal( | |
| 60 const GlobalFrameRoutingId& routing_id) { | |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 62 // Only resume blocked requests for valid ids. See | |
| 63 // RenderWidgetHelper::CreateNewWindow for when an invalid id might be used. | |
| 64 if (routing_id.route_id == MSG_ROUTING_NONE) | |
| 65 return; | |
| 66 BrowserThread::PostTask( | |
| 67 BrowserThread::IO, FROM_HERE, | |
| 68 base::Bind( | |
| 69 &NotifyForFrameOnIO, | |
| 70 base::Bind( | |
| 71 &ResourceDispatcherHostImpl::ResumeBlockedRequestsForFrame), | |
| 72 routing_id)); | |
| 73 } | |
| 74 | |
| 75 // static | |
| 76 void LoaderIOThreadNotifierImpl::NotifyForEachFrame( | |
| 77 FrameTree* frame_tree, | |
| 78 base::Callback<void(ResourceDispatcherHostImpl*, | |
| 79 const GlobalFrameRoutingId&)> frame_callback) { | |
| 80 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 81 scoped_ptr<std::set<GlobalFrameRoutingId>> routing_ids( | |
| 82 new std::set<GlobalFrameRoutingId>()); | |
| 83 frame_tree->ForEach( | |
| 84 base::Bind(&CollectRenderFrameRoutingIds, routing_ids.get())); | |
| 85 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 86 base::Bind(&NotifyForEachFrameOnIO, frame_callback, | |
| 87 base::Passed(std::move(routing_ids)))); | |
| 88 } | |
| 89 | |
| 90 LoaderIOThreadNotifierImpl::LoaderIOThreadNotifierImpl( | |
| 91 WebContents* web_contents) | |
| 92 : WebContentsObserver(web_contents) {} | |
| 93 | |
| 94 LoaderIOThreadNotifierImpl::~LoaderIOThreadNotifierImpl() {} | |
| 95 | |
| 96 void LoaderIOThreadNotifierImpl::RenderFrameDeleted( | |
| 97 RenderFrameHost* render_frame_host) { | |
| 98 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 99 BrowserThread::PostTask( | |
| 100 BrowserThread::IO, FROM_HERE, | |
| 101 base::Bind( | |
| 102 &NotifyForFrameOnIO, | |
| 103 base::Bind(&ResourceDispatcherHostImpl::OnRenderFrameHostDeleted), | |
|
nasko
2016/01/07 19:58:39
This isn't quite correct. RenderFrame is the rende
Charlie Harrison
2016/01/07 22:47:05
Fixed the name to refer to the RenderFrame.
| |
| 104 static_cast<RenderFrameHostImpl*>(render_frame_host) | |
| 105 ->GetGlobalFrameRoutingId())); | |
| 106 } | |
| 107 | |
| 108 } // namespace content | |
| OLD | NEW |