summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/app_lifetime_monitor.cc129
-rw-r--r--apps/app_lifetime_monitor.h87
-rw-r--r--apps/app_lifetime_monitor_factory.cc48
-rw-r--r--apps/app_lifetime_monitor_factory.h42
-rw-r--r--apps/app_restore_service.cc108
-rw-r--r--apps/app_restore_service.h30
-rw-r--r--apps/app_restore_service_factory.cc4
-rw-r--r--apps/apps.gypi4
-rw-r--r--chrome/browser/extensions/extension_prefs.cc18
-rw-r--r--chrome/browser/extensions/extension_prefs.h10
-rw-r--r--chrome/browser/extensions/platform_app_launcher.cc4
11 files changed, 375 insertions, 109 deletions
diff --git a/apps/app_lifetime_monitor.cc b/apps/app_lifetime_monitor.cc
new file mode 100644
index 0000000..6c2b9b9
--- /dev/null
+++ b/apps/app_lifetime_monitor.cc
@@ -0,0 +1,129 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/app_lifetime_monitor.h"
+
+#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/ui/extensions/shell_window.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/extensions/extension.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
+
+namespace apps {
+
+using extensions::Extension;
+using extensions::ExtensionHost;
+using extensions::ShellWindowRegistry;
+
+AppLifetimeMonitor::AppLifetimeMonitor(Profile* profile)
+ : profile_(profile) {
+ registrar_.Add(
+ this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
+ content::NotificationService::AllSources());
+ registrar_.Add(
+ this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
+ content::NotificationService::AllSources());
+ registrar_.Add(
+ this, chrome::NOTIFICATION_APP_TERMINATING,
+ content::NotificationService::AllSources());
+
+ ShellWindowRegistry* shell_window_registry =
+ ShellWindowRegistry::Factory::GetForProfile(
+ profile_, false /* create */);
+ DCHECK(shell_window_registry);
+ shell_window_registry->AddObserver(this);
+}
+
+AppLifetimeMonitor::~AppLifetimeMonitor() {}
+
+void AppLifetimeMonitor::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void AppLifetimeMonitor::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void AppLifetimeMonitor::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
+ ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
+ const Extension* extension = host->extension();
+ if (!extension || !extension->is_platform_app())
+ return;
+
+ NotifyAppStart(extension->id());
+ break;
+ }
+
+ case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
+ ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
+ const Extension* extension = host->extension();
+ if (!extension || !extension->is_platform_app())
+ return;
+
+ NotifyAppStop(extension->id());
+ break;
+ }
+
+ case chrome::NOTIFICATION_APP_TERMINATING: {
+ NotifyChromeTerminating();
+ break;
+ }
+ }
+}
+
+void AppLifetimeMonitor::OnShellWindowAdded(ShellWindow* shell_window) {
+ if (shell_window->window_type() != ShellWindow::WINDOW_TYPE_DEFAULT)
+ return;
+
+ ShellWindowRegistry::ShellWindowList windows =
+ ShellWindowRegistry::Get(shell_window->profile())->
+ GetShellWindowsForApp(shell_window->extension_id());
+ if (windows.size() == 1)
+ NotifyAppActivated(shell_window->extension_id());
+}
+
+void AppLifetimeMonitor::OnShellWindowIconChanged(ShellWindow* shell_window) {}
+
+void AppLifetimeMonitor::OnShellWindowRemoved(ShellWindow* shell_window) {
+ ShellWindowRegistry::ShellWindowList windows =
+ ShellWindowRegistry::Get(shell_window->profile())->
+ GetShellWindowsForApp(shell_window->extension_id());
+ if (windows.empty())
+ NotifyAppDeactivated(shell_window->extension_id());
+}
+
+void AppLifetimeMonitor::Shutdown() {
+ ShellWindowRegistry* shell_window_registry =
+ ShellWindowRegistry::Factory::GetForProfile(
+ profile_, false /* create */);
+ if (shell_window_registry)
+ shell_window_registry->RemoveObserver(this);
+}
+
+void AppLifetimeMonitor::NotifyAppStart(const std::string& app_id) {
+ FOR_EACH_OBSERVER(Observer, observers_, OnAppStart(profile_, app_id));
+}
+
+void AppLifetimeMonitor::NotifyAppActivated(const std::string& app_id) {
+ FOR_EACH_OBSERVER(Observer, observers_, OnAppActivated(profile_, app_id));
+}
+
+void AppLifetimeMonitor::NotifyAppDeactivated(const std::string& app_id) {
+ FOR_EACH_OBSERVER(Observer, observers_, OnAppDeactivated(profile_, app_id));
+}
+
+void AppLifetimeMonitor::NotifyAppStop(const std::string& app_id) {
+ FOR_EACH_OBSERVER(Observer, observers_, OnAppStop(profile_, app_id));
+}
+
+void AppLifetimeMonitor::NotifyChromeTerminating() {
+ FOR_EACH_OBSERVER(Observer, observers_, OnChromeTerminating());
+}
+
+} // namespace apps
diff --git a/apps/app_lifetime_monitor.h b/apps/app_lifetime_monitor.h
new file mode 100644
index 0000000..f18a97d
--- /dev/null
+++ b/apps/app_lifetime_monitor.h
@@ -0,0 +1,87 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APPS_APP_LIFETIME_MONITOR_H_
+#define APPS_APP_LIFETIME_MONITOR_H_
+
+#include <string>
+#include <vector>
+
+#include "base/observer_list.h"
+#include "chrome/browser/extensions/shell_window_registry.h"
+#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+
+namespace extensions {
+class Extension;
+}
+
+class Profile;
+
+namespace apps {
+
+// Observes startup of apps and their windows and notifies observers of these
+// events.
+class AppLifetimeMonitor : public BrowserContextKeyedService,
+ public content::NotificationObserver,
+ public extensions::ShellWindowRegistry::Observer {
+ public:
+ class Observer {
+ public:
+ // Called when the app starts running.
+ virtual void OnAppStart(Profile* profile, const std::string& app_id) = 0;
+ // Called when the app becomes active to the user, i.e. it opens a window.
+ virtual void OnAppActivated(Profile* profile,
+ const std::string& app_id) = 0;
+ // Called when the app becomes inactive to the user.
+ virtual void OnAppDeactivated(Profile* profile,
+ const std::string& app_id) = 0;
+ // Called when the app stops running.
+ virtual void OnAppStop(Profile* profile, const std::string& app_id) = 0;
+ // Called when chrome is about to terminate. This gives observers a chance
+ // to do something before the apps shut down. This is a system-wide event
+ // so there is no associated profile and app id.
+ virtual void OnChromeTerminating() = 0;
+
+ protected:
+ virtual ~Observer() {}
+ };
+
+ explicit AppLifetimeMonitor(Profile* profile);
+ virtual ~AppLifetimeMonitor();
+
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ private:
+ // content::NotificationObserver overrides:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ // extensions::ShellWindowRegistry::Observer overrides:
+ virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE;
+ virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE;
+ virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE;
+
+ // BrowserContextKeyedService overrides:
+ virtual void Shutdown() OVERRIDE;
+
+ void NotifyAppStart(const std::string& app_id);
+ void NotifyAppActivated(const std::string& app_id);
+ void NotifyAppDeactivated(const std::string& app_id);
+ void NotifyAppStop(const std::string& app_id);
+ void NotifyChromeTerminating();
+
+ content::NotificationRegistrar registrar_;
+ Profile* profile_;
+ ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppLifetimeMonitor);
+};
+
+} // namespace apps
+
+#endif // APPS_APP_LIFETIME_MONITOR_H_
diff --git a/apps/app_lifetime_monitor_factory.cc b/apps/app_lifetime_monitor_factory.cc
new file mode 100644
index 0000000..4d828b0
--- /dev/null
+++ b/apps/app_lifetime_monitor_factory.cc
@@ -0,0 +1,48 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/app_lifetime_monitor_factory.h"
+
+#include "apps/app_lifetime_monitor.h"
+#include "chrome/browser/extensions/shell_window_registry.h"
+#include "chrome/browser/profiles/incognito_helpers.h"
+#include "chrome/browser/profiles/profile.h"
+#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
+
+namespace apps {
+
+// static
+AppLifetimeMonitor* AppLifetimeMonitorFactory::GetForProfile(Profile* profile) {
+ return static_cast<AppLifetimeMonitor*>(
+ GetInstance()->GetServiceForBrowserContext(profile, false));
+}
+
+AppLifetimeMonitorFactory* AppLifetimeMonitorFactory::GetInstance() {
+ return Singleton<AppLifetimeMonitorFactory>::get();
+}
+
+AppLifetimeMonitorFactory::AppLifetimeMonitorFactory()
+ : BrowserContextKeyedServiceFactory(
+ "AppLifetimeMonitor",
+ BrowserContextDependencyManager::GetInstance()) {
+ DependsOn(extensions::ShellWindowRegistry::Factory::GetInstance());
+}
+
+AppLifetimeMonitorFactory::~AppLifetimeMonitorFactory() {}
+
+BrowserContextKeyedService* AppLifetimeMonitorFactory::BuildServiceInstanceFor(
+ content::BrowserContext* profile) const {
+ return new AppLifetimeMonitor(static_cast<Profile*>(profile));
+}
+
+bool AppLifetimeMonitorFactory::ServiceIsCreatedWithBrowserContext() const {
+ return true;
+}
+
+content::BrowserContext* AppLifetimeMonitorFactory::GetBrowserContextToUse(
+ content::BrowserContext* context) const {
+ return chrome::GetBrowserContextRedirectedInIncognito(context);
+}
+
+} // namespace apps
diff --git a/apps/app_lifetime_monitor_factory.h b/apps/app_lifetime_monitor_factory.h
new file mode 100644
index 0000000..c55ba71
--- /dev/null
+++ b/apps/app_lifetime_monitor_factory.h
@@ -0,0 +1,42 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APPS_APP_LIFETIME_MONITOR_FACTORY_H_
+#define APPS_APP_LIFETIME_MONITOR_FACTORY_H_
+
+#include "base/memory/singleton.h"
+#include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h"
+
+class Profile;
+
+namespace apps {
+
+class AppLifetimeMonitor;
+
+// Singleton that owns all AppLifetimeMonitors and associates them with
+// Profiles. Listens for the Profile's destruction notification and cleans up
+// the associated AppLifetimeMonitor.
+class AppLifetimeMonitorFactory : public BrowserContextKeyedServiceFactory {
+ public:
+ static AppLifetimeMonitor* GetForProfile(Profile* profile);
+
+ static AppLifetimeMonitorFactory* GetInstance();
+
+ private:
+ friend struct DefaultSingletonTraits<AppLifetimeMonitorFactory>;
+
+ AppLifetimeMonitorFactory();
+ virtual ~AppLifetimeMonitorFactory();
+
+ // BrowserContextKeyedServiceFactory:
+ virtual BrowserContextKeyedService* BuildServiceInstanceFor(
+ content::BrowserContext* profile) const OVERRIDE;
+ virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE;
+ virtual content::BrowserContext* GetBrowserContextToUse(
+ content::BrowserContext* context) const OVERRIDE;
+};
+
+} // namespace apps
+
+#endif // APPS_APP_LIFETIME_MONITOR_FACTORY_H_
diff --git a/apps/app_restore_service.cc b/apps/app_restore_service.cc
index f5cf21c..210ccf3 100644
--- a/apps/app_restore_service.cc
+++ b/apps/app_restore_service.cc
@@ -4,28 +4,22 @@
#include "apps/app_restore_service.h"
+#include "apps/app_lifetime_monitor_factory.h"
#include "apps/app_restore_service_factory.h"
#include "apps/saved_files_service.h"
#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.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"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/notification_types.h"
#if defined(OS_WIN)
#include "win8/util/win8_util.h"
#endif
-using extensions::AppEventRouter;
using extensions::Extension;
using extensions::ExtensionHost;
using extensions::ExtensionPrefs;
@@ -49,16 +43,7 @@ bool AppRestoreService::ShouldRestoreApps(bool is_browser_restart) {
AppRestoreService::AppRestoreService(Profile* profile)
: profile_(profile) {
- registrar_.Add(
- this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
- content::NotificationService::AllSources());
- registrar_.Add(
- this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
- content::NotificationService::AllSources());
- registrar_.Add(
- this, chrome::NOTIFICATION_APP_TERMINATING,
- content::NotificationService::AllSources());
- StartObservingShellWindows();
+ StartObservingAppLifetime();
}
void AppRestoreService::HandleStartup(bool should_restore_apps) {
@@ -95,51 +80,33 @@ AppRestoreService* AppRestoreService::Get(Profile* profile) {
return apps::AppRestoreServiceFactory::GetForProfile(profile);
}
-void AppRestoreService::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- switch (type) {
- case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
- ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
- const Extension* extension = host->extension();
- if (extension && extension->is_platform_app())
- RecordAppStart(extension->id());
- break;
- }
-
- case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
- ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
- const Extension* extension = host->extension();
- if (extension && extension->is_platform_app())
- RecordAppStop(extension->id());
- break;
- }
+void AppRestoreService::OnAppStart(Profile* profile,
+ const std::string& app_id) {
+ RecordAppStart(app_id);
+}
- case chrome::NOTIFICATION_APP_TERMINATING: {
- // 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::OnAppActivated(Profile* profile,
+ const std::string& app_id) {
+ RecordAppActiveState(app_id, true);
}
-void AppRestoreService::OnShellWindowAdded(ShellWindow* shell_window) {
- RecordIfAppHasWindows(shell_window->extension_id());
+void AppRestoreService::OnAppDeactivated(Profile* profile,
+ const std::string& app_id) {
+ RecordAppActiveState(app_id, false);
}
-void AppRestoreService::OnShellWindowIconChanged(ShellWindow* shell_window) {
+void AppRestoreService::OnAppStop(Profile* profile, const std::string& app_id) {
+ RecordAppStop(app_id);
}
-void AppRestoreService::OnShellWindowRemoved(ShellWindow* shell_window) {
- RecordIfAppHasWindows(shell_window->extension_id());
+void AppRestoreService::OnChromeTerminating() {
+ // We want to preserve the state when the app begins terminating, so stop
+ // listening to app lifetime events.
+ StopObservingAppLifetime();
}
void AppRestoreService::Shutdown() {
- StopObservingShellWindows();
+ StopObservingAppLifetime();
}
void AppRestoreService::RecordAppStart(const std::string& extension_id) {
@@ -154,44 +121,37 @@ void AppRestoreService::RecordAppStop(const std::string& extension_id) {
extension_prefs->SetExtensionRunning(extension_id, false);
}
-void AppRestoreService::RecordIfAppHasWindows(
- const std::string& id) {
+void AppRestoreService::RecordAppActiveState(const std::string& id,
+ bool is_active) {
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.
+ // it is active 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);
+ extension_prefs->SetIsActive(id, is_active);
}
void AppRestoreService::RestoreApp(const Extension* extension) {
extensions::RestartPlatformApp(profile_, extension);
}
-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::StartObservingAppLifetime() {
+ AppLifetimeMonitor* app_lifetime_monitor =
+ AppLifetimeMonitorFactory::GetForProfile(profile_);
+ DCHECK(app_lifetime_monitor);
+ app_lifetime_monitor->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);
+void AppRestoreService::StopObservingAppLifetime() {
+ AppLifetimeMonitor* app_lifetime_monitor =
+ AppLifetimeMonitorFactory::GetForProfile(profile_);
+ // This might be NULL in tests.
+ if (app_lifetime_monitor)
+ app_lifetime_monitor->RemoveObserver(this);
}
} // namespace apps
diff --git a/apps/app_restore_service.h b/apps/app_restore_service.h
index bf53829..5a66005 100644
--- a/apps/app_restore_service.h
+++ b/apps/app_restore_service.h
@@ -8,10 +8,9 @@
#include <string>
#include <vector>
+#include "apps/app_lifetime_monitor.h"
#include "chrome/browser/extensions/shell_window_registry.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
namespace extensions {
class Extension;
@@ -23,8 +22,7 @@ namespace apps {
// Tracks what apps need to be restarted when the browser restarts.
class AppRestoreService : public BrowserContextKeyedService,
- public content::NotificationObserver,
- public extensions::ShellWindowRegistry::Observer {
+ public AppLifetimeMonitor::Observer {
public:
// Returns true if apps should be restored on the current platform, given
// whether this new browser process launched due to a restart.
@@ -43,29 +41,27 @@ class AppRestoreService : public BrowserContextKeyedService,
static AppRestoreService* Get(Profile* profile);
private:
- // content::NotificationObserver.
- virtual void Observe(int type,
- 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;
+ // AppLifetimeMonitor::Observer.
+ virtual void OnAppStart(Profile* profile, const std::string& app_id) OVERRIDE;
+ virtual void OnAppActivated(Profile* profile,
+ const std::string& app_id) OVERRIDE;
+ virtual void OnAppDeactivated(Profile* profile,
+ const std::string& app_id) OVERRIDE;
+ virtual void OnAppStop(Profile* profile, const std::string& app_id) OVERRIDE;
+ virtual void OnChromeTerminating() OVERRIDE;
// BrowserContextKeyedService.
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 RecordAppActiveState(const std::string& id, bool is_active);
void RestoreApp(const extensions::Extension* extension);
- void StartObservingShellWindows();
- void StopObservingShellWindows();
+ void StartObservingAppLifetime();
+ void StopObservingAppLifetime();
- content::NotificationRegistrar registrar_;
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(AppRestoreService);
diff --git a/apps/app_restore_service_factory.cc b/apps/app_restore_service_factory.cc
index ffd31a7..a762e53 100644
--- a/apps/app_restore_service_factory.cc
+++ b/apps/app_restore_service_factory.cc
@@ -4,8 +4,8 @@
#include "apps/app_restore_service_factory.h"
+#include "apps/app_lifetime_monitor_factory.h"
#include "apps/app_restore_service.h"
-#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/profiles/profile.h"
#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
@@ -25,7 +25,7 @@ AppRestoreServiceFactory::AppRestoreServiceFactory()
: BrowserContextKeyedServiceFactory(
"AppRestoreService",
BrowserContextDependencyManager::GetInstance()) {
- DependsOn(extensions::ShellWindowRegistry::Factory::GetInstance());
+ DependsOn(AppLifetimeMonitorFactory::GetInstance());
}
AppRestoreServiceFactory::~AppRestoreServiceFactory() {
diff --git a/apps/apps.gypi b/apps/apps.gypi
index 1ad9600..fd45772d 100644
--- a/apps/apps.gypi
+++ b/apps/apps.gypi
@@ -26,6 +26,10 @@
'app_launch_for_metro_restart_win.h',
'app_launcher.cc',
'app_launcher.h',
+ 'app_lifetime_monitor.cc',
+ 'app_lifetime_monitor.h',
+ 'app_lifetime_monitor_factory.cc',
+ 'app_lifetime_monitor_factory.h',
'app_load_service.cc',
'app_load_service.h',
'app_load_service_factory.cc',
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index 8a212c9..c7f5bbf 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -60,7 +60,7 @@ namespace {
const char kPrefRunning[] = "running";
// Whether this extension had windows when it was last running.
-const char kHasWindows[] = "has_windows";
+const char kIsActive[] = "is_active";
// Where an extension was installed from. (see Manifest::Location)
const char kPrefLocation[] = "location";
@@ -985,19 +985,19 @@ bool ExtensionPrefs::IsExtensionRunning(const std::string& extension_id) {
return running;
}
-void ExtensionPrefs::SetHasWindows(const std::string& extension_id,
- bool has_windows) {
- Value* value = Value::CreateBooleanValue(has_windows);
- UpdateExtensionPref(extension_id, kHasWindows, value);
+void ExtensionPrefs::SetIsActive(const std::string& extension_id,
+ bool is_active) {
+ Value* value = Value::CreateBooleanValue(is_active);
+ UpdateExtensionPref(extension_id, kIsActive, value);
}
-bool ExtensionPrefs::HasWindows(const std::string& extension_id) {
+bool ExtensionPrefs::IsActive(const std::string& extension_id) {
const DictionaryValue* extension = GetExtensionPref(extension_id);
if (!extension)
return false;
- bool has_windows = false;
- extension->GetBoolean(kHasWindows, &has_windows);
- return has_windows;
+ bool is_active = false;
+ extension->GetBoolean(kIsActive, &is_active);
+ return is_active;
}
bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) {
diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h
index 1f894d5..a0eb1ec 100644
--- a/chrome/browser/extensions/extension_prefs.h
+++ b/chrome/browser/extensions/extension_prefs.h
@@ -351,11 +351,11 @@ class ExtensionPrefs : public ExtensionScopedPrefs,
// restart apps across browser restarts.
bool IsExtensionRunning(const std::string& extension_id);
- // Set/Get whether or not the extension has windows associated with it. Used
- // to force a launch of apps that don't handle onRestarted() on a restart. We
- // can only safely do that if the app had windows when it was last running.
- void SetHasWindows(const std::string& extension_id, bool has_windows);
- bool HasWindows(const std::string& extension_id);
+ // Set/Get whether or not the app is active. Used to force a launch of apps
+ // that don't handle onRestarted() on a restart. We can only safely do that if
+ // the app was active when it was last running.
+ void SetIsActive(const std::string& extension_id, bool is_active);
+ bool IsActive(const std::string& extension_id);
// Returns true if the user enabled this extension to be loaded in incognito
// mode.
diff --git a/chrome/browser/extensions/platform_app_launcher.cc b/chrome/browser/extensions/platform_app_launcher.cc
index 5e105d7..03d914b 100644
--- a/chrome/browser/extensions/platform_app_launcher.cc
+++ b/chrome/browser/extensions/platform_app_launcher.cc
@@ -343,8 +343,8 @@ void RestartPlatformApp(Profile* profile, const Extension* extension) {
ExtensionPrefs* extension_prefs = ExtensionSystem::Get(profile)->
extension_service()->extension_prefs();
- bool had_windows = extension_prefs->HasWindows(extension->id());
- extension_prefs->SetHasWindows(extension->id(), false);
+ bool had_windows = extension_prefs->IsActive(extension->id());
+ extension_prefs->SetIsActive(extension->id(), false);
bool listening_to_launch = event_router->
ExtensionHasEventListener(extension->id(), event_names::kOnLaunched);