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

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

Issue 166533002: [wip] Introduce SiteInstanceKeepAlive. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 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 | Annotate | Revision Log
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 delegate_->IsHidden()); 114 delegate_->IsHidden());
115 115
116 // Keep track of renderer processes as they start to shut down or are 116 // Keep track of renderer processes as they start to shut down or are
117 // crashed/killed. 117 // crashed/killed.
118 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, 118 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED,
119 NotificationService::AllSources()); 119 NotificationService::AllSources());
120 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, 120 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING,
121 NotificationService::AllSources()); 121 NotificationService::AllSources());
122 } 122 }
123 123
124 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance(
125 int32 site_instance_id) {
126 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts
127 // in the SiteInstance, then tell their respective FrameTrees to remove all
128 // swapped out RenderFrameHosts corresponding to them.
129 // TODO(creis): Replace this with a RenderFrameHostIterator that protects
130 // against use-after-frees if a later element is deleted before getting to it.
131 scoped_ptr<RenderWidgetHostIterator> widgets(
132 RenderWidgetHostImpl::GetAllRenderWidgetHosts());
133 while (RenderWidgetHost* widget = widgets->GetNextHost()) {
134 if (!widget->IsRenderView())
135 continue;
136 RenderViewHostImpl* rvh =
137 static_cast<RenderViewHostImpl*>(RenderViewHost::From(widget));
138 if (site_instance_id == rvh->GetSiteInstance()->GetId()) {
139 // This deletes all RenderFrameHosts using the |rvh|, which then causes
140 // |rvh| to Shutdown.
141 FrameTree* tree = rvh->GetDelegate()->GetFrameTree();
142 tree->ForEach(base::Bind(
143 &RenderFrameHostManager::ClearSwappedOutRFHsInSiteInstance,
144 site_instance_id));
145 }
146 }
147 }
148
124 RenderViewHostImpl* RenderFrameHostManager::current_host() const { 149 RenderViewHostImpl* RenderFrameHostManager::current_host() const {
125 if (!render_frame_host_) 150 if (!render_frame_host_)
126 return NULL; 151 return NULL;
127 return render_frame_host_->render_view_host(); 152 return render_frame_host_->render_view_host();
128 } 153 }
129 154
130 RenderViewHostImpl* RenderFrameHostManager::pending_render_view_host() const { 155 RenderViewHostImpl* RenderFrameHostManager::pending_render_view_host() const {
131 if (!pending_render_frame_host_) 156 if (!pending_render_frame_host_)
132 return NULL; 157 return NULL;
133 return pending_render_frame_host_->render_view_host(); 158 return pending_render_frame_host_->render_view_host();
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 active_view_count()) { 1185 active_view_count()) {
1161 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id); 1186 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id);
1162 // This is deleted while cleaning up the SiteInstance's views. 1187 // This is deleted while cleaning up the SiteInstance's views.
1163 old_render_frame_host = NULL; 1188 old_render_frame_host = NULL;
1164 } 1189 }
1165 } else { 1190 } else {
1166 delete old_render_frame_host; 1191 delete old_render_frame_host;
1167 } 1192 }
1168 } 1193 }
1169 1194
1170 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance(
1171 int32 site_instance_id) {
1172 // First remove any swapped out RFH for this SiteInstance from our own list.
1173 ClearSwappedOutRFHsInSiteInstance(site_instance_id, frame_tree_node_);
sadrul 2014/02/21 03:51:17 This line is removed from the static version. From
1174
1175 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts
1176 // in the SiteInstance, then tell their respective FrameTrees to remove all
1177 // swapped out RenderFrameHosts corresponding to them.
1178 // TODO(creis): Replace this with a RenderFrameHostIterator that protects
1179 // against use-after-frees if a later element is deleted before getting to it.
1180 scoped_ptr<RenderWidgetHostIterator> widgets(
1181 RenderWidgetHostImpl::GetAllRenderWidgetHosts());
1182 while (RenderWidgetHost* widget = widgets->GetNextHost()) {
1183 if (!widget->IsRenderView())
1184 continue;
1185 RenderViewHostImpl* rvh =
1186 static_cast<RenderViewHostImpl*>(RenderViewHost::From(widget));
1187 if (site_instance_id == rvh->GetSiteInstance()->GetId()) {
1188 // This deletes all RenderFrameHosts using the |rvh|, which then causes
1189 // |rvh| to Shutdown.
1190 FrameTree* tree = rvh->GetDelegate()->GetFrameTree();
1191 tree->ForEach(base::Bind(
1192 &RenderFrameHostManager::ClearSwappedOutRFHsInSiteInstance,
1193 site_instance_id));
1194 }
1195 }
1196 }
1197
1198 RenderFrameHostImpl* RenderFrameHostManager::UpdateRendererStateForNavigate( 1195 RenderFrameHostImpl* RenderFrameHostManager::UpdateRendererStateForNavigate(
1199 const NavigationEntryImpl& entry) { 1196 const NavigationEntryImpl& entry) {
1200 // If we are currently navigating cross-process, we want to get back to normal 1197 // If we are currently navigating cross-process, we want to get back to normal
1201 // and then navigate as usual. 1198 // and then navigate as usual.
1202 if (cross_navigation_pending_) { 1199 if (cross_navigation_pending_) {
1203 if (pending_render_frame_host_) 1200 if (pending_render_frame_host_)
1204 CancelPending(); 1201 CancelPending();
1205 cross_navigation_pending_ = false; 1202 cross_navigation_pending_ = false;
1206 } 1203 }
1207 1204
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 SiteInstance* instance) const { 1449 SiteInstance* instance) const {
1453 RenderFrameHostMap::const_iterator iter = 1450 RenderFrameHostMap::const_iterator iter =
1454 swapped_out_hosts_.find(instance->GetId()); 1451 swapped_out_hosts_.find(instance->GetId());
1455 if (iter != swapped_out_hosts_.end()) 1452 if (iter != swapped_out_hosts_.end())
1456 return iter->second; 1453 return iter->second;
1457 1454
1458 return NULL; 1455 return NULL;
1459 } 1456 }
1460 1457
1461 } // namespace content 1458 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698