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 content::NotificationService::current()->Notify( | 90 content::NotificationService::current()->Notify( |
91 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | 91 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
92 content::NotificationService::AllSources(), | 92 content::NotificationService::AllSources(), |
93 content::NotificationService::NoDetails()); | 93 content::NotificationService::NoDetails()); |
94 | 94 |
95 // On Mac, the platform-specific part handles setting this. | |
96 #if !defined(OS_MACOSX) | |
sky
2013/10/22 15:41:18
Is there a reason you set trying to quit after sen
Sam McNally
2013/10/22 22:58:29
Done.
| |
97 if (try_to_quit_application) { | |
sky
2013/10/22 15:41:18
nit: no {}
Sam McNally
2013/10/22 22:58:29
Done.
| |
98 browser_shutdown::SetTryingToQuit(true); | |
99 } | |
100 #endif | |
101 | |
95 g_browser_process->platform_part()->AttemptExit(); | 102 g_browser_process->platform_part()->AttemptExit(); |
96 } | 103 } |
97 | 104 |
105 void CloseAllBrowsersAndQuit() { | |
106 browser_shutdown::SetTryingToQuit(true); | |
107 CloseAllBrowsers(); | |
108 } | |
109 | |
98 void CloseAllBrowsers() { | 110 void CloseAllBrowsers() { |
99 // 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 |
100 // 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. | |
101 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() || | 114 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() || |
102 chrome::GetTotalBrowserCount() == 0) { | 115 (chrome::GetTotalBrowserCount() == 0 && |
116 (browser_shutdown::IsTryingToQuit() || !chrome::WillKeepAlive() || | |
117 CommandLine::ForCurrentProcess()->HasSwitch( | |
118 switches::kDisableBatchedShutdown)))) { | |
103 // Tell everyone that we are shutting down. | 119 // Tell everyone that we are shutting down. |
104 browser_shutdown::SetTryingToQuit(true); | 120 browser_shutdown::SetTryingToQuit(true); |
105 | 121 |
106 #if defined(ENABLE_SESSION_SERVICE) | 122 #if defined(ENABLE_SESSION_SERVICE) |
107 // If ShuttingDownWithoutClosingBrowsers() returns true, the session | 123 // If ShuttingDownWithoutClosingBrowsers() returns true, the session |
108 // 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 |
109 // 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. |
110 ProfileManager::ShutdownSessionServices(); | 126 ProfileManager::ShutdownSessionServices(); |
111 #endif | 127 #endif |
112 | 128 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 } | 162 } |
147 g_session_manager_requested_shutdown = false; | 163 g_session_manager_requested_shutdown = false; |
148 // On ChromeOS, always terminate the browser, regardless of the result of | 164 // On ChromeOS, always terminate the browser, regardless of the result of |
149 // AreAllBrowsersCloseable(). See crbug.com/123107. | 165 // AreAllBrowsersCloseable(). See crbug.com/123107. |
150 chrome::NotifyAndTerminate(true); | 166 chrome::NotifyAndTerminate(true); |
151 #else | 167 #else |
152 // 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 |
153 // request. | 169 // request. |
154 PrefService* pref_service = g_browser_process->local_state(); | 170 PrefService* pref_service = g_browser_process->local_state(); |
155 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); | 171 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); |
156 AttemptExitInternal(); | 172 AttemptExitInternal(false); |
157 #endif | 173 #endif |
158 } | 174 } |
159 | 175 |
160 void StartShutdownTracing() { | 176 void StartShutdownTracing() { |
161 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 177 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
162 if (command_line.HasSwitch(switches::kTraceShutdown)) { | 178 if (command_line.HasSwitch(switches::kTraceShutdown)) { |
163 base::debug::CategoryFilter category_filter( | 179 base::debug::CategoryFilter category_filter( |
164 command_line.GetSwitchValueASCII(switches::kTraceShutdown)); | 180 command_line.GetSwitchValueASCII(switches::kTraceShutdown)); |
165 base::debug::TraceLog::GetInstance()->SetEnabled( | 181 base::debug::TraceLog::GetInstance()->SetEnabled( |
166 category_filter, | 182 category_filter, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 void AttemptExit() { | 221 void AttemptExit() { |
206 // If we know that all browsers can be closed without blocking, | 222 // If we know that all browsers can be closed without blocking, |
207 // don't notify users of crashes beyond this point. | 223 // don't notify users of crashes beyond this point. |
208 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit | 224 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit |
209 // so crashes during shutdown are still reported in UMA. | 225 // so crashes during shutdown are still reported in UMA. |
210 #if !defined(OS_ANDROID) | 226 #if !defined(OS_ANDROID) |
211 // Android doesn't use Browser. | 227 // Android doesn't use Browser. |
212 if (AreAllBrowsersCloseable()) | 228 if (AreAllBrowsersCloseable()) |
213 MarkAsCleanShutdown(); | 229 MarkAsCleanShutdown(); |
214 #endif | 230 #endif |
215 AttemptExitInternal(); | 231 AttemptExitInternal(true); |
216 } | 232 } |
217 | 233 |
218 #if defined(OS_CHROMEOS) | 234 #if defined(OS_CHROMEOS) |
219 // A function called when SIGTERM is received. | 235 // A function called when SIGTERM is received. |
220 void ExitCleanly() { | 236 void ExitCleanly() { |
221 // We always mark exit cleanly because SessionManager may kill | 237 // We always mark exit cleanly because SessionManager may kill |
222 // chrome in 3 seconds after SIGTERM. | 238 // chrome in 3 seconds after SIGTERM. |
223 g_browser_process->EndSession(); | 239 g_browser_process->EndSession(); |
224 | 240 |
225 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() | 241 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() |
226 // 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 |
227 // screen locker. | 243 // screen locker. |
228 if (!AreAllBrowsersCloseable()) | 244 if (!AreAllBrowsersCloseable()) |
229 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); | 245 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); |
230 AttemptExitInternal(); | 246 AttemptExitInternal(true); |
231 } | 247 } |
232 #endif | 248 #endif |
233 | 249 |
234 void SessionEnding() { | 250 void SessionEnding() { |
235 // 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 |
236 // 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 |
237 // process within a hang timeout to avoid user prompts. | 253 // process within a hang timeout to avoid user prompts. |
238 | 254 |
239 // 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. |
240 // 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... | |
379 // environment is still active. | 395 // environment is still active. |
380 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) | 396 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) |
381 return !ash::Shell::HasInstance(); | 397 return !ash::Shell::HasInstance(); |
382 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) | 398 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) |
383 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); | 399 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); |
384 #endif | 400 #endif |
385 return true; | 401 return true; |
386 } | 402 } |
387 | 403 |
388 } // namespace chrome | 404 } // namespace chrome |
OLD | NEW |