OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains the penultimate pieces of the Mac shutdown puzzle. For | 5 // This file contains the penultimate pieces of the Mac shutdown puzzle. For |
6 // an in-depth overview of the Mac shutdown path, see the comment above | 6 // an in-depth overview of the Mac shutdown path, see the comment above |
7 // -[BrowserCrApplication terminate:]. | 7 // -[BrowserCrApplication terminate:]. |
8 | 8 |
9 #include "chrome/browser/lifetime/application_lifetime.h" | 9 #include "chrome/browser/lifetime/application_lifetime.h" |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | |
13 #include "chrome/browser/browser_shutdown.h" | 12 #include "chrome/browser/browser_shutdown.h" |
14 #import "chrome/browser/chrome_browser_application_mac.h" | 13 #import "chrome/browser/chrome_browser_application_mac.h" |
15 | 14 |
16 namespace browser { | 15 namespace browser { |
17 | 16 |
18 namespace { | 17 // At this point, the user is trying to quit (or the system is forcing the |
| 18 // application to quit) and all browsers have been successfully closed. The |
| 19 // final step in shutdown is to post the NSApplicationWillTerminateNotification |
| 20 // to end the -[NSApplication run] event loop. |
| 21 void HandleAppExitingForPlatform() { |
| 22 static bool kill_me_now = false; |
| 23 CHECK(!kill_me_now); |
| 24 kill_me_now = true; |
19 | 25 |
20 // A closure that is used to finalize application shutdown. | |
21 void PerformTerminate() { | |
22 [[NSNotificationCenter defaultCenter] | 26 [[NSNotificationCenter defaultCenter] |
23 postNotificationName:NSApplicationWillTerminateNotification | 27 postNotificationName:NSApplicationWillTerminateNotification |
24 object:NSApp]; | 28 object:NSApp]; |
25 } | 29 } |
26 | 30 |
27 } // namespace | |
28 | |
29 // At this point, the user is trying to quit (or the system is forcing the | |
30 // application to quit) and all browsers have been successfully closed. The | |
31 // final step in shutdown is to post the NSApplicationWillTerminateNotification | |
32 // to end the -[NSApplication run] event loop. That is performed via the | |
33 // MessageLoop, since this can be called via the destruction path of the last | |
34 // Browser object. | |
35 void HandleAppExitingForPlatform() { | |
36 static bool kill_me_now = false; | |
37 CHECK(!kill_me_now); | |
38 kill_me_now = true; | |
39 | |
40 MessageLoop::current()->PostNonNestableTask(FROM_HERE, | |
41 base::Bind(&PerformTerminate)); | |
42 } | |
43 | |
44 } // namespace browser | 31 } // namespace browser |
OLD | NEW |