| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/profiles/profile_manager.h" | 30 #include "chrome/browser/profiles/profile_manager.h" |
| 31 #include "chrome/browser/service/service_process_control.h" | 31 #include "chrome/browser/service/service_process_control.h" |
| 32 #include "chrome/browser/sessions/session_service.h" | 32 #include "chrome/browser/sessions/session_service.h" |
| 33 #include "chrome/browser/sessions/session_service_factory.h" | 33 #include "chrome/browser/sessions/session_service_factory.h" |
| 34 #include "chrome/browser/sessions/tab_restore_service.h" | 34 #include "chrome/browser/sessions/tab_restore_service.h" |
| 35 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 35 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 36 #include "chrome/browser/sync/profile_sync_service.h" | 36 #include "chrome/browser/sync/profile_sync_service.h" |
| 37 #include "chrome/browser/sync/sync_ui_util.h" | 37 #include "chrome/browser/sync/sync_ui_util.h" |
| 38 #include "chrome/browser/sync/sync_ui_util_mac.h" | 38 #include "chrome/browser/sync/sync_ui_util_mac.h" |
| 39 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
| 40 #include "chrome/browser/ui/browser_finder.h" |
| 40 #include "chrome/browser/ui/browser_list.h" | 41 #include "chrome/browser/ui/browser_list.h" |
| 41 #include "chrome/browser/ui/browser_window.h" | 42 #include "chrome/browser/ui/browser_window.h" |
| 42 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 43 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 43 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 44 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
| 44 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 45 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
| 45 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 46 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 46 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 47 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 47 #import "chrome/browser/ui/cocoa/confirm_quit.h" | 48 #import "chrome/browser/ui/cocoa/confirm_quit.h" |
| 48 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" | 49 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" |
| 49 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" | 50 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // global flag here, analogue to StartupBrowserCreator::InProcessStartup() | 100 // global flag here, analogue to StartupBrowserCreator::InProcessStartup() |
| 100 // because otherwise the SessionService will try to restore sessions when we | 101 // because otherwise the SessionService will try to restore sessions when we |
| 101 // make a new window while there are no other active windows. | 102 // make a new window while there are no other active windows. |
| 102 bool g_is_opening_new_window = false; | 103 bool g_is_opening_new_window = false; |
| 103 | 104 |
| 104 // Activates a browser window having the given profile (the last one active) if | 105 // Activates a browser window having the given profile (the last one active) if |
| 105 // possible and returns a pointer to the activate |Browser| or NULL if this was | 106 // possible and returns a pointer to the activate |Browser| or NULL if this was |
| 106 // not possible. If the last active browser is minimized (in particular, if | 107 // not possible. If the last active browser is minimized (in particular, if |
| 107 // there are only minimized windows), it will unminimize it. | 108 // there are only minimized windows), it will unminimize it. |
| 108 Browser* ActivateBrowser(Profile* profile) { | 109 Browser* ActivateBrowser(Profile* profile) { |
| 109 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 110 Browser* browser = browser::FindLastActiveWithProfile(profile); |
| 110 if (browser) | 111 if (browser) |
| 111 browser->window()->Activate(); | 112 browser->window()->Activate(); |
| 112 return browser; | 113 return browser; |
| 113 } | 114 } |
| 114 | 115 |
| 115 // Creates an empty browser window with the given profile and returns a pointer | 116 // Creates an empty browser window with the given profile and returns a pointer |
| 116 // to the new |Browser|. | 117 // to the new |Browser|. |
| 117 Browser* CreateBrowser(Profile* profile) { | 118 Browser* CreateBrowser(Profile* profile) { |
| 118 { | 119 { |
| 119 AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true); | 120 AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 CHECK_EQ(0u, BrowserList::size()); | 366 CHECK_EQ(0u, BrowserList::size()); |
| 366 | 367 |
| 367 // Tell BrowserList not to keep the browser process alive. Once all the | 368 // Tell BrowserList not to keep the browser process alive. Once all the |
| 368 // browsers get dealloc'd, it will stop the RunLoop and fall back into main(). | 369 // browsers get dealloc'd, it will stop the RunLoop and fall back into main(). |
| 369 BrowserList::EndKeepAlive(); | 370 BrowserList::EndKeepAlive(); |
| 370 | 371 |
| 371 [self unregisterEventHandlers]; | 372 [self unregisterEventHandlers]; |
| 372 } | 373 } |
| 373 | 374 |
| 374 - (void)didEndMainMessageLoop { | 375 - (void)didEndMainMessageLoop { |
| 375 DCHECK(!BrowserList::HasBrowserWithProfile([self lastProfile])); | 376 DCHECK_EQ(0u, browser::GetBrowserCount([self lastProfile])); |
| 376 if (!BrowserList::HasBrowserWithProfile([self lastProfile])) { | 377 if (!browser::GetBrowserCount([self lastProfile])) { |
| 377 // As we're shutting down, we need to nuke the TabRestoreService, which | 378 // As we're shutting down, we need to nuke the TabRestoreService, which |
| 378 // will start the shutdown of the NavigationControllers and allow for | 379 // will start the shutdown of the NavigationControllers and allow for |
| 379 // proper shutdown. If we don't do this, Chrome won't shut down cleanly, | 380 // proper shutdown. If we don't do this, Chrome won't shut down cleanly, |
| 380 // and may end up crashing when some thread tries to use the IO thread (or | 381 // and may end up crashing when some thread tries to use the IO thread (or |
| 381 // another thread) that is no longer valid. | 382 // another thread) that is no longer valid. |
| 382 TabRestoreServiceFactory::ResetForProfile([self lastProfile]); | 383 TabRestoreServiceFactory::ResetForProfile([self lastProfile]); |
| 383 } | 384 } |
| 384 } | 385 } |
| 385 | 386 |
| 386 // If the window has a tab controller, make "close window" be cmd-shift-w, | 387 // If the window has a tab controller, make "close window" be cmd-shift-w, |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 DownloadService* download_service = | 676 DownloadService* download_service = |
| 676 DownloadServiceFactory::GetForProfile(profiles[i]); | 677 DownloadServiceFactory::GetForProfile(profiles[i]); |
| 677 DownloadManager* download_manager = | 678 DownloadManager* download_manager = |
| 678 (download_service->HasCreatedDownloadManager() ? | 679 (download_service->HasCreatedDownloadManager() ? |
| 679 download_service->GetDownloadManager() : NULL); | 680 download_service->GetDownloadManager() : NULL); |
| 680 if (download_manager && download_manager->InProgressCount() > 0) { | 681 if (download_manager && download_manager->InProgressCount() > 0) { |
| 681 int downloadCount = download_manager->InProgressCount(); | 682 int downloadCount = download_manager->InProgressCount(); |
| 682 if ([self userWillWaitForInProgressDownloads:downloadCount]) { | 683 if ([self userWillWaitForInProgressDownloads:downloadCount]) { |
| 683 // Create a new browser window (if necessary) and navigate to the | 684 // Create a new browser window (if necessary) and navigate to the |
| 684 // downloads page if the user chooses to wait. | 685 // downloads page if the user chooses to wait. |
| 685 Browser* browser = BrowserList::FindBrowserWithProfile(profiles[i]); | 686 Browser* browser = browser::FindBrowserWithProfile(profiles[i]); |
| 686 if (!browser) { | 687 if (!browser) { |
| 687 browser = Browser::Create(profiles[i]); | 688 browser = Browser::Create(profiles[i]); |
| 688 browser->window()->Show(); | 689 browser->window()->Show(); |
| 689 } | 690 } |
| 690 DCHECK(browser); | 691 DCHECK(browser); |
| 691 browser->ShowDownloadsTab(); | 692 browser->ShowDownloadsTab(); |
| 692 return NO; | 693 return NO; |
| 693 } | 694 } |
| 694 | 695 |
| 695 // User wants to exit. | 696 // User wants to exit. |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1316 | 1317 |
| 1317 } // namespace browser | 1318 } // namespace browser |
| 1318 | 1319 |
| 1319 namespace app_controller_mac { | 1320 namespace app_controller_mac { |
| 1320 | 1321 |
| 1321 bool IsOpeningNewWindow() { | 1322 bool IsOpeningNewWindow() { |
| 1322 return g_is_opening_new_window; | 1323 return g_is_opening_new_window; |
| 1323 } | 1324 } |
| 1324 | 1325 |
| 1325 } // namespace app_controller_mac | 1326 } // namespace app_controller_mac |
| OLD | NEW |