diff options
author | jackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-15 08:25:20 +0000 |
---|---|---|
committer | jackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-15 08:25:20 +0000 |
commit | 2603e73bf191c664e3841592d94090ba98014fbb (patch) | |
tree | f0e59ff5f45709fa0cd63d71a287d0f275494f06 /apps | |
parent | 7d08a93537fedd6c349f2194d7e2ba0d22b39e35 (diff) | |
download | chromium_src-2603e73bf191c664e3841592d94090ba98014fbb.zip chromium_src-2603e73bf191c664e3841592d94090ba98014fbb.tar.gz chromium_src-2603e73bf191c664e3841592d94090ba98014fbb.tar.bz2 |
Terminate Chrome when App Launcher is dismissed. (Mac)
This moves the code that terminates Chrome if no browser window was ever
opened from ExtensionAppShimHandler to AppShimHandlerRegistry.
Chrome is now only terminated if the app list is not visible.
AppListServiceMac calls AppShimHandler::MaybeTerminate when dismissing
the app list.
BUG=256723
TEST=Show the app list by clicking the App Launcher app.
Dismiss it by clicking the App Launcher again, or focusing another window.
Chrome should quit.
TEST=Show the app list and go to Settings.
Switch the profile in the settings page.
The app list should re-show with the new profile.
Review URL: https://codereview.chromium.org/27149003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228653 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r-- | apps/app_shim/DEPS | 1 | ||||
-rw-r--r-- | apps/app_shim/app_shim_handler_mac.cc | 58 | ||||
-rw-r--r-- | apps/app_shim/app_shim_handler_mac.h | 4 | ||||
-rw-r--r-- | apps/app_shim/extension_app_shim_handler_mac.cc | 27 | ||||
-rw-r--r-- | apps/app_shim/extension_app_shim_handler_mac.h | 2 | ||||
-rw-r--r-- | apps/app_shim/extension_app_shim_handler_mac_unittest.cc | 13 |
6 files changed, 62 insertions, 43 deletions
diff --git a/apps/app_shim/DEPS b/apps/app_shim/DEPS index 5bf1f29..fc7d0e0 100644 --- a/apps/app_shim/DEPS +++ b/apps/app_shim/DEPS @@ -3,6 +3,7 @@ include_rules = [ # See http://crbug.com/266705. "+chrome/browser/apps/app_launcher_util.h", "+chrome/browser/browser_process.h", + "+chrome/browser/ui/app_list/app_list_service.h", "+chrome/browser/ui/extensions/application_launch.h", "+chrome/browser/ui/web_applications/web_app_ui.h", "+chrome/browser/ui/webui/ntp/core_app_launcher_handler.h", diff --git a/apps/app_shim/app_shim_handler_mac.cc b/apps/app_shim/app_shim_handler_mac.cc index 6076557..6593155 100644 --- a/apps/app_shim/app_shim_handler_mac.cc +++ b/apps/app_shim/app_shim_handler_mac.cc @@ -6,14 +6,30 @@ #include <map> +#include "apps/shell_window_registry.h" +#include "base/bind.h" #include "base/logging.h" #include "base/memory/singleton.h" +#include "base/message_loop/message_loop.h" +#include "chrome/browser/chrome_notification_types.h" +#include "chrome/browser/lifetime/application_lifetime.h" +#include "chrome/browser/ui/app_list/app_list_service.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" +#include "content/public/browser/notification_service.h" namespace apps { namespace { -class AppShimHandlerRegistry { +void TerminateIfNoShellWindows() { + bool shell_windows_left = + apps::ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile(0); + if (!shell_windows_left && !AppListService::Get()->IsAppListVisible()) + chrome::AttemptExit(); +} + +class AppShimHandlerRegistry : public content::NotificationObserver { public: static AppShimHandlerRegistry* GetInstance() { return Singleton<AppShimHandlerRegistry, @@ -41,15 +57,46 @@ class AppShimHandlerRegistry { default_handler_ = handler; } + void MaybeTerminate() { + if (!browser_opened_ever_) { + // Post this to give ShellWindows a chance to remove themselves from the + // registry. + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&TerminateIfNoShellWindows)); + } + } + private: friend struct DefaultSingletonTraits<AppShimHandlerRegistry>; typedef std::map<std::string, AppShimHandler*> HandlerMap; - AppShimHandlerRegistry() : default_handler_(NULL) {} - ~AppShimHandlerRegistry() {} + AppShimHandlerRegistry() + : default_handler_(NULL), + browser_opened_ever_(false) { + registrar_.Add( + this, chrome::NOTIFICATION_BROWSER_OPENED, + content::NotificationService::AllBrowserContextsAndSources()); + } + + virtual ~AppShimHandlerRegistry() {} + + // content::NotificationObserver override: + virtual void Observe( + 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; + } HandlerMap handlers_; AppShimHandler* default_handler_; + content::NotificationRegistrar registrar_; + bool browser_opened_ever_; DISALLOW_COPY_AND_ASSIGN(AppShimHandlerRegistry); }; @@ -78,4 +125,9 @@ void AppShimHandler::SetDefaultHandler(AppShimHandler* handler) { AppShimHandlerRegistry::GetInstance()->SetDefaultHandler(handler); } +// static +void AppShimHandler::MaybeTerminate() { + AppShimHandlerRegistry::GetInstance()->MaybeTerminate(); +} + } // namespace apps diff --git a/apps/app_shim/app_shim_handler_mac.h b/apps/app_shim/app_shim_handler_mac.h index 66dbea9..2e73181 100644 --- a/apps/app_shim/app_shim_handler_mac.h +++ b/apps/app_shim/app_shim_handler_mac.h @@ -54,6 +54,10 @@ class AppShimHandler { // Setting this to NULL removes the default handler. static void SetDefaultHandler(AppShimHandler* handler); + // Terminate Chrome if a browser window has never been opened, there are no + // shell windows, and the app list is not visible. + static void MaybeTerminate(); + // 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. diff --git a/apps/app_shim/extension_app_shim_handler_mac.cc b/apps/app_shim/extension_app_shim_handler_mac.cc index b2f9a1a..9cd2070e 100644 --- a/apps/app_shim/extension_app_shim_handler_mac.cc +++ b/apps/app_shim/extension_app_shim_handler_mac.cc @@ -18,7 +18,6 @@ #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" -#include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/web_applications/web_app_ui.h" @@ -46,13 +45,6 @@ void ProfileLoadedCallback(base::Callback<void(Profile*)> callback, DCHECK_EQ(Profile::CREATE_STATUS_CREATED, status); } -void TerminateIfNoShellWindows() { - bool shell_windows_left = - apps::ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile(0); - if (!shell_windows_left) - chrome::AttemptExit(); -} - void SetAppHidden(Profile* profile, const std::string& app_id, bool hidden) { ShellWindowList windows = apps::ShellWindowRegistry::Get(profile)->GetShellWindowsForApp(app_id); @@ -158,16 +150,11 @@ void ExtensionAppShimHandler::Delegate::LaunchShim( } void ExtensionAppShimHandler::Delegate::MaybeTerminate() { - // Post this to give ShellWindows a chance to remove themselves from the - // registry. - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&TerminateIfNoShellWindows)); + AppShimHandler::MaybeTerminate(); } ExtensionAppShimHandler::ExtensionAppShimHandler() : delegate_(new Delegate), - browser_opened_ever_(false), weak_factory_(this) { // This is instantiated in BrowserProcessImpl::PreMainMessageLoopRun with // AppShimHostManager. Since PROFILE_CREATED is not fired until @@ -177,8 +164,6 @@ ExtensionAppShimHandler::ExtensionAppShimHandler() content::NotificationService::AllBrowserContextsAndSources()); registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, content::NotificationService::AllBrowserContextsAndSources()); - registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, - content::NotificationService::AllBrowserContextsAndSources()); } ExtensionAppShimHandler::~ExtensionAppShimHandler() {} @@ -399,14 +384,6 @@ void ExtensionAppShimHandler::Observe( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_BROWSER_OPENED) { - registrar_.Remove( - this, chrome::NOTIFICATION_BROWSER_OPENED, - content::NotificationService::AllBrowserContextsAndSources()); - browser_opened_ever_ = true; - return; - } - Profile* profile = content::Source<Profile>(source).ptr(); if (profile->IsOffTheRecord()) return; @@ -461,7 +438,7 @@ void ExtensionAppShimHandler::OnAppDeactivated(Profile* profile, if (host) host->OnAppClosed(); - if (!browser_opened_ever_ && hosts_.empty()) + if (hosts_.empty()) delegate_->MaybeTerminate(); } diff --git a/apps/app_shim/extension_app_shim_handler_mac.h b/apps/app_shim/extension_app_shim_handler_mac.h index 6c287a6..140fc02 100644 --- a/apps/app_shim/extension_app_shim_handler_mac.h +++ b/apps/app_shim/extension_app_shim_handler_mac.h @@ -127,8 +127,6 @@ class ExtensionAppShimHandler : public AppShimHandler, content::NotificationRegistrar registrar_; - bool browser_opened_ever_; - base::WeakPtrFactory<ExtensionAppShimHandler> weak_factory_; DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandler); diff --git a/apps/app_shim/extension_app_shim_handler_mac_unittest.cc b/apps/app_shim/extension_app_shim_handler_mac_unittest.cc index d0ac3b0..b6a156f 100644 --- a/apps/app_shim/extension_app_shim_handler_mac_unittest.cc +++ b/apps/app_shim/extension_app_shim_handler_mac_unittest.cc @@ -342,19 +342,6 @@ TEST_F(ExtensionAppShimHandlerTest, MaybeTerminate) { // Quitting when it's the last shim should terminate. EXPECT_CALL(*delegate_, MaybeTerminate()); handler_->OnAppDeactivated(&profile_a_, kTestAppIdB); - - // Launch a shim again. - EXPECT_CALL(host_aa_, OnAppLaunchComplete(APP_SHIM_LAUNCH_SUCCESS)); - RegisterOnlyLaunch(&host_aa_); - EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA)); - - // Quitting after a browser window has opened should not terminate. - handler_->Observe(chrome::NOTIFICATION_BROWSER_OPENED, - content::NotificationService::AllSources(), - content::NotificationService::NoDetails()); - EXPECT_CALL(*delegate_, MaybeTerminate()) - .Times(0); - handler_->OnAppDeactivated(&profile_a_, kTestAppIdA); } TEST_F(ExtensionAppShimHandlerTest, RegisterOnly) { |