summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorkoz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-17 09:47:40 +0000
committerkoz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-17 09:47:40 +0000
commit771c8d27dbe9d36918a8bdbfe6bf0752140d2960 (patch)
treee49e61e5adb732c3d0d47f9e1b4d7602759adbda /apps
parent489b9e29258a49bbaf346d6810333ae5d73e6a95 (diff)
downloadchromium_src-771c8d27dbe9d36918a8bdbfe6bf0752140d2960.zip
chromium_src-771c8d27dbe9d36918a8bdbfe6bf0752140d2960.tar.gz
chromium_src-771c8d27dbe9d36918a8bdbfe6bf0752140d2960.tar.bz2
Restart apps that don't listen to onRestarted() by sending them onLaunched().
We only do this if the app had windows opened the last time it was running, otherwise apps that were running but had no windows may restart by opening windows, which manifests as apps coming back on a restart after the user already closed them. BUG=230667,167740,162057 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=199406 Reverted: https://src.chromium.org/viewvc/chrome?view=rev&revision=199409 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=199970 Reverted: https://src.chromium.org/viewvc/chrome?view=rev&revision=200016 Review URL: https://chromiumcodereview.appspot.com/14878008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200779 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r--apps/app_restore_service.cc56
-rw-r--r--apps/app_restore_service.h17
-rw-r--r--apps/app_restore_service_factory.cc2
3 files changed, 74 insertions, 1 deletions
diff --git a/apps/app_restore_service.cc b/apps/app_restore_service.cc
index f8932fb..a567811 100644
--- a/apps/app_restore_service.cc
+++ b/apps/app_restore_service.cc
@@ -8,9 +8,11 @@
#include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
#include "chrome/browser/extensions/event_router.h"
#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/platform_app_launcher.h"
+#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_set.h"
@@ -55,6 +57,7 @@ AppRestoreService::AppRestoreService(Profile* profile)
registrar_.Add(
this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
+ StartObservingShellWindows();
}
void AppRestoreService::HandleStartup(bool should_restore_apps) {
@@ -102,11 +105,28 @@ void AppRestoreService::Observe(int type,
// Stop listening to NOTIFICATION_EXTENSION_HOST_DESTROYED in particular
// as all extension hosts will be destroyed as a result of shutdown.
registrar_.RemoveAll();
+ // Stop listening to the ShellWindowRegistry for window closes, because
+ // all windows will be closed as a result of shutdown.
+ StopObservingShellWindows();
break;
}
}
}
+void AppRestoreService::OnShellWindowAdded(ShellWindow* shell_window) {
+ RecordIfAppHasWindows(shell_window->extension_id());
+}
+
+void AppRestoreService::OnShellWindowIconChanged(ShellWindow* shell_window) {
+}
+
+void AppRestoreService::OnShellWindowRemoved(ShellWindow* shell_window) {
+ RecordIfAppHasWindows(shell_window->extension_id());
+}
+
+void AppRestoreService::Shutdown() {
+ StopObservingShellWindows();
+}
void AppRestoreService::RecordAppStart(const std::string& extension_id) {
ExtensionPrefs* extension_prefs =
@@ -122,6 +142,26 @@ void AppRestoreService::RecordAppStop(const std::string& extension_id) {
extension_prefs, extension_id);
}
+void AppRestoreService::RecordIfAppHasWindows(
+ const std::string& id) {
+ ExtensionService* extension_service =
+ ExtensionSystem::Get(profile_)->extension_service();
+ ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
+
+ // If the extension isn't running then we will already have recorded whether
+ // it had windows or not.
+ if (!extension_prefs->IsExtensionRunning(id))
+ return;
+
+ extensions::ShellWindowRegistry* shell_window_registry =
+ extensions::ShellWindowRegistry::Factory::GetForProfile(
+ profile_, false /* create */);
+ if (!shell_window_registry)
+ return;
+ bool has_windows = !shell_window_registry->GetShellWindowsForApp(id).empty();
+ extension_prefs->SetHasWindows(id, has_windows);
+}
+
void AppRestoreService::RestoreApp(
const Extension* extension,
const std::vector<SavedFileEntry>& file_entries) {
@@ -130,4 +170,20 @@ void AppRestoreService::RestoreApp(
file_entries);
}
+void AppRestoreService::StartObservingShellWindows() {
+ extensions::ShellWindowRegistry* shell_window_registry =
+ extensions::ShellWindowRegistry::Factory::GetForProfile(
+ profile_, false /* create */);
+ if (shell_window_registry)
+ shell_window_registry->AddObserver(this);
+}
+
+void AppRestoreService::StopObservingShellWindows() {
+ extensions::ShellWindowRegistry* shell_window_registry =
+ extensions::ShellWindowRegistry::Factory::GetForProfile(
+ profile_, false /* create */);
+ if (shell_window_registry)
+ shell_window_registry->RemoveObserver(this);
+}
+
} // namespace apps
diff --git a/apps/app_restore_service.h b/apps/app_restore_service.h
index f27c83c..16d0910 100644
--- a/apps/app_restore_service.h
+++ b/apps/app_restore_service.h
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
+#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/profiles/profile_keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@@ -29,7 +30,8 @@ namespace apps {
// Tracks what apps need to be restarted when the browser restarts.
class AppRestoreService : public ProfileKeyedService,
- public content::NotificationObserver {
+ public content::NotificationObserver,
+ public extensions::ShellWindowRegistry::Observer {
public:
// Returns true if apps should be restored on the current platform, given
// whether this new browser process launched due to a restart.
@@ -47,12 +49,25 @@ class AppRestoreService : public ProfileKeyedService,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
+ // extensions::ShellWindowRegistry::Observer.
+ virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE;
+ virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE;
+ virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE;
+
+ // ProfileKeyedService.
+ virtual void Shutdown() OVERRIDE;
+
void RecordAppStart(const std::string& extension_id);
void RecordAppStop(const std::string& extension_id);
+ void RecordIfAppHasWindows(const std::string& id);
+
void RestoreApp(
const extensions::Extension* extension,
const std::vector<SavedFileEntry>& file_entries);
+ void StartObservingShellWindows();
+ void StopObservingShellWindows();
+
content::NotificationRegistrar registrar_;
Profile* profile_;
diff --git a/apps/app_restore_service_factory.cc b/apps/app_restore_service_factory.cc
index 71dd80b..091487e 100644
--- a/apps/app_restore_service_factory.cc
+++ b/apps/app_restore_service_factory.cc
@@ -5,6 +5,7 @@
#include "apps/app_restore_service_factory.h"
#include "apps/app_restore_service.h"
+#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
@@ -30,6 +31,7 @@ AppRestoreServiceFactory* AppRestoreServiceFactory::GetInstance() {
AppRestoreServiceFactory::AppRestoreServiceFactory()
: ProfileKeyedServiceFactory("AppRestoreService",
ProfileDependencyManager::GetInstance()) {
+ DependsOn(extensions::ShellWindowRegistry::Factory::GetInstance());
}
AppRestoreServiceFactory::~AppRestoreServiceFactory() {