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