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

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

Issue 782093002: Ensure that before creating proxy of site A, RVH of site A is initialized. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync again Created 5 years, 11 months 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
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/render_frame_host_manager.h" 5 #include "content/browser/frame_host/render_frame_host_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 pending_render_frame_host_->DisownOpener(); 495 pending_render_frame_host_->DisownOpener();
496 } 496 }
497 } 497 }
498 498
499 void RenderFrameHostManager::RendererProcessClosing( 499 void RenderFrameHostManager::RendererProcessClosing(
500 RenderProcessHost* render_process_host) { 500 RenderProcessHost* render_process_host) {
501 // Remove any swapped out RVHs from this process, so that we don't try to 501 // Remove any swapped out RVHs from this process, so that we don't try to
502 // swap them back in while the process is exiting. Start by finding them, 502 // swap them back in while the process is exiting. Start by finding them,
503 // since there could be more than one. 503 // since there could be more than one.
504 std::list<int> ids_to_remove; 504 std::list<int> ids_to_remove;
505 // Do not remove proxies in the dead process that still have active frame
506 // count though, we just reset them to be uninitialized.
507 std::list<int> ids_to_keep;
505 for (RenderFrameProxyHostMap::iterator iter = proxy_hosts_.begin(); 508 for (RenderFrameProxyHostMap::iterator iter = proxy_hosts_.begin();
506 iter != proxy_hosts_.end(); 509 iter != proxy_hosts_.end();
507 ++iter) { 510 ++iter) {
508 if (iter->second->GetProcess() == render_process_host) 511 RenderFrameProxyHost* proxy = iter->second;
512 if (proxy->GetProcess() != render_process_host)
513 continue;
514
515 if (static_cast<SiteInstanceImpl*>(proxy->GetSiteInstance())
516 ->active_frame_count() >= 1U) {
517 ids_to_keep.push_back(iter->first);
518 } else {
509 ids_to_remove.push_back(iter->first); 519 ids_to_remove.push_back(iter->first);
520 }
510 } 521 }
511 522
512 // Now delete them. 523 // Now delete them.
513 while (!ids_to_remove.empty()) { 524 while (!ids_to_remove.empty()) {
514 delete proxy_hosts_[ids_to_remove.back()]; 525 delete proxy_hosts_[ids_to_remove.back()];
515 proxy_hosts_.erase(ids_to_remove.back()); 526 proxy_hosts_.erase(ids_to_remove.back());
516 ids_to_remove.pop_back(); 527 ids_to_remove.pop_back();
517 } 528 }
529
530 while (!ids_to_keep.empty()) {
531 frame_tree_node_->frame_tree()->ForEach(
532 base::Bind(
533 &RenderFrameHostManager::ResetProxiesInSiteInstanceForNewProcess,
534 ids_to_keep.back()));
535 ids_to_keep.pop_back();
536 }
518 } 537 }
519 538
520 void RenderFrameHostManager::SwapOutOldFrame( 539 void RenderFrameHostManager::SwapOutOldFrame(
521 scoped_ptr<RenderFrameHostImpl> old_render_frame_host) { 540 scoped_ptr<RenderFrameHostImpl> old_render_frame_host) {
522 TRACE_EVENT1("navigation", "RenderFrameHostManager::SwapOutOldFrame", 541 TRACE_EVENT1("navigation", "RenderFrameHostManager::SwapOutOldFrame",
523 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); 542 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id());
524 543
525 // Tell the renderer to suppress any further modal dialogs so that we can swap 544 // Tell the renderer to suppress any further modal dialogs so that we can swap
526 // it out. This must be done before canceling any current dialog, in case 545 // it out. This must be done before canceling any current dialog, in case
527 // there is a loop creating additional dialogs. 546 // there is a loop creating additional dialogs.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // Otherwise there are active views and we need a proxy for the old RFH. 581 // Otherwise there are active views and we need a proxy for the old RFH.
563 // (There should not be one yet.) 582 // (There should not be one yet.)
564 CHECK(!GetRenderFrameProxyHost(old_render_frame_host->GetSiteInstance())); 583 CHECK(!GetRenderFrameProxyHost(old_render_frame_host->GetSiteInstance()));
565 RenderFrameProxyHost* proxy = new RenderFrameProxyHost( 584 RenderFrameProxyHost* proxy = new RenderFrameProxyHost(
566 old_render_frame_host->GetSiteInstance(), frame_tree_node_); 585 old_render_frame_host->GetSiteInstance(), frame_tree_node_);
567 CHECK(proxy_hosts_.insert(std::make_pair(old_site_instance_id, proxy)).second) 586 CHECK(proxy_hosts_.insert(std::make_pair(old_site_instance_id, proxy)).second)
568 << "Inserting a duplicate item."; 587 << "Inserting a duplicate item.";
569 588
570 // Tell the old RenderFrameHost to swap out and be replaced by the proxy. 589 // Tell the old RenderFrameHost to swap out and be replaced by the proxy.
571 old_render_frame_host->SwapOut(proxy, true); 590 old_render_frame_host->SwapOut(proxy, true);
591 // SwapOut creates a RenderFrameProxy, so set the proxy to be initialized.
592 proxy->set_render_frame_proxy_created(true);
572 593
573 bool is_main_frame = frame_tree_node_->IsMainFrame(); 594 bool is_main_frame = frame_tree_node_->IsMainFrame();
574 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 595 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
575 switches::kSitePerProcess) && 596 switches::kSitePerProcess) &&
576 !is_main_frame) { 597 !is_main_frame) {
577 // In --site-per-process, subframes delete their RFH rather than storing it 598 // In --site-per-process, subframes delete their RFH rather than storing it
578 // in the proxy. Schedule it for deletion once the SwapOutACK comes in. 599 // in the proxy. Schedule it for deletion once the SwapOutACK comes in.
579 // TODO(creis): This will be the default when we remove swappedout://. 600 // TODO(creis): This will be the default when we remove swappedout://.
580 MoveToPendingDeleteHosts(old_render_frame_host.Pass()); 601 MoveToPendingDeleteHosts(old_render_frame_host.Pass());
581 } else { 602 } else {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 proxy->PassFrameHostOwnership(); 827 proxy->PassFrameHostOwnership();
807 node->render_manager()->MoveToPendingDeleteHosts(swapped_out_rfh.Pass()); 828 node->render_manager()->MoveToPendingDeleteHosts(swapped_out_rfh.Pass());
808 } 829 }
809 delete proxy; 830 delete proxy;
810 node->render_manager()->proxy_hosts_.erase(site_instance_id); 831 node->render_manager()->proxy_hosts_.erase(site_instance_id);
811 } 832 }
812 833
813 return true; 834 return true;
814 } 835 }
815 836
837 // static.
838 bool RenderFrameHostManager::ResetProxiesInSiteInstanceForNewProcess(
839 int32 site_instance_id,
840 FrameTreeNode* node) {
841 RenderFrameProxyHostMap::iterator iter =
842 node->render_manager()->proxy_hosts_.find(site_instance_id);
843 if (iter != node->render_manager()->proxy_hosts_.end())
844 iter->second->set_render_frame_proxy_created(false);
845
846 return true;
847 }
848
816 bool RenderFrameHostManager::ShouldTransitionCrossSite() { 849 bool RenderFrameHostManager::ShouldTransitionCrossSite() {
817 // False in the single-process mode, as it makes RVHs to accumulate 850 // False in the single-process mode, as it makes RVHs to accumulate
818 // in swapped_out_hosts_. 851 // in swapped_out_hosts_.
819 // True if we are using process-per-site-instance (default) or 852 // True if we are using process-per-site-instance (default) or
820 // process-per-site (kProcessPerSite). 853 // process-per-site (kProcessPerSite).
821 return !base::CommandLine::ForCurrentProcess()->HasSwitch( 854 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
822 switches::kSingleProcess) && 855 switches::kSingleProcess) &&
823 !base::CommandLine::ForCurrentProcess()->HasSwitch( 856 !base::CommandLine::ForCurrentProcess()->HasSwitch(
824 switches::kProcessPerTab); 857 switches::kProcessPerTab);
825 } 858 }
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); 1406 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance);
1374 if (proxy) 1407 if (proxy)
1375 return proxy->GetRoutingID(); 1408 return proxy->GetRoutingID();
1376 1409
1377 proxy = new RenderFrameProxyHost(instance, frame_tree_node_); 1410 proxy = new RenderFrameProxyHost(instance, frame_tree_node_);
1378 proxy_hosts_[instance->GetId()] = proxy; 1411 proxy_hosts_[instance->GetId()] = proxy;
1379 proxy->InitRenderFrameProxy(); 1412 proxy->InitRenderFrameProxy();
1380 return proxy->GetRoutingID(); 1413 return proxy->GetRoutingID();
1381 } 1414 }
1382 1415
1416 void RenderFrameHostManager::EnsureRenderViewInitialized(
1417 FrameTreeNode* source,
1418 RenderViewHostImpl* render_view_host,
1419 SiteInstance* instance) {
1420 DCHECK(frame_tree_node_->IsMainFrame());
1421
1422 if (render_view_host->IsRenderViewLive())
1423 return;
1424
1425 // Recreate the opener chain.
1426 int opener_route_id =
1427 delegate_->CreateOpenerRenderViewsForRenderManager(instance);
1428 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance);
1429 DCHECK(proxy);
nasko 2015/01/20 23:51:23 nit: no need for DCHECK, it will crash on the next
lazyboy 2015/01/21 18:52:14 Done.
1430 InitRenderView(render_view_host, opener_route_id, proxy->GetRoutingID(),
1431 source->IsMainFrame());
1432 }
1433
1383 bool RenderFrameHostManager::InitRenderView( 1434 bool RenderFrameHostManager::InitRenderView(
1384 RenderViewHostImpl* render_view_host, 1435 RenderViewHostImpl* render_view_host,
1385 int opener_route_id, 1436 int opener_route_id,
1386 int proxy_routing_id, 1437 int proxy_routing_id,
1387 bool for_main_frame_navigation) { 1438 bool for_main_frame_navigation) {
1388 // We may have initialized this RenderViewHost for another RenderFrameHost. 1439 // We may have initialized this RenderViewHost for another RenderFrameHost.
1389 if (render_view_host->IsRenderViewLive()) 1440 if (render_view_host->IsRenderViewLive())
1390 return true; 1441 return true;
1391 1442
1392 // If the ongoing navigation is to a WebUI and the RenderView is not in a 1443 // If the ongoing navigation is to a WebUI and the RenderView is not in a
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 // the proxy it is replacing, so that it can fully initialize itself. 1485 // the proxy it is replacing, so that it can fully initialize itself.
1435 // NOTE: This is the only time that a RenderFrameProxyHost can be in the same 1486 // NOTE: This is the only time that a RenderFrameProxyHost can be in the same
1436 // SiteInstance as its RenderFrameHost. This is only the case until the 1487 // SiteInstance as its RenderFrameHost. This is only the case until the
1437 // RenderFrameHost commits, at which point it will replace and delete the 1488 // RenderFrameHost commits, at which point it will replace and delete the
1438 // RenderFrameProxyHost. 1489 // RenderFrameProxyHost.
1439 RenderFrameProxyHost* existing_proxy = 1490 RenderFrameProxyHost* existing_proxy =
1440 GetRenderFrameProxyHost(render_frame_host->GetSiteInstance()); 1491 GetRenderFrameProxyHost(render_frame_host->GetSiteInstance());
1441 if (existing_proxy) { 1492 if (existing_proxy) {
1442 proxy_routing_id = existing_proxy->GetRoutingID(); 1493 proxy_routing_id = existing_proxy->GetRoutingID();
1443 CHECK_NE(proxy_routing_id, MSG_ROUTING_NONE); 1494 CHECK_NE(proxy_routing_id, MSG_ROUTING_NONE);
1495 if (!existing_proxy->IsRenderFrameProxyLive())
1496 existing_proxy->InitRenderFrameProxy();
1444 } 1497 }
1445 return delegate_->CreateRenderFrameForRenderManager(render_frame_host, 1498 return delegate_->CreateRenderFrameForRenderManager(render_frame_host,
1446 parent_routing_id, 1499 parent_routing_id,
1447 proxy_routing_id); 1500 proxy_routing_id);
1448 } 1501 }
1449 1502
1450 int RenderFrameHostManager::GetRoutingIdForSiteInstance( 1503 int RenderFrameHostManager::GetRoutingIdForSiteInstance(
1451 SiteInstance* site_instance) { 1504 SiteInstance* site_instance) {
1452 if (render_frame_host_->GetSiteInstance() == site_instance) 1505 if (render_frame_host_->GetSiteInstance() == site_instance)
1453 return render_frame_host_->GetRoutingID(); 1506 return render_frame_host_->GetRoutingID();
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 void RenderFrameHostManager::DeleteRenderFrameProxyHost( 1923 void RenderFrameHostManager::DeleteRenderFrameProxyHost(
1871 SiteInstance* instance) { 1924 SiteInstance* instance) {
1872 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); 1925 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId());
1873 if (iter != proxy_hosts_.end()) { 1926 if (iter != proxy_hosts_.end()) {
1874 delete iter->second; 1927 delete iter->second;
1875 proxy_hosts_.erase(iter); 1928 proxy_hosts_.erase(iter);
1876 } 1929 }
1877 } 1930 }
1878 1931
1879 } // namespace content 1932 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698