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 "ash/shell.h" | 7 #include "ash/shell.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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 #endif | 79 #endif |
80 | 80 |
81 } // namespace | 81 } // namespace |
82 | 82 |
83 void MarkAsCleanShutdown() { | 83 void MarkAsCleanShutdown() { |
84 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles() instead? | 84 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles() instead? |
85 for (chrome::BrowserIterator it; !it.done(); it.Next()) | 85 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
86 it->profile()->SetExitType(Profile::EXIT_NORMAL); | 86 it->profile()->SetExitType(Profile::EXIT_NORMAL); |
87 } | 87 } |
88 | 88 |
89 void AttemptExitInternal() { | 89 void AttemptExitInternal(bool try_to_quit_application) { |
| 90 // On Mac, the platform-specific part handles setting this. |
| 91 #if !defined(OS_MACOSX) |
| 92 if (try_to_quit_application) |
| 93 browser_shutdown::SetTryingToQuit(true); |
| 94 #endif |
| 95 |
90 content::NotificationService::current()->Notify( | 96 content::NotificationService::current()->Notify( |
91 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | 97 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
92 content::NotificationService::AllSources(), | 98 content::NotificationService::AllSources(), |
93 content::NotificationService::NoDetails()); | 99 content::NotificationService::NoDetails()); |
94 | 100 |
95 g_browser_process->platform_part()->AttemptExit(); | 101 g_browser_process->platform_part()->AttemptExit(); |
96 } | 102 } |
97 | 103 |
| 104 void CloseAllBrowsersAndQuit() { |
| 105 browser_shutdown::SetTryingToQuit(true); |
| 106 CloseAllBrowsers(); |
| 107 } |
| 108 |
98 void CloseAllBrowsers() { | 109 void CloseAllBrowsers() { |
99 // If there are no browsers, send the APP_TERMINATING action here. Otherwise, | 110 // If there are no browsers and closing the last browser would quit the |
100 // it will be sent by RemoveBrowser() when the last browser has closed. | 111 // application, send the APP_TERMINATING action here. Otherwise, it will be |
| 112 // sent by RemoveBrowser() when the last browser has closed. |
101 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() || | 113 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() || |
102 chrome::GetTotalBrowserCount() == 0) { | 114 (chrome::GetTotalBrowserCount() == 0 && |
| 115 (browser_shutdown::IsTryingToQuit() || !chrome::WillKeepAlive() || |
| 116 CommandLine::ForCurrentProcess()->HasSwitch( |
| 117 switches::kDisableBatchedShutdown)))) { |
103 // Tell everyone that we are shutting down. | 118 // Tell everyone that we are shutting down. |
104 browser_shutdown::SetTryingToQuit(true); | 119 browser_shutdown::SetTryingToQuit(true); |
105 | 120 |
106 #if defined(ENABLE_SESSION_SERVICE) | 121 #if defined(ENABLE_SESSION_SERVICE) |
107 // If ShuttingDownWithoutClosingBrowsers() returns true, the session | 122 // If ShuttingDownWithoutClosingBrowsers() returns true, the session |
108 // services may not get a chance to shut down normally, so explicitly shut | 123 // services may not get a chance to shut down normally, so explicitly shut |
109 // them down here to ensure they have a chance to persist their data. | 124 // them down here to ensure they have a chance to persist their data. |
110 ProfileManager::ShutdownSessionServices(); | 125 ProfileManager::ShutdownSessionServices(); |
111 #endif | 126 #endif |
112 | 127 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 161 } |
147 g_session_manager_requested_shutdown = false; | 162 g_session_manager_requested_shutdown = false; |
148 // On ChromeOS, always terminate the browser, regardless of the result of | 163 // On ChromeOS, always terminate the browser, regardless of the result of |
149 // AreAllBrowsersCloseable(). See crbug.com/123107. | 164 // AreAllBrowsersCloseable(). See crbug.com/123107. |
150 chrome::NotifyAndTerminate(true); | 165 chrome::NotifyAndTerminate(true); |
151 #else | 166 #else |
152 // Reset the restart bit that might have been set in cancelled restart | 167 // Reset the restart bit that might have been set in cancelled restart |
153 // request. | 168 // request. |
154 PrefService* pref_service = g_browser_process->local_state(); | 169 PrefService* pref_service = g_browser_process->local_state(); |
155 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); | 170 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); |
156 AttemptExitInternal(); | 171 AttemptExitInternal(false); |
157 #endif | 172 #endif |
158 } | 173 } |
159 | 174 |
160 void StartShutdownTracing() { | 175 void StartShutdownTracing() { |
161 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 176 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
162 if (command_line.HasSwitch(switches::kTraceShutdown)) { | 177 if (command_line.HasSwitch(switches::kTraceShutdown)) { |
163 base::debug::CategoryFilter category_filter( | 178 base::debug::CategoryFilter category_filter( |
164 command_line.GetSwitchValueASCII(switches::kTraceShutdown)); | 179 command_line.GetSwitchValueASCII(switches::kTraceShutdown)); |
165 base::debug::TraceLog::GetInstance()->SetEnabled( | 180 base::debug::TraceLog::GetInstance()->SetEnabled( |
166 category_filter, | 181 category_filter, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 void AttemptExit() { | 220 void AttemptExit() { |
206 // If we know that all browsers can be closed without blocking, | 221 // If we know that all browsers can be closed without blocking, |
207 // don't notify users of crashes beyond this point. | 222 // don't notify users of crashes beyond this point. |
208 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit | 223 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit |
209 // so crashes during shutdown are still reported in UMA. | 224 // so crashes during shutdown are still reported in UMA. |
210 #if !defined(OS_ANDROID) | 225 #if !defined(OS_ANDROID) |
211 // Android doesn't use Browser. | 226 // Android doesn't use Browser. |
212 if (AreAllBrowsersCloseable()) | 227 if (AreAllBrowsersCloseable()) |
213 MarkAsCleanShutdown(); | 228 MarkAsCleanShutdown(); |
214 #endif | 229 #endif |
215 AttemptExitInternal(); | 230 AttemptExitInternal(true); |
216 } | 231 } |
217 | 232 |
218 #if defined(OS_CHROMEOS) | 233 #if defined(OS_CHROMEOS) |
219 // A function called when SIGTERM is received. | 234 // A function called when SIGTERM is received. |
220 void ExitCleanly() { | 235 void ExitCleanly() { |
221 // We always mark exit cleanly because SessionManager may kill | 236 // We always mark exit cleanly because SessionManager may kill |
222 // chrome in 3 seconds after SIGTERM. | 237 // chrome in 3 seconds after SIGTERM. |
223 g_browser_process->EndSession(); | 238 g_browser_process->EndSession(); |
224 | 239 |
225 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() | 240 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() |
226 // can be false in following cases. a) power-off b) signout from | 241 // can be false in following cases. a) power-off b) signout from |
227 // screen locker. | 242 // screen locker. |
228 if (!AreAllBrowsersCloseable()) | 243 if (!AreAllBrowsersCloseable()) |
229 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); | 244 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); |
230 AttemptExitInternal(); | 245 AttemptExitInternal(true); |
231 } | 246 } |
232 #endif | 247 #endif |
233 | 248 |
234 void SessionEnding() { | 249 void SessionEnding() { |
235 // This is a time-limited shutdown where we need to write as much to | 250 // This is a time-limited shutdown where we need to write as much to |
236 // disk as we can as soon as we can, and where we must kill the | 251 // disk as we can as soon as we can, and where we must kill the |
237 // process within a hang timeout to avoid user prompts. | 252 // process within a hang timeout to avoid user prompts. |
238 | 253 |
239 // Start watching for hang during shutdown, and crash it if takes too long. | 254 // Start watching for hang during shutdown, and crash it if takes too long. |
240 // We disarm when |shutdown_watcher| object is destroyed, which is when we | 255 // We disarm when |shutdown_watcher| object is destroyed, which is when we |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // environment is still active. | 394 // environment is still active. |
380 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) | 395 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) |
381 return !ash::Shell::HasInstance(); | 396 return !ash::Shell::HasInstance(); |
382 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) | 397 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) |
383 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); | 398 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); |
384 #endif | 399 #endif |
385 return true; | 400 return true; |
386 } | 401 } |
387 | 402 |
388 } // namespace chrome | 403 } // namespace chrome |
OLD | NEW |