Commit 235b69a5 authored by atwilson@chromium.org's avatar atwilson@chromium.org

Blow away BackgroundContents when RenderView goes away.

Reopening, because this CL broke NoticeNotificationChanges on XP for some reason, so I'm going to undo my (now superfluous) changes to flush the queue in WaitForResourceChange().

BUG=65189
TEST=TaskManagerBrowserTest.KillBGContents

Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=71458

Review URL: http://codereview.chromium.org/6226002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71688 0039d316-1c4b-4281-b951-d872f2087c98
parent 1ab006c2
...@@ -84,6 +84,8 @@ class BackgroundContentsService : private NotificationObserver, ...@@ -84,6 +84,8 @@ class BackgroundContentsService : private NotificationObserver,
TestApplicationIDLinkage); TestApplicationIDLinkage);
FRIEND_TEST_ALL_PREFIXES(TaskManagerBrowserTest, FRIEND_TEST_ALL_PREFIXES(TaskManagerBrowserTest,
NoticeBGContentsChanges); NoticeBGContentsChanges);
FRIEND_TEST_ALL_PREFIXES(TaskManagerBrowserTest,
KillBGContents);
// Registers for various notifications. // Registers for various notifications.
void StartObserving(Profile* profile); void StartObserving(Profile* profile);
......
...@@ -175,6 +175,16 @@ void BackgroundContents::Close(RenderViewHost* render_view_host) { ...@@ -175,6 +175,16 @@ void BackgroundContents::Close(RenderViewHost* render_view_host) {
delete this; delete this;
} }
void BackgroundContents::RenderViewGone(RenderViewHost* rvh,
base::TerminationStatus status,
int error_code) {
// Our RenderView went away, so we should go away also, so killing the process
// via the TaskManager doesn't permanently leave a BackgroundContents hanging
// around the system, blocking future instances from being created
// (http://crbug.com/65189).
delete this;
}
RendererPreferences BackgroundContents::GetRendererPrefs( RendererPreferences BackgroundContents::GetRendererPrefs(
Profile* profile) const { Profile* profile) const {
RendererPreferences preferences; RendererPreferences preferences;
......
...@@ -75,6 +75,9 @@ class BackgroundContents : public RenderViewHostDelegate, ...@@ -75,6 +75,9 @@ class BackgroundContents : public RenderViewHostDelegate,
bool* did_suppress_message); bool* did_suppress_message);
virtual void Close(RenderViewHost* render_view_host); virtual void Close(RenderViewHost* render_view_host);
virtual RendererPreferences GetRendererPrefs(Profile* profile) const; virtual RendererPreferences GetRendererPrefs(Profile* profile) const;
virtual void RenderViewGone(RenderViewHost* rvh,
base::TerminationStatus status,
int error_code);
// RenderViewHostDelegate::View // RenderViewHostDelegate::View
virtual void CreateNewWindow( virtual void CreateNewWindow(
......
...@@ -68,6 +68,24 @@ class ResourceChangeObserver : public TaskManagerModelObserver { ...@@ -68,6 +68,24 @@ class ResourceChangeObserver : public TaskManagerModelObserver {
const int target_resource_count_; const int target_resource_count_;
}; };
// Helper class used to wait for a BackgroundContents to finish loading.
class BackgroundContentsListener : public NotificationObserver {
public:
explicit BackgroundContentsListener(Profile* profile) {
registrar_.Add(this, NotificationType::BACKGROUND_CONTENTS_NAVIGATED,
Source<Profile>(profile));
}
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
// Quit once the BackgroundContents has been loaded.
if (type.value == NotificationType::BACKGROUND_CONTENTS_NAVIGATED)
MessageLoopForUI::current()->Quit();
}
private:
NotificationRegistrar registrar_;
};
} // namespace } // namespace
class TaskManagerBrowserTest : public ExtensionBrowserTest { class TaskManagerBrowserTest : public ExtensionBrowserTest {
...@@ -84,6 +102,12 @@ class TaskManagerBrowserTest : public ExtensionBrowserTest { ...@@ -84,6 +102,12 @@ class TaskManagerBrowserTest : public ExtensionBrowserTest {
ui_test_utils::RunMessageLoop(); ui_test_utils::RunMessageLoop();
model()->RemoveObserver(&observer); model()->RemoveObserver(&observer);
} }
// Wait for any pending BackgroundContents to finish starting up.
void WaitForBackgroundContents() {
BackgroundContentsListener listener(browser()->profile());
ui_test_utils::RunMessageLoop();
}
}; };
// Regression test for http://crbug.com/13361 // Regression test for http://crbug.com/13361
...@@ -149,6 +173,45 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) { ...@@ -149,6 +173,45 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) {
WaitForResourceChange(2); WaitForResourceChange(2);
} }
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) {
EXPECT_EQ(0, model()->ResourceCount());
// Show the task manager. This populates the model, and helps with debugging
// (you see the task manager).
browser()->window()->ShowTaskManager();
// Browser and the New Tab Page.
WaitForResourceChange(2);
// Open a new background contents and make sure we notice that.
GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
FilePath(kTitle1File)));
BackgroundContentsService* service =
browser()->profile()->GetBackgroundContentsService();
string16 application_id(ASCIIToUTF16("test_app_id"));
service->LoadBackgroundContents(browser()->profile(),
url,
ASCIIToUTF16("background_page"),
application_id);
// Wait for the background contents process to finish loading.
WaitForBackgroundContents();
EXPECT_EQ(3, model()->ResourceCount());
// Kill the background contents process and verify that it disappears from the
// model.
bool found = false;
for (int i = 0; i < model()->ResourceCount(); ++i) {
if (model()->IsBackgroundResource(i)) {
TaskManager::GetInstance()->KillProcess(i);
found = true;
break;
}
}
ASSERT_TRUE(found);
WaitForResourceChange(2);
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) {
EXPECT_EQ(0, model()->ResourceCount()); EXPECT_EQ(0, model()->ResourceCount());
......
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