Commit fb8f3ec2 authored by nhiroki@chromium.org's avatar nhiroki@chromium.org

ServiceWorker: Stop a worker thread on unregistration

ServiceWorker is designed to delay stopping the worker thread (30 sec) when all
controlled documents are closed so that the next navigation can save the startup
time.

In the current code, this improvement also applies to the unregistration with no
controllees, but in that case we should immediately stop the thread because the
worker doesn't work anymore.


BUG=392735,393127
TEST=content_unittests --gtest_filter=ServiceWorker*

Review URL: https://codereview.chromium.org/385143002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282922 0039d316-1c4b-4281-b951-d872f2087c98
parent 62d863cf
...@@ -735,8 +735,9 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { ...@@ -735,8 +735,9 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called); ASSERT_TRUE(called);
EXPECT_EQ(ServiceWorkerVersion::RUNNING, // The version should be stopped since there is no controllee after
version->running_status()); // unregistration.
EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status());
EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
} }
...@@ -764,7 +765,9 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { ...@@ -764,7 +765,9 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called); ASSERT_TRUE(called);
EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); // The version should be stopped since there is no controllee after
// unregistration.
EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status());
EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
} }
...@@ -800,12 +803,15 @@ TEST_F(ServiceWorkerJobTest, ...@@ -800,12 +803,15 @@ TEST_F(ServiceWorkerJobTest,
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called); ASSERT_TRUE(called);
// The version should be running since there is still a controllee.
EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status()); EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status());
EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
registration->active_version()->RemoveControllee(host.get()); registration->active_version()->RemoveControllee(host.get());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(ServiceWorkerVersion::RUNNING, version->running_status());
// The version should be stopped since there is no controllee.
EXPECT_EQ(ServiceWorkerVersion::STOPPED, version->running_status());
EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status()); EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version->status());
} }
......
...@@ -389,9 +389,11 @@ void ServiceWorkerVersion::RemoveControllee( ...@@ -389,9 +389,11 @@ void ServiceWorkerVersion::RemoveControllee(
RemoveProcessFromWorker(provider_host->process_id()); RemoveProcessFromWorker(provider_host->process_id());
if (HasControllee()) if (HasControllee())
return; return;
ScheduleStopWorker(); if (is_doomed_) {
if (is_doomed_)
DoomInternal(); DoomInternal();
return;
}
ScheduleStopWorker();
} }
void ServiceWorkerVersion::AddPotentialControllee( void ServiceWorkerVersion::AddPotentialControllee(
...@@ -667,7 +669,9 @@ void ServiceWorkerVersion::ScheduleStopWorker() { ...@@ -667,7 +669,9 @@ void ServiceWorkerVersion::ScheduleStopWorker() {
} }
void ServiceWorkerVersion::DoomInternal() { void ServiceWorkerVersion::DoomInternal() {
DCHECK(!HasControllee());
SetStatus(REDUNDANT); SetStatus(REDUNDANT);
StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
if (!context_) if (!context_)
return; return;
std::vector<ServiceWorkerDatabase::ResourceRecord> resources; std::vector<ServiceWorkerDatabase::ResourceRecord> resources;
......
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