Skip to content

Commit

Permalink
Clears the list of apps to restore when the browser starts normally.
Browse files Browse the repository at this point in the history
In the case of a browser restart, we restart the apps that were running when the browser exited. This change makes it so that when chrome is starting normally (ie: not restarting) we clear the list of running apps, so that subsequent chrome restarts don't prompt the restart of apps that are no longer running.


BUG=156243


Review URL: https://chromiumcodereview.appspot.com/11187016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162683 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
koz@chromium.org committed Oct 18, 2012
1 parent f707573 commit 1194546
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
11 changes: 7 additions & 4 deletions chrome/browser/extensions/app_restore_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ AppRestoreService::AppRestoreService(Profile* profile)
content::NotificationService::AllSources());
}

void AppRestoreService::RestoreApps() {
void AppRestoreService::HandleStartup(bool is_restart) {
ExtensionService* extension_service =
ExtensionSystem::Get(profile_)->extension_service();
const ExtensionSet* extensions = extension_service->extensions();
ExtensionPrefs* extension_prefs = extension_service->extension_prefs();

for (ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
it != extensions->end(); ++it) {
const Extension* extension = *it;
if (extension_prefs->IsExtensionRunning(extension->id()))
RestoreApp(extension);
if (extension_prefs->IsExtensionRunning(extension->id())) {
RecordAppStop(extension->id());
if (is_restart)
RestoreApp(*it);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/extensions/app_restore_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class AppRestoreService : public ProfileKeyedService,
public:
explicit AppRestoreService(Profile* profile);

// Dispatches the app.runtime.onRestarted event to apps that were running in
// the last session.
void RestoreApps();
// Restart apps that need to be restarted and clear the "running" preference
// from apps to prevent them being restarted in subsequent restarts.
void HandleStartup(bool is_restart);

private:
// content::NotificationObserver.
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/extensions/platform_app_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) {
extension_prefs->SetExtensionRunning(extension->id(), true);

ExtensionTestMessageListener restart_listener("onRestarted", false);
AppRestoreServiceFactory::GetForProfile(browser()->profile())->RestoreApps();
AppRestoreServiceFactory::GetForProfile(browser()->profile())->
HandleStartup(true);
restart_listener.WaitUntilSatisfied();
}

Expand Down
13 changes: 5 additions & 8 deletions chrome/browser/ui/startup/startup_browser_creator_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -642,14 +642,11 @@ bool StartupBrowserCreatorImpl::ProcessStartupURLs(
else if (pref.type == SessionStartupPref::DEFAULT)
VLOG(1) << "Pref: default";

// The only time apps get restored is when the browser process is restarted.
if (StartupBrowserCreator::WasRestarted()) {
extensions::AppRestoreService* service =
extensions::AppRestoreServiceFactory::GetForProfile(profile_);
// NULL in incognito mode.
if (service)
service->RestoreApps();
}
extensions::AppRestoreService* service =
extensions::AppRestoreServiceFactory::GetForProfile(profile_);
// NULL in incognito mode.
if (service)
service->HandleStartup(StartupBrowserCreator::WasRestarted());

if (pref.type == SessionStartupPref::LAST) {
if (profile_->GetLastSessionExitType() == Profile::EXIT_CRASHED &&
Expand Down

0 comments on commit 1194546

Please sign in to comment.