summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/app_shim/app_shim_handler_mac.cc37
-rw-r--r--apps/app_shim/app_shim_handler_mac.h5
2 files changed, 34 insertions, 8 deletions
diff --git a/apps/app_shim/app_shim_handler_mac.cc b/apps/app_shim/app_shim_handler_mac.cc
index cfbf4ff..7e67e73 100644
--- a/apps/app_shim/app_shim_handler_mac.cc
+++ b/apps/app_shim/app_shim_handler_mac.cc
@@ -61,7 +61,7 @@ class AppShimHandlerRegistry : public content::NotificationObserver {
}
void MaybeTerminate() {
- if (!browser_opened_ever_) {
+ if (!browser_session_running_) {
// Post this to give AppWindows a chance to remove themselves from the
// registry.
base::MessageLoop::current()->PostTask(
@@ -69,16 +69,26 @@ class AppShimHandlerRegistry : public content::NotificationObserver {
}
}
+ bool ShouldRestoreSession() {
+ return !browser_session_running_;
+ }
+
private:
friend struct DefaultSingletonTraits<AppShimHandlerRegistry>;
typedef std::map<std::string, AppShimHandler*> HandlerMap;
AppShimHandlerRegistry()
: default_handler_(NULL),
- browser_opened_ever_(false) {
+ browser_session_running_(false) {
registrar_.Add(
this, chrome::NOTIFICATION_BROWSER_OPENED,
content::NotificationService::AllBrowserContextsAndSources());
+ registrar_.Add(
+ this, chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
+ content::NotificationService::AllBrowserContextsAndSources());
+ registrar_.Add(
+ this, chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
+ content::NotificationService::AllBrowserContextsAndSources());
}
virtual ~AppShimHandlerRegistry() {}
@@ -88,17 +98,23 @@ class AppShimHandlerRegistry : public content::NotificationObserver {
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
- DCHECK_EQ(chrome::NOTIFICATION_BROWSER_OPENED, type);
- registrar_.Remove(
- this, chrome::NOTIFICATION_BROWSER_OPENED,
- content::NotificationService::AllBrowserContextsAndSources());
- browser_opened_ever_ = true;
+ switch (type) {
+ case chrome::NOTIFICATION_BROWSER_OPENED:
+ case chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED:
+ browser_session_running_ = true;
+ break;
+ case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST:
+ browser_session_running_ = false;
+ break;
+ default:
+ NOTREACHED();
+ }
}
HandlerMap handlers_;
AppShimHandler* default_handler_;
content::NotificationRegistrar registrar_;
- bool browser_opened_ever_;
+ bool browser_session_running_;
DISALLOW_COPY_AND_ASSIGN(AppShimHandlerRegistry);
};
@@ -132,4 +148,9 @@ void AppShimHandler::MaybeTerminate() {
AppShimHandlerRegistry::GetInstance()->MaybeTerminate();
}
+// static
+bool AppShimHandler::ShouldRestoreSession() {
+ return AppShimHandlerRegistry::GetInstance()->ShouldRestoreSession();
+}
+
} // namespace apps
diff --git a/apps/app_shim/app_shim_handler_mac.h b/apps/app_shim/app_shim_handler_mac.h
index 0ecde07..9e53e0e 100644
--- a/apps/app_shim/app_shim_handler_mac.h
+++ b/apps/app_shim/app_shim_handler_mac.h
@@ -56,6 +56,11 @@ class AppShimHandler {
// shell windows, and the app list is not visible.
static void MaybeTerminate();
+ // Whether browser sessions should be restored right now. This is true if
+ // the browser has been quit but kept alive because Chrome Apps are still
+ // running.
+ static bool ShouldRestoreSession();
+
// Invoked by the shim host when the shim process is launched. The handler
// must call OnAppLaunchComplete to inform the shim of the result.
// |launch_type| indicates the type of launch.