From b7ebe4de82381e106ec01490c6f60a4d6b5ae3ea Mon Sep 17 00:00:00 2001 From: "sammc@chromium.org" Date: Thu, 7 Nov 2013 01:28:45 +0000 Subject: [PATCH] Don't add keep-alives for apps after the app keep-alive service has shut down. BUG=314729 Review URL: https://codereview.chromium.org/60193005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233462 0039d316-1c4b-4281-b951-d872f2087c98 --- apps/app_keep_alive_service.cc | 5 +++-- apps/app_keep_alive_service.h | 1 + apps/app_keep_alive_service_unittest.cc | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/app_keep_alive_service.cc b/apps/app_keep_alive_service.cc index 825e0bb3f213e6..73bd63acf390d8 100644 --- a/apps/app_keep_alive_service.cc +++ b/apps/app_keep_alive_service.cc @@ -13,7 +13,7 @@ namespace apps { AppKeepAliveService::AppKeepAliveService(content::BrowserContext* context) - : context_(context) { + : context_(context), shut_down_(false) { AppLifetimeMonitor* app_lifetime_monitor = AppLifetimeMonitorFactory::GetForProfile(static_cast(context)); app_lifetime_monitor->AddObserver(this); @@ -30,7 +30,7 @@ void AppKeepAliveService::Shutdown() { void AppKeepAliveService::OnAppStart(Profile* profile, const std::string& app_id) { - if (profile != context_) + if (profile != context_ || shut_down_) return; if (running_apps_.insert(app_id).second) @@ -53,6 +53,7 @@ void AppKeepAliveService::OnAppDeactivated(Profile* profile, const std::string& app_id) {} void AppKeepAliveService::OnChromeTerminating() { + shut_down_ = true; size_t keep_alives = running_apps_.size(); running_apps_.clear(); diff --git a/apps/app_keep_alive_service.h b/apps/app_keep_alive_service.h index 563a953f59267b..d3fecf9755ee29 100644 --- a/apps/app_keep_alive_service.h +++ b/apps/app_keep_alive_service.h @@ -29,6 +29,7 @@ class AppKeepAliveService : public BrowserContextKeyedService, private: content::BrowserContext* context_; std::set running_apps_; + bool shut_down_; DISALLOW_COPY_AND_ASSIGN(AppKeepAliveService); }; diff --git a/apps/app_keep_alive_service_unittest.cc b/apps/app_keep_alive_service_unittest.cc index 3478162e8b577b..9f08d76ef39832 100644 --- a/apps/app_keep_alive_service_unittest.cc +++ b/apps/app_keep_alive_service_unittest.cc @@ -78,6 +78,14 @@ TEST_F(AppKeepAliveServiceUnitTest, StartMoreThanOnce) { EXPECT_FALSE(chrome::WillKeepAlive()); } +// Test that OnAppStart is ignored after the service has been shut down. +TEST_F(AppKeepAliveServiceUnitTest, StartAfterShutdown) { + ASSERT_FALSE(chrome::WillKeepAlive()); + service_->Shutdown(); + service_->OnAppStart(&profile_, "foo"); + EXPECT_FALSE(chrome::WillKeepAlive()); +} + TEST_F(AppKeepAliveServiceUnitTest, MultipleApps) { ASSERT_FALSE(chrome::WillKeepAlive()); service_->OnAppStart(&profile_, "foo");