Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 } | 296 } |
| 297 | 297 |
| 298 RenderViewHostImpl* FrameTree::CreateRenderViewHost( | 298 RenderViewHostImpl* FrameTree::CreateRenderViewHost( |
| 299 SiteInstance* site_instance, | 299 SiteInstance* site_instance, |
| 300 int32_t routing_id, | 300 int32_t routing_id, |
| 301 int32_t main_frame_routing_id, | 301 int32_t main_frame_routing_id, |
| 302 bool swapped_out, | 302 bool swapped_out, |
| 303 bool hidden) { | 303 bool hidden) { |
| 304 RenderViewHostMap::iterator iter = | 304 RenderViewHostMap::iterator iter = |
| 305 render_view_host_map_.find(site_instance->GetId()); | 305 render_view_host_map_.find(site_instance->GetId()); |
| 306 if (iter != render_view_host_map_.end()) { | 306 if (iter != render_view_host_map_.end()) |
| 307 // If a RenderViewHost is pending deletion for this |site_instance|, it | 307 return iter->second; |
| 308 // shouldn't be reused, so put it in the map of RenderViewHosts pending | 308 |
| 309 // shutdown. Otherwise, return the existing RenderViewHost for the | |
| 310 // SiteInstance. Note that if swapped-out is forbidden, the | |
| 311 // RenderViewHost's main frame has already been cleared, so we cannot rely | |
| 312 // on checking whether the main frame is pending deletion. | |
| 313 if (root_->render_manager()->IsViewPendingDeletion(iter->second)) { | |
| 314 render_view_host_pending_shutdown_map_.insert( | |
| 315 std::make_pair(site_instance->GetId(), iter->second)); | |
| 316 render_view_host_map_.erase(iter); | |
| 317 } else { | |
| 318 return iter->second; | |
| 319 } | |
| 320 } | |
| 321 RenderViewHostImpl* rvh = | 309 RenderViewHostImpl* rvh = |
| 322 static_cast<RenderViewHostImpl*>(RenderViewHostFactory::Create( | 310 static_cast<RenderViewHostImpl*>(RenderViewHostFactory::Create( |
| 323 site_instance, render_view_delegate_, render_widget_delegate_, | 311 site_instance, render_view_delegate_, render_widget_delegate_, |
| 324 routing_id, main_frame_routing_id, swapped_out, hidden)); | 312 routing_id, main_frame_routing_id, swapped_out, hidden)); |
| 325 | 313 |
| 326 render_view_host_map_[site_instance->GetId()] = rvh; | 314 render_view_host_map_[site_instance->GetId()] = rvh; |
| 327 return rvh; | 315 return rvh; |
| 328 } | 316 } |
| 329 | 317 |
| 330 RenderViewHostImpl* FrameTree::GetRenderViewHost(SiteInstance* site_instance) { | 318 RenderViewHostImpl* FrameTree::GetRenderViewHost(SiteInstance* site_instance) { |
| 331 RenderViewHostMap::iterator iter = | 319 RenderViewHostMap::iterator iter = |
| 332 render_view_host_map_.find(site_instance->GetId()); | 320 render_view_host_map_.find(site_instance->GetId()); |
| 333 // Don't return the RVH if it is pending deletion. | 321 if (iter != render_view_host_map_.end()) |
| 334 if (iter != render_view_host_map_.end() && | |
| 335 !root_->render_manager()->IsViewPendingDeletion(iter->second)) { | |
| 336 return iter->second; | 322 return iter->second; |
| 337 } | 323 |
| 338 return nullptr; | 324 return nullptr; |
| 339 } | 325 } |
| 340 | 326 |
| 341 void FrameTree::AddRenderViewHostRef(RenderViewHostImpl* render_view_host) { | 327 void FrameTree::AddRenderViewHostRef(RenderViewHostImpl* render_view_host) { |
| 342 SiteInstance* site_instance = render_view_host->GetSiteInstance(); | 328 SiteInstance* site_instance = render_view_host->GetSiteInstance(); |
| 343 RenderViewHostMap::iterator iter = | 329 RenderViewHostMap::iterator iter = |
| 344 render_view_host_map_.find(site_instance->GetId()); | 330 render_view_host_map_.find(site_instance->GetId()); |
| 345 CHECK(iter != render_view_host_map_.end()); | 331 CHECK(iter != render_view_host_map_.end()); |
| 346 CHECK(iter->second == render_view_host); | 332 CHECK(iter->second == render_view_host); |
| 347 | 333 |
| 348 iter->second->increment_ref_count(); | 334 iter->second->increment_ref_count(); |
| 349 } | 335 } |
| 350 | 336 |
| 351 void FrameTree::ReleaseRenderViewHostRef(RenderViewHostImpl* render_view_host) { | 337 void FrameTree::ReleaseRenderViewHostRef(RenderViewHostImpl* render_view_host) { |
| 352 SiteInstance* site_instance = render_view_host->GetSiteInstance(); | 338 SiteInstance* site_instance = render_view_host->GetSiteInstance(); |
| 353 int32_t site_instance_id = site_instance->GetId(); | 339 int32_t site_instance_id = site_instance->GetId(); |
| 354 RenderViewHostMap::iterator iter = | 340 RenderViewHostMap::iterator iter = |
| 355 render_view_host_map_.find(site_instance_id); | 341 render_view_host_map_.find(site_instance_id); |
| 356 if (iter != render_view_host_map_.end() && iter->second == render_view_host) { | 342 |
| 357 // Decrement the refcount and shutdown the RenderViewHost if no one else is | 343 CHECK(iter != render_view_host_map_.end()); |
|
Charlie Reis
2016/04/22 19:11:33
Would CHECK_NE work?
alexmos
2016/04/25 18:17:07
I had that originally, but that failed to compile
Charlie Reis
2016/04/26 05:06:36
Acknowledged.
| |
| 358 // using it. | 344 CHECK_EQ(iter->second, render_view_host); |
| 359 CHECK_GT(iter->second->ref_count(), 0); | 345 |
| 360 iter->second->decrement_ref_count(); | 346 // Decrement the refcount and shutdown the RenderViewHost if no one else is |
| 361 if (iter->second->ref_count() == 0) { | 347 // using it. |
| 362 iter->second->ShutdownAndDestroy(); | 348 CHECK_GT(iter->second->ref_count(), 0); |
| 363 render_view_host_map_.erase(iter); | 349 iter->second->decrement_ref_count(); |
| 364 } | 350 if (iter->second->ref_count() == 0) { |
| 365 } else { | 351 iter->second->ShutdownAndDestroy(); |
| 366 // The RenderViewHost should be in the list of RenderViewHosts pending | 352 render_view_host_map_.erase(iter); |
| 367 // shutdown. | |
| 368 bool render_view_host_found = false; | |
| 369 std::pair<RenderViewHostMultiMap::iterator, | |
| 370 RenderViewHostMultiMap::iterator> result = | |
| 371 render_view_host_pending_shutdown_map_.equal_range(site_instance_id); | |
| 372 for (RenderViewHostMultiMap::iterator multi_iter = result.first; | |
| 373 multi_iter != result.second; | |
| 374 ++multi_iter) { | |
| 375 if (multi_iter->second != render_view_host) | |
| 376 continue; | |
| 377 render_view_host_found = true; | |
| 378 // Decrement the refcount and shutdown the RenderViewHost if no one else | |
| 379 // is using it. | |
| 380 CHECK_GT(render_view_host->ref_count(), 0); | |
| 381 render_view_host->decrement_ref_count(); | |
| 382 if (render_view_host->ref_count() == 0) { | |
| 383 render_view_host->ShutdownAndDestroy(); | |
| 384 render_view_host_pending_shutdown_map_.erase(multi_iter); | |
| 385 } | |
| 386 break; | |
| 387 } | |
| 388 CHECK(render_view_host_found); | |
| 389 } | 353 } |
| 390 } | 354 } |
| 391 | 355 |
| 392 void FrameTree::FrameRemoved(FrameTreeNode* frame) { | 356 void FrameTree::FrameRemoved(FrameTreeNode* frame) { |
| 393 if (frame->frame_tree_node_id() == focused_frame_tree_node_id_) | 357 if (frame->frame_tree_node_id() == focused_frame_tree_node_id_) |
| 394 focused_frame_tree_node_id_ = -1; | 358 focused_frame_tree_node_id_ = -1; |
| 395 | 359 |
| 396 // No notification for the root frame. | 360 // No notification for the root frame. |
| 397 if (!frame->parent()) { | 361 if (!frame->parent()) { |
| 398 CHECK_EQ(frame, root_); | 362 CHECK_EQ(frame, root_); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 // This is only used to set page-level focus in cross-process subframes, and | 426 // This is only used to set page-level focus in cross-process subframes, and |
| 463 // requests to set focus in main frame's SiteInstance are ignored. | 427 // requests to set focus in main frame's SiteInstance are ignored. |
| 464 if (instance != root_manager->current_frame_host()->GetSiteInstance()) { | 428 if (instance != root_manager->current_frame_host()->GetSiteInstance()) { |
| 465 RenderFrameProxyHost* proxy = | 429 RenderFrameProxyHost* proxy = |
| 466 root_manager->GetRenderFrameProxyHost(instance); | 430 root_manager->GetRenderFrameProxyHost(instance); |
| 467 proxy->Send(new InputMsg_SetFocus(proxy->GetRoutingID(), is_focused)); | 431 proxy->Send(new InputMsg_SetFocus(proxy->GetRoutingID(), is_focused)); |
| 468 } | 432 } |
| 469 } | 433 } |
| 470 | 434 |
| 471 } // namespace content | 435 } // namespace content |
| OLD | NEW |