summaryrefslogtreecommitdiffstats
path: root/chrome/browser/app_controller_mac.mm
diff options
context:
space:
mode:
authorjackhou <jackhou@chromium.org>2015-01-12 20:51:41 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-13 04:52:18 +0000
commitf60ef51534ed50361020392ed74435cfa7d6e311 (patch)
treef73a5e8fe7d93a58168800001f45aea22c6ce749 /chrome/browser/app_controller_mac.mm
parentc998ca372838d0b700c87dd8eda905ab2d1260df (diff)
downloadchromium_src-f60ef51534ed50361020392ed74435cfa7d6e311.zip
chromium_src-f60ef51534ed50361020392ed74435cfa7d6e311.tar.gz
chromium_src-f60ef51534ed50361020392ed74435cfa7d6e311.tar.bz2
[Mac] Do not let apps keep Chrome alive if shutting down.
If the user quits Chrome while Chrome Apps are running, we keep Chrome running in the background and show a notification. When Chrome is terminated because the system is shutting down or the user is logging off, we should make sure Chrome terminates regardless of any running apps. This CL detects whether an [NSApplication terminate:] is due to shutdown or log off by listening for NSWorkspaceWillPowerOffNotification. This notification is only received if Chrome is about to be terminated, i.e. we do not receive the notification if another app prevented shutdown. BUG=442280 Review URL: https://codereview.chromium.org/831813003 Cr-Commit-Position: refs/heads/master@{#311215}
Diffstat (limited to 'chrome/browser/app_controller_mac.mm')
-rw-r--r--chrome/browser/app_controller_mac.mm21
1 files changed, 19 insertions, 2 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 2b8bbfa..12b4398 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -377,6 +377,12 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
name:NSWorkspaceActiveSpaceDidChangeNotification
object:nil];
+ [[[NSWorkspace sharedWorkspace] notificationCenter]
+ addObserver:self
+ selector:@selector(willPowerOff:)
+ name:NSWorkspaceWillPowerOffNotification
+ object:nil];
+
// Set up the command updater for when there are no windows open
[self initMenuState];
@@ -408,6 +414,10 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
}
- (BOOL)tryToTerminateApplication:(NSApplication*)app {
+ // Reset this now that we've received the call to terminate.
+ BOOL isPoweringOff = isPoweringOff_;
+ isPoweringOff_ = NO;
+
// Check for in-process downloads, and prompt the user if they really want
// to quit (and thus cancel downloads). Only check if we're not already
// shutting down, else the user might be prompted multiple times if the
@@ -428,8 +438,8 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
// Check for active apps. If quitting is prevented, only close browsers and
// sessions.
- if (!browser_shutdown::IsTryingToQuit() && quitWithAppsController_.get() &&
- !quitWithAppsController_->ShouldQuit()) {
+ if (!browser_shutdown::IsTryingToQuit() && !isPoweringOff &&
+ quitWithAppsController_.get() && !quitWithAppsController_->ShouldQuit()) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kHostedAppQuitNotification)) {
return NO;
@@ -670,6 +680,13 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
}
}
+// Called when shutting down or logging out.
+- (void)willPowerOff:(NSNotification*)notify {
+ // Don't attempt any shutdown here. Cocoa will shortly call
+ // -[BrowserCrApplication terminate:].
+ isPoweringOff_ = YES;
+}
+
// Called on Lion and later when a popover (e.g. dictionary) is shown.
- (void)popoverDidShow:(NSNotification*)notify {
hasPopover_ = YES;