Commit b7ebe4de authored by sammc@chromium.org's avatar sammc@chromium.org

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
parent 6a6269c7
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
namespace apps { namespace apps {
AppKeepAliveService::AppKeepAliveService(content::BrowserContext* context) AppKeepAliveService::AppKeepAliveService(content::BrowserContext* context)
: context_(context) { : context_(context), shut_down_(false) {
AppLifetimeMonitor* app_lifetime_monitor = AppLifetimeMonitor* app_lifetime_monitor =
AppLifetimeMonitorFactory::GetForProfile(static_cast<Profile*>(context)); AppLifetimeMonitorFactory::GetForProfile(static_cast<Profile*>(context));
app_lifetime_monitor->AddObserver(this); app_lifetime_monitor->AddObserver(this);
...@@ -30,7 +30,7 @@ void AppKeepAliveService::Shutdown() { ...@@ -30,7 +30,7 @@ void AppKeepAliveService::Shutdown() {
void AppKeepAliveService::OnAppStart(Profile* profile, void AppKeepAliveService::OnAppStart(Profile* profile,
const std::string& app_id) { const std::string& app_id) {
if (profile != context_) if (profile != context_ || shut_down_)
return; return;
if (running_apps_.insert(app_id).second) if (running_apps_.insert(app_id).second)
...@@ -53,6 +53,7 @@ void AppKeepAliveService::OnAppDeactivated(Profile* profile, ...@@ -53,6 +53,7 @@ void AppKeepAliveService::OnAppDeactivated(Profile* profile,
const std::string& app_id) {} const std::string& app_id) {}
void AppKeepAliveService::OnChromeTerminating() { void AppKeepAliveService::OnChromeTerminating() {
shut_down_ = true;
size_t keep_alives = running_apps_.size(); size_t keep_alives = running_apps_.size();
running_apps_.clear(); running_apps_.clear();
......
...@@ -29,6 +29,7 @@ class AppKeepAliveService : public BrowserContextKeyedService, ...@@ -29,6 +29,7 @@ class AppKeepAliveService : public BrowserContextKeyedService,
private: private:
content::BrowserContext* context_; content::BrowserContext* context_;
std::set<std::string> running_apps_; std::set<std::string> running_apps_;
bool shut_down_;
DISALLOW_COPY_AND_ASSIGN(AppKeepAliveService); DISALLOW_COPY_AND_ASSIGN(AppKeepAliveService);
}; };
......
...@@ -78,6 +78,14 @@ TEST_F(AppKeepAliveServiceUnitTest, StartMoreThanOnce) { ...@@ -78,6 +78,14 @@ TEST_F(AppKeepAliveServiceUnitTest, StartMoreThanOnce) {
EXPECT_FALSE(chrome::WillKeepAlive()); 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) { TEST_F(AppKeepAliveServiceUnitTest, MultipleApps) {
ASSERT_FALSE(chrome::WillKeepAlive()); ASSERT_FALSE(chrome::WillKeepAlive());
service_->OnAppStart(&profile_, "foo"); service_->OnAppStart(&profile_, "foo");
......
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