diff options
author | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-12 16:10:00 +0000 |
---|---|---|
committer | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-12 16:10:00 +0000 |
commit | 97ee4140d7c3c0f9963352793837cb1c24892bbf (patch) | |
tree | 538c76415d7fe9207538be8b07eb776440b62705 /chrome/browser/background | |
parent | d999271074c970f6c126557ab54c74994696dea9 (diff) | |
download | chromium_src-97ee4140d7c3c0f9963352793837cb1c24892bbf.zip chromium_src-97ee4140d7c3c0f9963352793837cb1c24892bbf.tar.gz chromium_src-97ee4140d7c3c0f9963352793837cb1c24892bbf.tar.bz2 |
Properly disable background mode when deleting profiles.
Updated BackgroundModeManager to recalculate the background state when a
profile is removed - this avoids crashes where we are in background mode but
there are no background profiles.
Changed BackgroundApplicationListModel to complain if a caller forgets to
remove the observer before the model is destroyed. This would have caught
this bug much sooner had it been enabled.
BUG=346214
Review URL: https://codereview.chromium.org/192943002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256539 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/background')
4 files changed, 41 insertions, 1 deletions
diff --git a/chrome/browser/background/background_application_list_model.h b/chrome/browser/background/background_application_list_model.h index 0dbc407..1c9c2d6 100644 --- a/chrome/browser/background/background_application_list_model.h +++ b/chrome/browser/background/background_application_list_model.h @@ -148,7 +148,7 @@ class BackgroundApplicationListModel : public content::NotificationObserver { ApplicationMap applications_; extensions::ExtensionList extensions_; - ObserverList<Observer> observers_; + ObserverList<Observer, true> observers_; Profile* profile_; content::NotificationRegistrar registrar_; diff --git a/chrome/browser/background/background_mode_manager.cc b/chrome/browser/background/background_mode_manager.cc index 67945b3..cc091f5 100644 --- a/chrome/browser/background/background_mode_manager.cc +++ b/chrome/browser/background/background_mode_manager.cc @@ -459,7 +459,14 @@ void BackgroundModeManager::OnProfileWillBeRemoved( GetBackgroundModeIterator(profile_name); // If a profile isn't running a background app, it may not be in the map. if (it != background_mode_data_.end()) { + it->second->applications_->RemoveObserver(this); background_mode_data_.erase(it); + // If there are no background mode profiles any longer, then turn off + // background mode. + if (!ShouldBeInBackgroundMode()) { + EnableLaunchOnStartup(false); + EndBackgroundMode(); + } UpdateStatusTrayIconContextMenu(); } } diff --git a/chrome/browser/background/background_mode_manager.h b/chrome/browser/background/background_mode_manager.h index ac983ed..b65cd4a 100644 --- a/chrome/browser/background/background_mode_manager.h +++ b/chrome/browser/background/background_mode_manager.h @@ -103,6 +103,8 @@ class BackgroundModeManager FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, ProfileInfoCacheObserver); FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, + DeleteBackgroundProfile); + FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, BackgroundMenuGeneration); FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, BackgroundMenuGenerationMultipleProfile); diff --git a/chrome/browser/background/background_mode_manager_unittest.cc b/chrome/browser/background/background_mode_manager_unittest.cc index 28de86d..ef8f18a 100644 --- a/chrome/browser/background/background_mode_manager_unittest.cc +++ b/chrome/browser/background/background_mode_manager_unittest.cc @@ -365,6 +365,7 @@ TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { EXPECT_EQ(base::UTF8ToUTF16("p1"), manager.GetBackgroundModeData(profile1)->name()); + EXPECT_TRUE(chrome::WillKeepAlive()); TestingProfile* profile2 = profile_manager->CreateTestingProfile("p2"); manager.RegisterProfile(profile2); EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); @@ -374,6 +375,8 @@ TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { manager.GetBackgroundModeData(profile2)->name()); manager.OnProfileWillBeRemoved(profile2->GetPath()); + // Should still be in background mode after deleting profile. + EXPECT_TRUE(chrome::WillKeepAlive()); EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); // Check that the background mode data we think is in the map actually is. @@ -381,6 +384,34 @@ TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { manager.GetBackgroundModeData(profile1)->name()); } +TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { + // Tests whether deleting the only profile when it is a BG profile works + // or not (http://crbug.com/346214). + scoped_ptr<TestingProfileManager> profile_manager = + CreateTestingProfileManager(); + TestingProfile* profile = profile_manager->CreateTestingProfile("p1"); + TestBackgroundModeManager manager( + command_line_.get(), profile_manager->profile_info_cache(), true); + manager.RegisterProfile(profile); + EXPECT_FALSE(chrome::WillKeepAlive()); + + // Install app, should show status tray icon. + manager.OnBackgroundAppInstalled(NULL); + manager.SetBackgroundAppCount(1); + manager.SetBackgroundAppCountForProfile(1); + manager.OnApplicationListChanged(profile); + + manager.OnProfileNameChanged( + profile->GetPath(), + manager.GetBackgroundModeData(profile)->name()); + + EXPECT_TRUE(chrome::WillKeepAlive()); + manager.SetBackgroundAppCount(0); + manager.SetBackgroundAppCountForProfile(0); + manager.OnProfileWillBeRemoved(profile->GetPath()); + EXPECT_FALSE(chrome::WillKeepAlive()); +} + TEST_F(BackgroundModeManagerTest, DisableBackgroundModeUnderTestFlag) { scoped_ptr<TestingProfileManager> profile_manager = CreateTestingProfileManager(); |