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 #import "chrome/browser/app_controller_mac.h" | 5 #import "chrome/browser/app_controller_mac.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/mac/foundation_util.h" | 11 #include "base/mac/foundation_util.h" |
12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
18 #include "chrome/browser/background/background_application_list_model.h" | 18 #include "chrome/browser/background/background_application_list_model.h" |
19 #include "chrome/browser/background/background_mode_manager.h" | 19 #include "chrome/browser/background/background_mode_manager.h" |
20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/browser_shutdown.h" | 21 #include "chrome/browser/browser_shutdown.h" |
22 #include "chrome/browser/command_updater.h" | 22 #include "chrome/browser/command_updater.h" |
23 #include "chrome/browser/download/download_service.h" | 23 #include "chrome/browser/download/download_service.h" |
24 #include "chrome/browser/download/download_service_factory.h" | 24 #include "chrome/browser/download/download_service_factory.h" |
25 #include "chrome/browser/first_run/first_run.h" | 25 #include "chrome/browser/first_run/first_run.h" |
| 26 #include "chrome/browser/lifetime/application_lifetime.h" |
26 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
27 #include "chrome/browser/printing/cloud_print/virtual_driver_install_helper.h" | 28 #include "chrome/browser/printing/cloud_print/virtual_driver_install_helper.h" |
28 #include "chrome/browser/printing/print_dialog_cloud.h" | 29 #include "chrome/browser/printing/print_dialog_cloud.h" |
29 #include "chrome/browser/printing/print_job_manager.h" | 30 #include "chrome/browser/printing/print_job_manager.h" |
30 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" |
31 #include "chrome/browser/service/service_process_control.h" | 32 #include "chrome/browser/service/service_process_control.h" |
32 #include "chrome/browser/sessions/session_service.h" | 33 #include "chrome/browser/sessions/session_service.h" |
33 #include "chrome/browser/sessions/session_service_factory.h" | 34 #include "chrome/browser/sessions/session_service_factory.h" |
34 #include "chrome/browser/sessions/tab_restore_service.h" | 35 #include "chrome/browser/sessions/tab_restore_service.h" |
35 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 36 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 if (!browser_shutdown::IsTryingToQuit() && | 312 if (!browser_shutdown::IsTryingToQuit() && |
312 [self applicationShouldTerminate:app] != NSTerminateNow) | 313 [self applicationShouldTerminate:app] != NSTerminateNow) |
313 return NO; | 314 return NO; |
314 | 315 |
315 size_t num_browsers = BrowserList::size(); | 316 size_t num_browsers = BrowserList::size(); |
316 | 317 |
317 // Give any print jobs in progress time to finish. | 318 // Give any print jobs in progress time to finish. |
318 if (!browser_shutdown::IsTryingToQuit()) | 319 if (!browser_shutdown::IsTryingToQuit()) |
319 g_browser_process->print_job_manager()->StopJobs(true); | 320 g_browser_process->print_job_manager()->StopJobs(true); |
320 | 321 |
321 // Initiate a shutdown (via BrowserList::CloseAllBrowsers()) if we aren't | 322 // Initiate a shutdown (via browser::CloseAllBrowsers()) if we aren't |
322 // already shutting down. | 323 // already shutting down. |
323 if (!browser_shutdown::IsTryingToQuit()) { | 324 if (!browser_shutdown::IsTryingToQuit()) { |
324 content::NotificationService::current()->Notify( | 325 content::NotificationService::current()->Notify( |
325 content::NOTIFICATION_APP_EXITING, | 326 content::NOTIFICATION_APP_EXITING, |
326 content::NotificationService::AllSources(), | 327 content::NotificationService::AllSources(), |
327 content::NotificationService::NoDetails()); | 328 content::NotificationService::NoDetails()); |
328 BrowserList::CloseAllBrowsers(); | 329 browser::CloseAllBrowsers(); |
329 } | 330 } |
330 | 331 |
331 return num_browsers == 0 ? YES : NO; | 332 return num_browsers == 0 ? YES : NO; |
332 } | 333 } |
333 | 334 |
334 - (void)stopTryingToTerminateApplication:(NSApplication*)app { | 335 - (void)stopTryingToTerminateApplication:(NSApplication*)app { |
335 if (browser_shutdown::IsTryingToQuit()) { | 336 if (browser_shutdown::IsTryingToQuit()) { |
336 // Reset the "trying to quit" state, so that closing all browser windows | 337 // Reset the "trying to quit" state, so that closing all browser windows |
337 // will no longer lead to termination. | 338 // will no longer lead to termination. |
338 browser_shutdown::SetTryingToQuit(false); | 339 browser_shutdown::SetTryingToQuit(false); |
(...skipping 23 matching lines...) Expand all Loading... |
362 runModalLoopForApplication:app]; | 363 runModalLoopForApplication:app]; |
363 } | 364 } |
364 | 365 |
365 // Called when the app is shutting down. Clean-up as appropriate. | 366 // Called when the app is shutting down. Clean-up as appropriate. |
366 - (void)applicationWillTerminate:(NSNotification*)aNotification { | 367 - (void)applicationWillTerminate:(NSNotification*)aNotification { |
367 // There better be no browser windows left at this point. | 368 // There better be no browser windows left at this point. |
368 CHECK_EQ(0u, BrowserList::size()); | 369 CHECK_EQ(0u, BrowserList::size()); |
369 | 370 |
370 // Tell BrowserList not to keep the browser process alive. Once all the | 371 // Tell BrowserList not to keep the browser process alive. Once all the |
371 // browsers get dealloc'd, it will stop the RunLoop and fall back into main(). | 372 // browsers get dealloc'd, it will stop the RunLoop and fall back into main(). |
372 BrowserList::EndKeepAlive(); | 373 browser::EndKeepAlive(); |
373 | 374 |
374 [self unregisterEventHandlers]; | 375 [self unregisterEventHandlers]; |
375 } | 376 } |
376 | 377 |
377 - (void)didEndMainMessageLoop { | 378 - (void)didEndMainMessageLoop { |
378 DCHECK_EQ(0u, browser::GetBrowserCount([self lastProfile])); | 379 DCHECK_EQ(0u, browser::GetBrowserCount([self lastProfile])); |
379 if (!browser::GetBrowserCount([self lastProfile])) { | 380 if (!browser::GetBrowserCount([self lastProfile])) { |
380 // As we're shutting down, we need to nuke the TabRestoreService, which | 381 // As we're shutting down, we need to nuke the TabRestoreService, which |
381 // will start the shutdown of the NavigationControllers and allow for | 382 // will start the shutdown of the NavigationControllers and allow for |
382 // proper shutdown. If we don't do this, Chrome won't shut down cleanly, | 383 // proper shutdown. If we don't do this, Chrome won't shut down cleanly, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 CFPreferencesAppSynchronize(app); | 568 CFPreferencesAppSynchronize(app); |
568 } | 569 } |
569 #endif | 570 #endif |
570 } | 571 } |
571 | 572 |
572 // This is called after profiles have been loaded and preferences registered. | 573 // This is called after profiles have been loaded and preferences registered. |
573 // It is safe to access the default profile here. | 574 // It is safe to access the default profile here. |
574 - (void)applicationDidFinishLaunching:(NSNotification*)notify { | 575 - (void)applicationDidFinishLaunching:(NSNotification*)notify { |
575 // Notify BrowserList to keep the application running so it doesn't go away | 576 // Notify BrowserList to keep the application running so it doesn't go away |
576 // when all the browser windows get closed. | 577 // when all the browser windows get closed. |
577 BrowserList::StartKeepAlive(); | 578 browser::StartKeepAlive(); |
578 | 579 |
579 [self setUpdateCheckInterval]; | 580 [self setUpdateCheckInterval]; |
580 | 581 |
581 // Build up the encoding menu, the order of the items differs based on the | 582 // Build up the encoding menu, the order of the items differs based on the |
582 // current locale (see http://crbug.com/7647 for details). | 583 // current locale (see http://crbug.com/7647 for details). |
583 // We need a valid g_browser_process to get the profile which is why we can't | 584 // We need a valid g_browser_process to get the profile which is why we can't |
584 // call this from awakeFromNib. | 585 // call this from awakeFromNib. |
585 NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu]; | 586 NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu]; |
586 NSMenuItem* encodingMenuItem = [viewMenu itemWithTag:IDC_ENCODING_MENU]; | 587 NSMenuItem* encodingMenuItem = [viewMenu itemWithTag:IDC_ENCODING_MENU]; |
587 NSMenu* encodingMenu = [encodingMenuItem submenu]; | 588 NSMenu* encodingMenu = [encodingMenuItem submenu]; |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 | 1320 |
1320 } // namespace browser | 1321 } // namespace browser |
1321 | 1322 |
1322 namespace app_controller_mac { | 1323 namespace app_controller_mac { |
1323 | 1324 |
1324 bool IsOpeningNewWindow() { | 1325 bool IsOpeningNewWindow() { |
1325 return g_is_opening_new_window; | 1326 return g_is_opening_new_window; |
1326 } | 1327 } |
1327 | 1328 |
1328 } // namespace app_controller_mac | 1329 } // namespace app_controller_mac |
OLD | NEW |