OLD | NEW |
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" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 171 |
172 RenderViewHostImpl* FrameTree::CreateRenderViewHostForMainFrame( | 172 RenderViewHostImpl* FrameTree::CreateRenderViewHostForMainFrame( |
173 SiteInstance* site_instance, | 173 SiteInstance* site_instance, |
174 int routing_id, | 174 int routing_id, |
175 int main_frame_routing_id, | 175 int main_frame_routing_id, |
176 bool swapped_out, | 176 bool swapped_out, |
177 bool hidden) { | 177 bool hidden) { |
178 DCHECK(main_frame_routing_id != MSG_ROUTING_NONE); | 178 DCHECK(main_frame_routing_id != MSG_ROUTING_NONE); |
179 RenderViewHostMap::iterator iter = | 179 RenderViewHostMap::iterator iter = |
180 render_view_host_map_.find(site_instance->GetId()); | 180 render_view_host_map_.find(site_instance->GetId()); |
181 CHECK(iter == render_view_host_map_.end()); | 181 if (iter != render_view_host_map_.end()) { |
| 182 // If a RenderViewHost is pending shutdown for this |site_instance|, put it |
| 183 // in the map of RenderViewHost pending shutdown. Otherwise there should not |
| 184 // be a RenderViewHost for the site instance. |
| 185 CHECK_EQ(RenderViewHostImpl::STATE_PENDING_SHUTDOWN, |
| 186 iter->second->rvh_state()); |
| 187 render_view_host_pending_shutdown_map_.insert( |
| 188 std::pair<int, RenderViewHostImpl*>(site_instance->GetId(), |
| 189 iter->second)); |
| 190 render_view_host_map_.erase(iter); |
| 191 } |
182 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 192 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
183 RenderViewHostFactory::Create(site_instance, | 193 RenderViewHostFactory::Create(site_instance, |
184 render_view_delegate_, | 194 render_view_delegate_, |
185 render_widget_delegate_, | 195 render_widget_delegate_, |
186 routing_id, | 196 routing_id, |
187 main_frame_routing_id, | 197 main_frame_routing_id, |
188 swapped_out, | 198 swapped_out, |
189 hidden)); | 199 hidden)); |
190 | 200 |
191 render_view_host_map_[site_instance->GetId()] = | 201 render_view_host_map_[site_instance->GetId()] = rvh; |
192 RenderViewHostRefCount(rvh, 0); | |
193 return rvh; | 202 return rvh; |
194 } | 203 } |
195 | 204 |
196 RenderViewHostImpl* FrameTree::GetRenderViewHostForSubFrame( | 205 RenderViewHostImpl* FrameTree::GetRenderViewHostForSubFrame( |
197 SiteInstance* site_instance) { | 206 SiteInstance* site_instance) { |
198 RenderViewHostMap::iterator iter = | 207 RenderViewHostMap::iterator iter = |
199 render_view_host_map_.find(site_instance->GetId()); | 208 render_view_host_map_.find(site_instance->GetId()); |
200 // TODO(creis): Mirror the frame tree so this check can't fail. | 209 // TODO(creis): Mirror the frame tree so this check can't fail. |
201 if (iter == render_view_host_map_.end()) | 210 if (iter == render_view_host_map_.end()) |
202 return NULL; | 211 return NULL; |
203 RenderViewHostRefCount rvh_refcount = iter->second; | 212 return iter->second; |
204 return rvh_refcount.first; | |
205 } | 213 } |
206 | 214 |
207 void FrameTree::RegisterRenderFrameHost( | 215 void FrameTree::RegisterRenderFrameHost( |
208 RenderFrameHostImpl* render_frame_host) { | 216 RenderFrameHostImpl* render_frame_host) { |
209 SiteInstance* site_instance = | 217 SiteInstance* site_instance = |
210 render_frame_host->render_view_host()->GetSiteInstance(); | 218 render_frame_host->render_view_host()->GetSiteInstance(); |
211 RenderViewHostMap::iterator iter = | 219 RenderViewHostMap::iterator iter = |
212 render_view_host_map_.find(site_instance->GetId()); | 220 render_view_host_map_.find(site_instance->GetId()); |
213 CHECK(iter != render_view_host_map_.end()); | 221 CHECK(iter != render_view_host_map_.end()); |
214 | 222 |
215 // Increment the refcount. | 223 iter->second->increment_ref_count(); |
216 CHECK_GE(iter->second.second, 0); | |
217 iter->second.second++; | |
218 } | 224 } |
219 | 225 |
220 void FrameTree::UnregisterRenderFrameHost( | 226 void FrameTree::UnregisterRenderFrameHost( |
221 RenderFrameHostImpl* render_frame_host) { | 227 RenderFrameHostImpl* render_frame_host) { |
222 SiteInstance* site_instance = | 228 SiteInstance* site_instance = |
223 render_frame_host->render_view_host()->GetSiteInstance(); | 229 render_frame_host->render_view_host()->GetSiteInstance(); |
| 230 int32 site_instance_id = site_instance->GetId(); |
224 RenderViewHostMap::iterator iter = | 231 RenderViewHostMap::iterator iter = |
225 render_view_host_map_.find(site_instance->GetId()); | 232 render_view_host_map_.find(site_instance_id); |
226 CHECK(iter != render_view_host_map_.end()); | 233 if (iter != render_view_host_map_.end() && |
227 | 234 iter->second == render_frame_host->render_view_host()) { |
228 // Decrement the refcount and shutdown the RenderViewHost if no one else is | 235 // Decrement the refcount and shutdown the RenderViewHost if no one else is |
229 // using it. | 236 // using it. |
230 CHECK_GT(iter->second.second, 0); | 237 CHECK_GT(iter->second->ref_count(), 0); |
231 iter->second.second--; | 238 iter->second->decrement_ref_count(); |
232 if (iter->second.second == 0) { | 239 if (iter->second->ref_count() == 0) { |
233 iter->second.first->Shutdown(); | 240 iter->second->Shutdown(); |
234 render_view_host_map_.erase(iter); | 241 render_view_host_map_.erase(iter); |
| 242 } |
| 243 } else { |
| 244 // The RenderViewHost should be in the list of RenderViewHosts pending |
| 245 // shutdown. |
| 246 bool render_view_host_found = false; |
| 247 std::pair<RenderViewHostMultiMap::iterator, |
| 248 RenderViewHostMultiMap::iterator> result = |
| 249 render_view_host_pending_shutdown_map_.equal_range(site_instance_id); |
| 250 for (RenderViewHostMultiMap::iterator multi_iter = result.first; |
| 251 multi_iter != result.second; |
| 252 ++multi_iter) { |
| 253 if (multi_iter->second != render_frame_host->render_view_host()) |
| 254 continue; |
| 255 render_view_host_found = true; |
| 256 // Decrement the refcount and shutdown the RenderViewHost if no one else |
| 257 // is using it. |
| 258 CHECK_GT(multi_iter->second->ref_count(), 0); |
| 259 multi_iter->second->decrement_ref_count(); |
| 260 if (multi_iter->second->ref_count() == 0) { |
| 261 multi_iter->second->Shutdown(); |
| 262 render_view_host_pending_shutdown_map_.erase(multi_iter); |
| 263 } |
| 264 break; |
| 265 } |
| 266 CHECK(render_view_host_found); |
235 } | 267 } |
236 } | 268 } |
237 | 269 |
238 FrameTreeNode* FrameTree::FindByFrameID(int64 frame_id) { | 270 FrameTreeNode* FrameTree::FindByFrameID(int64 frame_id) { |
239 FrameTreeNode* node = NULL; | 271 FrameTreeNode* node = NULL; |
240 ForEach(base::Bind(&FrameTreeNodeForFrameId, frame_id, &node)); | 272 ForEach(base::Bind(&FrameTreeNodeForFrameId, frame_id, &node)); |
241 return node; | 273 return node; |
242 } | 274 } |
243 | 275 |
244 } // namespace content | 276 } // namespace content |
OLD | NEW |