Commit 3bcb8b87 authored by Arthur Sonzogni's avatar Arthur Sonzogni Committed by Commit Bot

Task manager: Make it work with iframes in pending deletion.

This CL is a sub-part of: [Don't delete subframes on CommitPending]
(https://chromium-review.googlesource.com/c/chromium/src/+/1122629/18)
RenderFrameHosts (subframes) are allowed to stay alive longer in the
background, the time needed for them to execute their unload handler.

The WebContentsTaskProvider needs to stop tracking all the frames in
pending deletion, not only the navigating one, but also its subframes.

Not doing it properly triggers a DCHECK:
---
// Whenever we have a task, we should have a main frame site instance.
DCHECK(tasks_by_frames_.empty() == (main_frame_site_instance_ == nullptr));
---
With tasks_by_frames_ not being empty, but main_frame_site_instance being
null after removing the old_frame in RenderFrameHostChanged.


Bug: 609963
Change-Id: I6e4ad45fb0d47ab378396e9ea1ad97bfc27c9c31
Reviewed-on: https://chromium-review.googlesource.com/c/1163502
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#598732}
parent 7f4f7291
...@@ -71,6 +71,10 @@ class WebContentsEntry : public content::WebContentsObserver { ...@@ -71,6 +71,10 @@ class WebContentsEntry : public content::WebContentsObserver {
// notifies the provider's observer of the tasks removal. // notifies the provider's observer of the tasks removal.
void ClearTaskForFrame(RenderFrameHost* render_frame_host); void ClearTaskForFrame(RenderFrameHost* render_frame_host);
// Same as |ClearTaskForFrame|, but for every descendant of
// |ancestor|.
void ClearTasksForDescendantsOf(RenderFrameHost* ancestor);
// Calls |on_task| for each task managed by this WebContentsEntry. // Calls |on_task| for each task managed by this WebContentsEntry.
void ForEachTask(const base::Callback<void(RendererTask*)>& on_task); void ForEachTask(const base::Callback<void(RendererTask*)>& on_task);
...@@ -164,7 +168,13 @@ void WebContentsEntry::RenderFrameDeleted(RenderFrameHost* render_frame_host) { ...@@ -164,7 +168,13 @@ void WebContentsEntry::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
void WebContentsEntry::RenderFrameHostChanged(RenderFrameHost* old_host, void WebContentsEntry::RenderFrameHostChanged(RenderFrameHost* old_host,
RenderFrameHost* new_host) { RenderFrameHost* new_host) {
DCHECK(new_host->IsCurrent()); DCHECK(new_host->IsCurrent());
// The navigating frame and its subframes are now pending deletion. Stop
// tracking them immediately rather than when they are destroyed. The order of
// deletion is important. The children must be removed first.
ClearTasksForDescendantsOf(old_host);
ClearTaskForFrame(old_host); ClearTaskForFrame(old_host);
CreateTaskForFrame(new_host); CreateTaskForFrame(new_host);
} }
...@@ -358,6 +368,20 @@ void WebContentsEntry::ClearTaskForFrame(RenderFrameHost* render_frame_host) { ...@@ -358,6 +368,20 @@ void WebContentsEntry::ClearTaskForFrame(RenderFrameHost* render_frame_host) {
DCHECK(tasks_by_frames_.empty() == (main_frame_site_instance_ == nullptr)); DCHECK(tasks_by_frames_.empty() == (main_frame_site_instance_ == nullptr));
} }
void WebContentsEntry::ClearTasksForDescendantsOf(RenderFrameHost* ancestor) {
// 1) Collect descendants.
std::vector<RenderFrameHost*> descendants;
for (auto it : tasks_by_frames_) {
RenderFrameHost* frame = it.first;
if (frame->IsDescendantOf(ancestor))
descendants.push_back(frame);
}
// 2) Delete them.
for (RenderFrameHost* rfh : descendants)
ClearTaskForFrame(rfh);
}
void WebContentsEntry::ForEachTask( void WebContentsEntry::ForEachTask(
const base::Callback<void(RendererTask*)>& on_task) { const base::Callback<void(RendererTask*)>& on_task) {
for (const auto& pair : frames_by_site_instance_) { for (const auto& pair : frames_by_site_instance_) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment