Skip to content

Commit

Permalink
Don't add keep-alives for apps after the app keep-alive service has s…
Browse files Browse the repository at this point in the history
…hut 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
  • Loading branch information
sammc@chromium.org committed Nov 7, 2013
1 parent 6a6269c commit b7ebe4d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apps/app_keep_alive_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Profile*>(context));
app_lifetime_monitor->AddObserver(this);
Expand All @@ -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)
Expand All @@ -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();

Expand Down
1 change: 1 addition & 0 deletions apps/app_keep_alive_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AppKeepAliveService : public BrowserContextKeyedService,
private:
content::BrowserContext* context_;
std::set<std::string> running_apps_;
bool shut_down_;

DISALLOW_COPY_AND_ASSIGN(AppKeepAliveService);
};
Expand Down
8 changes: 8 additions & 0 deletions apps/app_keep_alive_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit b7ebe4d

Please sign in to comment.