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/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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 | 644 |
645 // If the old RFH is not live, just return as there is no further work to do. | 645 // If the old RFH is not live, just return as there is no further work to do. |
646 // It will be deleted and there will be no proxy created. | 646 // It will be deleted and there will be no proxy created. |
647 if (!old_render_frame_host->IsRenderFrameLive()) | 647 if (!old_render_frame_host->IsRenderFrameLive()) |
648 return; | 648 return; |
649 | 649 |
650 // If there are no active frames besides this one, we can delete the old | 650 // If there are no active frames besides this one, we can delete the old |
651 // RenderFrameHost once it runs its unload handler, without replacing it with | 651 // RenderFrameHost once it runs its unload handler, without replacing it with |
652 // a proxy. | 652 // a proxy. |
653 if (old_render_frame_host->GetSiteInstance()->active_frame_count() <= 1) { | 653 if (old_render_frame_host->GetSiteInstance()->active_frame_count() <= 1) { |
654 // Tell the old RenderFrameHost to swap out, with no proxy to replace it. | 654 // Tell the old RenderFrameHost to swap out, with no proxy to replace it and |
655 // put it on the pending deletion list. It will be deleted when its SwapOut | |
656 // ACK is received, or when the timer times out, or when the RFHM itself is | |
657 // deleted (whichever comes first). | |
655 old_render_frame_host->SwapOut(nullptr, true); | 658 old_render_frame_host->SwapOut(nullptr, true); |
656 MoveToPendingDeleteHosts(std::move(old_render_frame_host)); | 659 pending_delete_hosts_.push_back(std::move(old_render_frame_host)); |
657 return; | 660 return; |
658 } | 661 } |
659 | 662 |
660 // Otherwise there are active views and we need a proxy for the old RFH. | 663 // Otherwise there are active views and we need a proxy for the old RFH. |
661 // (There should not be one yet.) | 664 // (There should not be one yet.) |
662 RenderFrameProxyHost* proxy = | 665 RenderFrameProxyHost* proxy = |
663 CreateRenderFrameProxyHost(old_render_frame_host->GetSiteInstance(), | 666 CreateRenderFrameProxyHost(old_render_frame_host->GetSiteInstance(), |
664 old_render_frame_host->render_view_host()); | 667 old_render_frame_host->render_view_host()); |
665 | 668 |
666 // Tell the old RenderFrameHost to swap out and be replaced by the proxy. | 669 // Tell the old RenderFrameHost to swap out and be replaced by the proxy. |
667 old_render_frame_host->SwapOut(proxy, true); | 670 old_render_frame_host->SwapOut(proxy, true); |
668 | 671 |
669 // SwapOut creates a RenderFrameProxy, so set the proxy to be initialized. | 672 // SwapOut creates a RenderFrameProxy, so set the proxy to be initialized. |
670 proxy->set_render_frame_proxy_created(true); | 673 proxy->set_render_frame_proxy_created(true); |
671 | 674 |
672 MoveToPendingDeleteHosts(std::move(old_render_frame_host)); | 675 // |old_render_frame_host| will be deleted when its SwapOut ACK is received, |
676 // or when the timer times out, or when the RFHM itself is deleted (whichever | |
677 // comes first). | |
678 pending_delete_hosts_.push_back(std::move(old_render_frame_host)); | |
alexmos
2016/04/18 20:48:05
nit: instead of repeating the comment, I'm curious
nasko
2016/04/18 22:00:16
Good idea! Done.
| |
673 } | 679 } |
674 | 680 |
675 void RenderFrameHostManager::DiscardUnusedFrame( | 681 void RenderFrameHostManager::DiscardUnusedFrame( |
676 std::unique_ptr<RenderFrameHostImpl> render_frame_host) { | 682 std::unique_ptr<RenderFrameHostImpl> render_frame_host) { |
677 // TODO(carlosk): this code is very similar to what can be found in | 683 // TODO(carlosk): this code is very similar to what can be found in |
678 // SwapOutOldFrame and we should see that these are unified at some point. | 684 // SwapOutOldFrame and we should see that these are unified at some point. |
679 | 685 |
680 // If the SiteInstance for the pending RFH is being used by others don't | 686 // If the SiteInstance for the pending RFH is being used by others don't |
681 // delete the RFH. Just swap it out and it can be reused at a later point. | 687 // delete the RFH. Just swap it out and it can be reused at a later point. |
682 // In --site-per-process, RenderFrameHosts are not kept around and are | 688 // In --site-per-process, RenderFrameHosts are not kept around and are |
(...skipping 11 matching lines...) Expand all Loading... | |
694 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance); | 700 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance); |
695 if (!proxy) { | 701 if (!proxy) { |
696 proxy = CreateRenderFrameProxyHost(site_instance, | 702 proxy = CreateRenderFrameProxyHost(site_instance, |
697 render_frame_host->render_view_host()); | 703 render_frame_host->render_view_host()); |
698 } | 704 } |
699 } | 705 } |
700 | 706 |
701 render_frame_host.reset(); | 707 render_frame_host.reset(); |
702 } | 708 } |
703 | 709 |
704 void RenderFrameHostManager::MoveToPendingDeleteHosts( | |
705 std::unique_ptr<RenderFrameHostImpl> render_frame_host) { | |
706 // |render_frame_host| will be deleted when its SwapOut ACK is received, or | |
707 // when the timer times out, or when the RFHM itself is deleted (whichever | |
708 // comes first). | |
709 pending_delete_hosts_.push_back(std::move(render_frame_host)); | |
710 } | |
711 | |
712 bool RenderFrameHostManager::IsViewPendingDeletion( | 710 bool RenderFrameHostManager::IsViewPendingDeletion( |
713 RenderViewHostImpl* render_view_host) { | 711 RenderViewHostImpl* render_view_host) { |
714 // Only safe to call this on the main frame. | 712 // Only safe to call this on the main frame. |
715 CHECK(frame_tree_node_->IsMainFrame()); | 713 CHECK(frame_tree_node_->IsMainFrame()); |
716 | 714 |
717 // The view is not pending deletion if more than one frame or proxy references | 715 // The view is not pending deletion if more than one frame or proxy references |
718 // it. | 716 // it. |
719 if (render_view_host->ref_count() > 1) | 717 if (render_view_host->ref_count() > 1) |
720 return false; | 718 return false; |
721 | 719 |
(...skipping 1859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2581 resolved_url)) { | 2579 resolved_url)) { |
2582 DCHECK(!dest_instance || | 2580 DCHECK(!dest_instance || |
2583 dest_instance == render_frame_host_->GetSiteInstance()); | 2581 dest_instance == render_frame_host_->GetSiteInstance()); |
2584 return false; | 2582 return false; |
2585 } | 2583 } |
2586 | 2584 |
2587 return true; | 2585 return true; |
2588 } | 2586 } |
2589 | 2587 |
2590 } // namespace content | 2588 } // namespace content |
OLD | NEW |