Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/browser/chrome_application_mac.mm

Issue 201121: Chrome should shut down cleanly when quit from the Dock icon menu, during... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chrome_application_mac.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/chrome_application_mac.h"
6
7 @implementation CrApplication
8
9 // -terminate: is the entry point for orderly "quit" operations in Cocoa.
10 // This includes the application menu's quit menu item and keyboard
11 // equivalent, the application's dock icon menu's quit menu item, "quit" (not
12 // "force quit") in the Activity Monitor, and quits triggered by user logout
13 // and system restart and shutdown.
14 //
15 // The default NSApplication -terminate: implementation will end the process
16 // by calling exit(), and thus never leave the main run loop. This is
17 // unsuitable for Chrome's purposes. Chrome depends on leaving the main
18 // run loop to perform a proper orderly shutdown. This design is ingrained
19 // in the application and the assumptions that its code makes, and is
20 // entirely reasonable and works well on other platforms, but it's not
21 // compatible with the standard Cocoa quit sequence. Quits originated from
22 // within the application can be redirected to not use -terminate:, but
23 // quits from elsewhere cannot be.
24 //
25 // To allow the Cocoa-based Chrome to support the standard Cocoa -terminate:
26 // interface, and allow all quits to cause Chrome to shut down properly
27 // regardless of their origin, -terminate: is overriden. The custom
28 // -terminate: does not end the application with exit(). Instead, it simply
29 // returns after posting the normal NSApplicationWillTerminateNotification
30 // notification. The application is responsible for exiting on its own in
31 // whatever way it deems appropriate. In Chrome's case, the main run loop will
32 // end and the applicaton will exit by returning from main().
33 //
34 // This implementation of -terminate: is scaled back and is not as
35 // fully-featured as the implementation in NSApplication, nor is it a direct
36 // drop-in replacement -terminate: in most applications. It is
37 // purpose-specific to Chrome.
38 - (void)terminate:(id)sender {
39 NSApplicationTerminateReply shouldTerminate = NSTerminateNow;
40 SEL selector = @selector(applicationShouldTerminate:);
41 if ([[self delegate] respondsToSelector:selector])
42 shouldTerminate = [[self delegate] applicationShouldTerminate:self];
43
44 // If shouldTerminate is NSTerminateLater, the application is expected to
45 // call -replyToApplicationShouldTerminate: when it knows whether or not it
46 // should terminate. If the argument is YES,
47 // -replyToApplicationShouldTerminate: will call -terminate:. This will
48 // result in another call to the delegate's -applicationShouldTerminate:,
49 // which would be expected to return NSTerminateNow at that point.
50 if (shouldTerminate != NSTerminateNow)
51 return;
52
53 [[NSNotificationCenter defaultCenter]
54 postNotificationName:NSApplicationWillTerminateNotification
55 object:self];
56
57 // Return, don't exit. The application is responsible for exiting on its
58 // own.
59 }
60
61 @end
OLDNEW
« no previous file with comments | « chrome/browser/chrome_application_mac.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698