summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-06 13:38:37 +0000
committerjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-06 13:38:37 +0000
commitd54b3f490de80c708e335714872e44eba322342b (patch)
tree08b3bb2e4312da05091229947ca82b1e1655c94f
parente34d51130d3026bf2fb6501264b1c761cfa48a18 (diff)
downloadchromium_src-d54b3f490de80c708e335714872e44eba322342b.zip
chromium_src-d54b3f490de80c708e335714872e44eba322342b.tar.gz
chromium_src-d54b3f490de80c708e335714872e44eba322342b.tar.bz2
Factor out AppLifetimeMonitor.
AppLifetimeMonitor listens to extension host notifications and observes ShellWindowRegistry. It sends out notifications when: - an app starts - the first shell window opens - the last shell window closes - the app stops BUG= Review URL: https://chromiumcodereview.appspot.com/16412002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204487 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--apps/app_lifetime_monitor.cc112
-rw-r--r--apps/app_lifetime_monitor.h82
-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.cc85
-rw-r--r--apps/app_restore_service.h20
-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, 345 insertions, 84 deletions
diff --git a/apps/app_lifetime_monitor.cc b/apps/app_lifetime_monitor.cc
new file mode 100644
index 0000000..458ca76
--- /dev/null
+++ b/apps/app_lifetime_monitor.cc
@@ -0,0 +1,112 @@
+// 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());
+
+ ShellWindowRegistry* shell_window_registry =
+ ShellWindowRegistry::Factory::GetForProfile(
+ profile_, false /* create */);
+ if (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) {
+ ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
+ const Extension* extension = host->extension();
+ if (!extension || !extension->is_platform_app())
+ return;
+
+ switch (type) {
+ case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
+ NotifyAppStart(extension->id());
+ break;
+ }
+
+ case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
+ NotifyAppStop(extension->id());
+ 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) {
+ ShellWindow* window =
+ ShellWindowRegistry::Get(shell_window->profile())->
+ GetCurrentShellWindowForApp(shell_window->extension_id());
+ if (!window)
+ 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));
+}
+
+} // namespace apps
diff --git a/apps/app_lifetime_monitor.h b/apps/app_lifetime_monitor.h
new file mode 100644
index 0000000..00c1ccc
--- /dev/null
+++ b/apps/app_lifetime_monitor.h
@@ -0,0 +1,82 @@
+// 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;
+
+ 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);
+
+ 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..66cfdf4
--- /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, true));
+}
+
+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 false;
+}
+
+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 88ac811..dd9639c 100644
--- a/apps/app_restore_service.cc
+++ b/apps/app_restore_service.cc
@@ -4,27 +4,24 @@
#include "apps/app_restore_service.h"
+#include "apps/app_lifetime_monitor_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;
@@ -48,16 +45,10 @@ 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());
+ StartObservingAppLifetime();
registrar_.Add(
this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
- StartObservingShellWindows();
}
void AppRestoreService::HandleStartup(bool should_restore_apps) {
@@ -88,47 +79,39 @@ 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;
- }
-
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();
+ // We want to preserve the state when the app begins terminating, so stop
+ // listening to app lifetime events.
+ StopObservingAppLifetime();
break;
}
}
}
-void AppRestoreService::OnShellWindowAdded(ShellWindow* shell_window) {
- RecordIfAppHasWindows(shell_window->extension_id());
+void AppRestoreService::OnAppStart(Profile* profile,
+ const std::string& app_id) {
+ RecordAppStart(app_id);
}
-void AppRestoreService::OnShellWindowIconChanged(ShellWindow* shell_window) {
+void AppRestoreService::OnAppActivated(Profile* profile,
+ const std::string& app_id) {
+ RecordAppActiveState(app_id, true);
}
-void AppRestoreService::OnShellWindowRemoved(ShellWindow* shell_window) {
- RecordIfAppHasWindows(shell_window->extension_id());
+void AppRestoreService::OnAppDeactivated(Profile* profile,
+ const std::string& app_id) {
+ RecordAppActiveState(app_id, false);
+}
+
+void AppRestoreService::OnAppStop(Profile* profile, const std::string& app_id) {
+ RecordAppStop(app_id);
}
void AppRestoreService::Shutdown() {
- StopObservingShellWindows();
+ StopObservingAppLifetime();
}
void AppRestoreService::RecordAppStart(const std::string& extension_id) {
@@ -143,44 +126,30 @@ 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() {
+ AppLifetimeMonitorFactory::GetForProfile(profile_)->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() {
+ AppLifetimeMonitorFactory::GetForProfile(profile_)->RemoveObserver(this);
}
} // namespace apps
diff --git a/apps/app_restore_service.h b/apps/app_restore_service.h
index 65d3de2..d4e605f 100644
--- a/apps/app_restore_service.h
+++ b/apps/app_restore_service.h
@@ -8,6 +8,7 @@
#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"
@@ -24,7 +25,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.
@@ -42,22 +43,25 @@ class AppRestoreService : public BrowserContextKeyedService,
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;
// 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_;
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 79ff1b4..e47f90e 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -53,7 +53,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";
@@ -1047,19 +1047,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 c4a9b3e..d8d324c 100644
--- a/chrome/browser/extensions/extension_prefs.h
+++ b/chrome/browser/extensions/extension_prefs.h
@@ -353,11 +353,11 @@ class ExtensionPrefs : public ContentSettingsStore::Observer,
// 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 1956abd..65d6653 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);