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

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

Issue 1886413002: Always swap with a replacement proxy in OnSwapOut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Charlie's comments Created 4 years, 7 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 // Now close any modal dialogs that would prevent us from swapping out. This 638 // Now close any modal dialogs that would prevent us from swapping out. This
639 // must be done separately from SwapOut, so that the ScopedPageLoadDeferrer is 639 // must be done separately from SwapOut, so that the ScopedPageLoadDeferrer is
640 // no longer on the stack when we send the SwapOut message. 640 // no longer on the stack when we send the SwapOut message.
641 delegate_->CancelModalDialogsForRenderManager(); 641 delegate_->CancelModalDialogsForRenderManager();
642 642
643 // If the old RFH is not live, just return as there is no further work to do. 643 // If the old RFH is not live, just return as there is no further work to do.
644 // It will be deleted and there will be no proxy created. 644 // It will be deleted and there will be no proxy created.
645 if (!old_render_frame_host->IsRenderFrameLive()) 645 if (!old_render_frame_host->IsRenderFrameLive())
646 return; 646 return;
647 647
648 // If there are no active frames besides this one, we can delete the old 648 // Create a replacement proxy for the old RenderFrameHost. (There should not
649 // RenderFrameHost once it runs its unload handler, without replacing it with 649 // be one yet.) This is done even if there are no active frames besides this
650 // a proxy. 650 // one to simplify cleanup logic on the renderer side (see
651 if (old_render_frame_host->GetSiteInstance()->active_frame_count() <= 1) { 651 // https://crbug.com/568836 for motivation).
652 // Tell the old RenderFrameHost to swap out, with no proxy to replace it. 652 RenderFrameProxyHost* proxy =
653 old_render_frame_host->SwapOut(nullptr, true); 653 CreateRenderFrameProxyHost(old_render_frame_host->GetSiteInstance(),
654 } else { 654 old_render_frame_host->render_view_host());
655 // Otherwise there are active views and we need a proxy for the old RFH.
656 // (There should not be one yet.)
657 RenderFrameProxyHost* proxy =
658 CreateRenderFrameProxyHost(old_render_frame_host->GetSiteInstance(),
659 old_render_frame_host->render_view_host());
660 655
661 // Tell the old RenderFrameHost to swap out and be replaced by the proxy. 656 // Tell the old RenderFrameHost to swap out and be replaced by the proxy.
662 old_render_frame_host->SwapOut(proxy, true); 657 old_render_frame_host->SwapOut(proxy, true);
663 658
664 // SwapOut creates a RenderFrameProxy, so set the proxy to be initialized. 659 // SwapOut creates a RenderFrameProxy, so set the proxy to be initialized.
665 proxy->set_render_frame_proxy_created(true); 660 proxy->set_render_frame_proxy_created(true);
666 }
667 661
668 // |old_render_frame_host| will be deleted when its SwapOut ACK is received, 662 // |old_render_frame_host| will be deleted when its SwapOut ACK is received,
669 // or when the timer times out, or when the RFHM itself is deleted (whichever 663 // or when the timer times out, or when the RFHM itself is deleted (whichever
670 // comes first). 664 // comes first).
671 pending_delete_hosts_.push_back(std::move(old_render_frame_host)); 665 pending_delete_hosts_.push_back(std::move(old_render_frame_host));
672 } 666 }
673 667
674 void RenderFrameHostManager::DiscardUnusedFrame( 668 void RenderFrameHostManager::DiscardUnusedFrame(
675 std::unique_ptr<RenderFrameHostImpl> render_frame_host) { 669 std::unique_ptr<RenderFrameHostImpl> render_frame_host) {
676 // TODO(carlosk): this code is very similar to what can be found in 670 // TODO(carlosk): this code is very similar to what can be found in
(...skipping 16 matching lines...) Expand all
693 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance); 687 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance);
694 if (!proxy) { 688 if (!proxy) {
695 proxy = CreateRenderFrameProxyHost(site_instance, 689 proxy = CreateRenderFrameProxyHost(site_instance,
696 render_frame_host->render_view_host()); 690 render_frame_host->render_view_host());
697 } 691 }
698 } 692 }
699 693
700 render_frame_host.reset(); 694 render_frame_host.reset();
701 } 695 }
702 696
703 bool RenderFrameHostManager::IsViewPendingDeletion(
704 RenderViewHostImpl* render_view_host) {
705 // Only safe to call this on the main frame.
706 CHECK(frame_tree_node_->IsMainFrame());
707
708 // The view is not pending deletion if more than one frame or proxy references
709 // it.
710 if (render_view_host->ref_count() > 1)
711 return false;
712
713 // If the only thing referencing it is a frame on the pending deletion list,
714 // then this view will go away when the frame goes away.
715 for (const auto& rfh : pending_delete_hosts_) {
716 if (rfh->GetRenderViewHost() == render_view_host)
717 return true;
718 }
719 return false;
720 }
721
722 bool RenderFrameHostManager::DeleteFromPendingList( 697 bool RenderFrameHostManager::DeleteFromPendingList(
723 RenderFrameHostImpl* render_frame_host) { 698 RenderFrameHostImpl* render_frame_host) {
724 for (RFHPendingDeleteList::iterator iter = pending_delete_hosts_.begin(); 699 for (RFHPendingDeleteList::iterator iter = pending_delete_hosts_.begin();
725 iter != pending_delete_hosts_.end(); 700 iter != pending_delete_hosts_.end();
726 iter++) { 701 iter++) {
727 if (iter->get() == render_frame_host) { 702 if (iter->get() == render_frame_host) {
728 pending_delete_hosts_.erase(iter); 703 pending_delete_hosts_.erase(iter);
729 return true; 704 return true;
730 } 705 }
731 } 706 }
(...skipping 1840 matching lines...) Expand 10 before | Expand all | Expand 10 after
2572 resolved_url)) { 2547 resolved_url)) {
2573 DCHECK(!dest_instance || 2548 DCHECK(!dest_instance ||
2574 dest_instance == render_frame_host_->GetSiteInstance()); 2549 dest_instance == render_frame_host_->GetSiteInstance());
2575 return false; 2550 return false;
2576 } 2551 }
2577 2552
2578 return true; 2553 return true;
2579 } 2554 }
2580 2555
2581 } // namespace content 2556 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698