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

Side by Side Diff: content/browser/frame_host/frame_tree.cc

Issue 30323002: [DRAFT] Create RenderFrameHostManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/frame_host/frame_tree.h ('k') | content/browser/frame_host/frame_tree_node.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "content/browser/frame_host/frame_tree.h" 5 #include "content/browser/frame_host/frame_tree.h"
6 6
7 #include <queue> 7 #include <queue>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "content/browser/frame_host/frame_tree_node.h" 11 #include "content/browser/frame_host/frame_tree_node.h"
12 #include "content/browser/frame_host/render_frame_host_impl.h" 12 #include "content/browser/frame_host/render_frame_host_impl.h"
13 #include "content/browser/renderer_host/render_view_host_factory.h"
14 #include "content/browser/renderer_host/render_view_host_impl.h"
13 15
14 namespace content { 16 namespace content {
15 17
16 namespace { 18 namespace {
17 // Used with FrameTree::ForEach() to search for the FrameTreeNode 19 // Used with FrameTree::ForEach() to search for the FrameTreeNode
18 // corresponding to |frame_id|. 20 // corresponding to |frame_tree_node_id|.
19 bool FrameTreeNodeForId(int64 frame_id, FrameTreeNode** out_node, 21 bool FrameTreeNodeForId(int64 frame_tree_node_id,
22 FrameTreeNode** out_node,
20 FrameTreeNode* node) { 23 FrameTreeNode* node) {
21 if (node->frame_id() == frame_id) { 24 if (node->frame_tree_node_id() == frame_tree_node_id) {
22 *out_node = node; 25 *out_node = node;
23 // Terminate iteration once the node has been found. 26 // Terminate iteration once the node has been found.
24 return false; 27 return false;
25 } 28 }
26 return true; 29 return true;
27 } 30 }
28 31
29 } // namespace 32 } // namespace
30 33
31 FrameTree::FrameTree() 34 int64 FrameTree::next_frame_tree_node_id_ = 1;
32 : root_(new FrameTreeNode(FrameTreeNode::kInvalidFrameId, std::string(), 35
33 scoped_ptr<RenderFrameHostImpl>())) { 36 FrameTree::FrameTree(RenderViewHostDelegate* render_view_delegate,
37 RenderWidgetHostDelegate* render_widget_delegate,
38 RenderViewHostManager::Delegate* manager_delegate)
39 : render_view_delegate_(render_view_delegate),
40 render_widget_delegate_(render_widget_delegate),
41 manager_delegate_(manager_delegate),
42 root_(new FrameTreeNode(GetNextFrameTreeNodeID(), std::string(),
43 render_view_delegate,
44 render_widget_delegate,
45 manager_delegate)) {
34 } 46 }
35 47
36 FrameTree::~FrameTree() { 48 FrameTree::~FrameTree() {
37 } 49 }
38 50
39 FrameTreeNode* FrameTree::FindByID(int64 frame_id) { 51 FrameTreeNode* FrameTree::FindByID(int64 frame_tree_node_id) {
40 FrameTreeNode* node = NULL; 52 FrameTreeNode* node = NULL;
41 ForEach(base::Bind(&FrameTreeNodeForId, frame_id, &node)); 53 ForEach(base::Bind(&FrameTreeNodeForId, frame_tree_node_id, &node));
42 return node; 54 return node;
43 } 55 }
44 56
45 void FrameTree::ForEach( 57 void FrameTree::ForEach(
46 const base::Callback<bool(FrameTreeNode*)>& on_node) const { 58 const base::Callback<bool(FrameTreeNode*)>& on_node) const {
47 std::queue<FrameTreeNode*> queue; 59 std::queue<FrameTreeNode*> queue;
48 queue.push(root_.get()); 60 queue.push(root_.get());
49 61
50 while (!queue.empty()) { 62 while (!queue.empty()) {
51 FrameTreeNode* node = queue.front(); 63 FrameTreeNode* node = queue.front();
52 queue.pop(); 64 queue.pop();
53 if (!on_node.Run(node)) 65 if (!on_node.Run(node))
54 break; 66 break;
55 67
56 for (size_t i = 0; i < node->child_count(); ++i) 68 for (size_t i = 0; i < node->child_count(); ++i)
57 queue.push(node->child_at(i)); 69 queue.push(node->child_at(i));
58 } 70 }
59 } 71 }
60 72
61 bool FrameTree::IsFirstNavigationAfterSwap() const { 73 void FrameTree::AddFrame(RenderViewHostImpl* parent_render_view_host,
62 return root_->frame_id() == FrameTreeNode::kInvalidFrameId; 74 int render_frame_host_id,
63 } 75 int64 parent_frame_id,
64 76 int64 frame_id,
65 void FrameTree::OnFirstNavigationAfterSwap(int main_frame_id) { 77 const std::string& frame_name) {
66 root_->set_frame_id(main_frame_id); 78 int64 parent_frame_tree_node_id =
67 } 79 parent_render_view_host->GetFrameTreeNodeID(parent_frame_id);
68 80 FrameTreeNode* parent = FindByID(parent_frame_tree_node_id);
69 void FrameTree::AddFrame(int render_frame_host_id, int64 parent_frame_id,
70 int64 frame_id, const std::string& frame_name) {
71 FrameTreeNode* parent = FindByID(parent_frame_id);
72 // TODO(ajwong): Should the renderer be killed here? Would there be a race on 81 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
73 // shutdown that might make this case possible? 82 // shutdown that might make this case possible?
74 if (!parent) 83 if (!parent)
75 return; 84 return;
76 85
77 parent->AddChild(CreateNode(frame_id, frame_name, render_frame_host_id, 86 parent->AddChild(CreateNode(frame_id, frame_name, render_frame_host_id,
78 parent->render_frame_host()->GetProcess())); 87 parent_render_view_host));
79 } 88 }
80 89
81 void FrameTree::RemoveFrame(int64 parent_frame_id, int64 frame_id) { 90 void FrameTree::RemoveFrame(int64 parent_frame_tree_node_id,
91 int64 frame_tree_node_id) {
82 // If switches::kSitePerProcess is not specified, then the FrameTree only 92 // If switches::kSitePerProcess is not specified, then the FrameTree only
83 // contains a node for the root element. However, even in this case 93 // contains a node for the root element. However, even in this case
84 // frame detachments need to be broadcast outwards. 94 // frame detachments need to be broadcast outwards.
85 // 95 //
86 // TODO(ajwong): Move this below the |parent| check after the FrameTree is 96 // TODO(ajwong): Move this below the |parent| check after the FrameTree is
87 // guaranteed to be correctly populated even without the 97 // guaranteed to be correctly populated even without the
88 // switches::kSitePerProcess flag. 98 // switches::kSitePerProcess flag.
89 FrameTreeNode* parent = FindByID(parent_frame_id); 99 FrameTreeNode* parent = FindByID(parent_frame_tree_node_id);
90 if (!on_frame_removed_.is_null()) { 100 if (!on_frame_removed_.is_null()) {
91 on_frame_removed_.Run( 101 on_frame_removed_.Run(
92 root_->render_frame_host()->render_view_host(), frame_id); 102 root_->render_frame_host()->render_view_host(), frame_tree_node_id);
103 }
104
105 // Decrement the refcount of the frame's RenderViewHost, allowing it to shut
106 // down if it is no longer needed.
107 // TODO(creis): Is this the only way that RFHs can be deleted? If not, we
108 // should listen for that instead of doing it here.
109 FrameTreeNode* node = FindByID(frame_tree_node_id);
110 RenderViewHostImpl* render_view_host =
111 node->render_frame_host()->render_view_host();
112 rvh_refcounts_[render_view_host->GetRoutingID()]--;
113 if (rvh_refcounts_[render_view_host->GetRoutingID()] <= 0) {
114 rvh_refcounts_.erase(render_view_host->GetRoutingID());
115 render_view_host->Shutdown();
93 } 116 }
94 117
95 // TODO(ajwong): Should the renderer be killed here? Would there be a race on 118 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
96 // shutdown that might make this case possible? 119 // shutdown that might make this case possible?
97 if (!parent) 120 if (!parent)
98 return; 121 return;
99 122
100 parent->RemoveChild(frame_id); 123 parent->RemoveChild(frame_tree_node_id);
101 } 124 }
102 125
103 void FrameTree::SetFrameUrl(int64 frame_id, const GURL& url) { 126 void FrameTree::SetFrameUrl(int64 frame_tree_node_id, const GURL& url) {
104 FrameTreeNode* node = FindByID(frame_id); 127 FrameTreeNode* node = FindByID(frame_tree_node_id);
105 // TODO(ajwong): Should the renderer be killed here? Would there be a race on 128 // TODO(ajwong): Should the renderer be killed here? Would there be a race on
106 // shutdown that might make this case possible? 129 // shutdown that might make this case possible?
107 if (!node) 130 if (!node)
108 return; 131 return;
109 132
110 if (node) 133 if (node)
111 node->set_current_url(url); 134 node->set_current_url(url);
112 } 135 }
113 136
114 void FrameTree::SwapMainFrame(RenderFrameHostImpl* render_frame_host) {
115 return root_->ResetForMainFrame(render_frame_host);
116 }
117
118 RenderFrameHostImpl* FrameTree::GetMainFrame() const { 137 RenderFrameHostImpl* FrameTree::GetMainFrame() const {
119 return root_->render_frame_host(); 138 return root_->render_frame_host();
120 } 139 }
121 140
122 void FrameTree::SetFrameRemoveListener( 141 void FrameTree::SetFrameRemoveListener(
123 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed) { 142 const base::Callback<void(RenderViewHostImpl*, int64)>& on_frame_removed) {
124 on_frame_removed_ = on_frame_removed; 143 on_frame_removed_ = on_frame_removed;
125 } 144 }
126 145
146 RenderViewHostImpl* FrameTree::GetRenderViewHostForNewFrame(
147 SiteInstance* site_instance,
148 int routing_id,
149 int main_frame_routing_id,
150 bool swapped_out,
151 bool hidden) {
152 RenderViewHostMap::iterator iter =
153 render_view_host_map_.find(site_instance->GetId());
154 RenderViewHostImpl* rvh = NULL;
155 if (iter != render_view_host_map_.end()) {
156 rvh = iter->second;
157 } else {
158 rvh = static_cast<RenderViewHostImpl*>(
159 RenderViewHostFactory::Create(site_instance,
160 render_view_delegate_,
161 render_widget_delegate_,
162 routing_id,
163 main_frame_routing_id,
164 swapped_out,
165 hidden));
166
167 render_view_host_map_[site_instance->GetId()] = rvh;
168 }
169 rvh_refcounts_[rvh->GetRoutingID()]++;
170 return rvh;
171 }
172
127 scoped_ptr<FrameTreeNode> FrameTree::CreateNode( 173 scoped_ptr<FrameTreeNode> FrameTree::CreateNode(
128 int64 frame_id, const std::string& frame_name, int render_frame_host_id, 174 int64 frame_id,
129 RenderProcessHost* render_process_host) { 175 const std::string& frame_name,
130 scoped_ptr<RenderFrameHostImpl> render_frame_host( 176 int render_frame_host_id,
131 new RenderFrameHostImpl(root_->render_frame_host()->render_view_host(), 177 RenderViewHostImpl* render_view_host) {
132 this, render_frame_host_id, false)); 178 // TODO(creis): Call Init on the RFHM.
133 179
134 return make_scoped_ptr(new FrameTreeNode(frame_id, frame_name, 180 // Create the FrameTreeNode with a unique browser-wide ID, and make sure the
135 render_frame_host.Pass())); 181 // renderer-specific frame_id can be used to find it.
182 int64 frame_tree_node_id = GetNextFrameTreeNodeID();
183 render_view_host->RegisterFrameTreeNodeID(frame_id, frame_tree_node_id);
184 return make_scoped_ptr(new FrameTreeNode(frame_tree_node_id, frame_name,
185 render_view_delegate_,
186 render_widget_delegate_,
187 manager_delegate_));
188 }
189
190 int64 FrameTree::GetNextFrameTreeNodeID() {
191 return next_frame_tree_node_id_++;
136 } 192 }
137 193
138 } // namespace content 194 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/frame_tree.h ('k') | content/browser/frame_host/frame_tree_node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698