| 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 #include "chrome/browser/lifetime/application_lifetime.h" | 5 #include "chrome/browser/lifetime/application_lifetime.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/process/process.h" | 12 #include "base/process/process.h" |
| 13 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/browser_process_platform_part.h" | 16 #include "chrome/browser/browser_process_platform_part.h" |
| 17 #include "chrome/browser/browser_shutdown.h" | 17 #include "chrome/browser/browser_shutdown.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/download/download_service.h" | 19 #include "chrome/browser/download/download_service.h" |
| 20 #include "chrome/browser/lifetime/browser_close_manager.h" | 20 #include "chrome/browser/lifetime/browser_close_manager.h" |
| 21 #include "chrome/browser/metrics/thread_watcher.h" | 21 #include "chrome/browser/metrics/thread_watcher.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
| 26 #include "chrome/browser/ui/browser_iterator.h" | 26 #include "chrome/browser/ui/browser_list.h" |
| 27 #include "chrome/browser/ui/browser_tabstrip.h" | 27 #include "chrome/browser/ui/browser_tabstrip.h" |
| 28 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
| 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 30 #include "chrome/browser/ui/user_manager.h" | 30 #include "chrome/browser/ui/user_manager.h" |
| 31 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
| 32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 33 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/navigation_details.h" | 34 #include "content/public/browser/navigation_details.h" |
| 35 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 36 | 36 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 namespace chrome { | 49 namespace chrome { |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 #if !defined(OS_ANDROID) | 52 #if !defined(OS_ANDROID) |
| 53 // Returns true if all browsers can be closed without user interaction. | 53 // Returns true if all browsers can be closed without user interaction. |
| 54 // This currently checks if there is pending download, or if it needs to | 54 // This currently checks if there is pending download, or if it needs to |
| 55 // handle unload handler. | 55 // handle unload handler. |
| 56 bool AreAllBrowsersCloseable() { | 56 bool AreAllBrowsersCloseable() { |
| 57 chrome::BrowserIterator browser_it; | 57 if (BrowserList::GetInstance()->empty()) |
| 58 if (browser_it.done()) | |
| 59 return true; | 58 return true; |
| 60 | 59 |
| 61 // If there are any downloads active, all browsers are not closeable. | 60 // If there are any downloads active, all browsers are not closeable. |
| 62 // However, this does not block for malicious downloads. | 61 // However, this does not block for malicious downloads. |
| 63 if (DownloadService::NonMaliciousDownloadCountAllProfiles() > 0) | 62 if (DownloadService::NonMaliciousDownloadCountAllProfiles() > 0) |
| 64 return false; | 63 return false; |
| 65 | 64 |
| 66 // Check TabsNeedBeforeUnloadFired(). | 65 // Check TabsNeedBeforeUnloadFired(). |
| 67 for (; !browser_it.done(); browser_it.Next()) { | 66 for (auto& browser : *BrowserList::GetInstance()) { |
| 68 if (browser_it->TabsNeedBeforeUnloadFired()) | 67 if (browser->TabsNeedBeforeUnloadFired()) |
| 69 return false; | 68 return false; |
| 70 } | 69 } |
| 71 return true; | 70 return true; |
| 72 } | 71 } |
| 73 #endif // !defined(OS_ANDROID) | 72 #endif // !defined(OS_ANDROID) |
| 74 | 73 |
| 75 int g_keep_alive_count = 0; | 74 int g_keep_alive_count = 0; |
| 76 bool g_disable_shutdown_for_testing = false; | 75 bool g_disable_shutdown_for_testing = false; |
| 77 | 76 |
| 78 #if defined(OS_CHROMEOS) | 77 #if defined(OS_CHROMEOS) |
| 79 // Whether chrome should send stop request to a session manager. | 78 // Whether chrome should send stop request to a session manager. |
| 80 bool g_send_stop_request_to_session_manager = false; | 79 bool g_send_stop_request_to_session_manager = false; |
| 81 #endif | 80 #endif |
| 82 | 81 |
| 83 } // namespace | 82 } // namespace |
| 84 | 83 |
| 85 void MarkAsCleanShutdown() { | 84 void MarkAsCleanShutdown() { |
| 86 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles() instead? | 85 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles() instead? |
| 87 for (chrome::BrowserIterator it; !it.done(); it.Next()) | 86 for (auto& browser : *BrowserList::GetInstance()) |
| 88 it->profile()->SetExitType(Profile::EXIT_NORMAL); | 87 browser->profile()->SetExitType(Profile::EXIT_NORMAL); |
| 89 } | 88 } |
| 90 | 89 |
| 91 void AttemptExitInternal(bool try_to_quit_application) { | 90 void AttemptExitInternal(bool try_to_quit_application) { |
| 92 // On Mac, the platform-specific part handles setting this. | 91 // On Mac, the platform-specific part handles setting this. |
| 93 #if !defined(OS_MACOSX) | 92 #if !defined(OS_MACOSX) |
| 94 if (try_to_quit_application) | 93 if (try_to_quit_application) |
| 95 browser_shutdown::SetTryingToQuit(true); | 94 browser_shutdown::SetTryingToQuit(true); |
| 96 #endif | 95 #endif |
| 97 | 96 |
| 98 content::NotificationService::current()->Notify( | 97 content::NotificationService::current()->Notify( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 PrefService* pref_service = g_browser_process->local_state(); | 168 PrefService* pref_service = g_browser_process->local_state(); |
| 170 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); | 169 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); |
| 171 AttemptExitInternal(false); | 170 AttemptExitInternal(false); |
| 172 #endif | 171 #endif |
| 173 } | 172 } |
| 174 | 173 |
| 175 // The Android implementation is in application_lifetime_android.cc | 174 // The Android implementation is in application_lifetime_android.cc |
| 176 #if !defined(OS_ANDROID) | 175 #if !defined(OS_ANDROID) |
| 177 void AttemptRestart() { | 176 void AttemptRestart() { |
| 178 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? | 177 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? |
| 179 for (chrome::BrowserIterator it; !it.done(); it.Next()) | 178 for (auto& browser : *BrowserList::GetInstance()) |
| 180 content::BrowserContext::SaveSessionState(it->profile()); | 179 content::BrowserContext::SaveSessionState(browser->profile()); |
| 181 | 180 |
| 182 PrefService* pref_service = g_browser_process->local_state(); | 181 PrefService* pref_service = g_browser_process->local_state(); |
| 183 pref_service->SetBoolean(prefs::kWasRestarted, true); | 182 pref_service->SetBoolean(prefs::kWasRestarted, true); |
| 184 | 183 |
| 185 #if defined(OS_CHROMEOS) | 184 #if defined(OS_CHROMEOS) |
| 186 chromeos::BootTimesRecorder::Get()->set_restart_requested(); | 185 chromeos::BootTimesRecorder::Get()->set_restart_requested(); |
| 187 | 186 |
| 188 DCHECK(!g_send_stop_request_to_session_manager); | 187 DCHECK(!g_send_stop_request_to_session_manager); |
| 189 // Make sure we don't send stop request to the session manager. | 188 // Make sure we don't send stop request to the session manager. |
| 190 g_send_stop_request_to_session_manager = false; | 189 g_send_stop_request_to_session_manager = false; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 HandleAppExitingForPlatform(); | 366 HandleAppExitingForPlatform(); |
| 368 } | 367 } |
| 369 | 368 |
| 370 void DisableShutdownForTesting(bool disable_shutdown_for_testing) { | 369 void DisableShutdownForTesting(bool disable_shutdown_for_testing) { |
| 371 g_disable_shutdown_for_testing = disable_shutdown_for_testing; | 370 g_disable_shutdown_for_testing = disable_shutdown_for_testing; |
| 372 if (!g_disable_shutdown_for_testing && !WillKeepAlive()) | 371 if (!g_disable_shutdown_for_testing && !WillKeepAlive()) |
| 373 CloseAllBrowsersIfNeeded(); | 372 CloseAllBrowsersIfNeeded(); |
| 374 } | 373 } |
| 375 | 374 |
| 376 } // namespace chrome | 375 } // namespace chrome |
| OLD | NEW |