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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 | 88 |
89 void AttemptExitInternal() { | 89 void AttemptExitInternal() { |
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 g_browser_process->platform_part()->AttemptExit(); | 95 g_browser_process->platform_part()->AttemptExit(); |
96 } | 96 } |
97 | 97 |
98 void CloseAllBrowsersAndQuit() { | |
99 browser_shutdown::SetTryingToQuit(true); | |
100 CloseAllBrowsers(); | |
101 } | |
102 | |
98 void CloseAllBrowsers() { | 103 void CloseAllBrowsers() { |
99 // If there are no browsers, send the APP_TERMINATING action here. Otherwise, | 104 // 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. | 105 // application, send the APP_TERMINATING action here. Otherwise, it will be |
106 // sent by RemoveBrowser() when the last browser has closed. | |
101 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() || | 107 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() || |
102 chrome::GetTotalBrowserCount() == 0) { | 108 (chrome::GetTotalBrowserCount() == 0 && |
103 // Tell everyone that we are shutting down. | 109 (browser_shutdown::IsTryingToQuit() || !chrome::WillKeepAlive()))) { |
benwells
2013/10/21 05:57:22
Why did the SetTryingToQuit(true) line get removed
Sam McNally
2013/10/21 06:45:35
Done.
benwells
2013/10/21 21:12:51
Sorry, I'm probably being dense here but why don't
| |
104 browser_shutdown::SetTryingToQuit(true); | |
105 | 110 |
106 #if defined(ENABLE_SESSION_SERVICE) | 111 #if defined(ENABLE_SESSION_SERVICE) |
107 // If ShuttingDownWithoutClosingBrowsers() returns true, the session | 112 // If ShuttingDownWithoutClosingBrowsers() returns true, the session |
108 // services may not get a chance to shut down normally, so explicitly shut | 113 // 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. | 114 // them down here to ensure they have a chance to persist their data. |
110 ProfileManager::ShutdownSessionServices(); | 115 ProfileManager::ShutdownSessionServices(); |
111 #endif | 116 #endif |
112 | 117 |
113 chrome::NotifyAndTerminate(true); | 118 chrome::NotifyAndTerminate(true); |
114 chrome::OnAppExiting(); | 119 chrome::OnAppExiting(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 base::debug::TraceLog::GetInstance()->SetEnabled( | 170 base::debug::TraceLog::GetInstance()->SetEnabled( |
166 category_filter, | 171 category_filter, |
167 base::debug::TraceLog::RECORD_UNTIL_FULL); | 172 base::debug::TraceLog::RECORD_UNTIL_FULL); |
168 } | 173 } |
169 TRACE_EVENT0("shutdown", "StartShutdownTracing"); | 174 TRACE_EVENT0("shutdown", "StartShutdownTracing"); |
170 } | 175 } |
171 | 176 |
172 // The Android implementation is in application_lifetime_android.cc | 177 // The Android implementation is in application_lifetime_android.cc |
173 #if !defined(OS_ANDROID) | 178 #if !defined(OS_ANDROID) |
174 void AttemptRestart() { | 179 void AttemptRestart() { |
180 // Tell everyone that we are shutting down. | |
181 browser_shutdown::SetTryingToQuit(true); | |
182 | |
175 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? | 183 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? |
176 for (chrome::BrowserIterator it; !it.done(); it.Next()) | 184 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
177 content::BrowserContext::SaveSessionState(it->profile()); | 185 content::BrowserContext::SaveSessionState(it->profile()); |
178 | 186 |
179 PrefService* pref_service = g_browser_process->local_state(); | 187 PrefService* pref_service = g_browser_process->local_state(); |
180 pref_service->SetBoolean(prefs::kWasRestarted, true); | 188 pref_service->SetBoolean(prefs::kWasRestarted, true); |
181 | 189 |
182 #if defined(OS_CHROMEOS) | 190 #if defined(OS_CHROMEOS) |
183 // For CrOS instead of browser restart (which is not supported) perform a full | 191 // For CrOS instead of browser restart (which is not supported) perform a full |
184 // sign out. Session will be only restored if user has that setting set. | 192 // sign out. Session will be only restored if user has that setting set. |
(...skipping 11 matching lines...) Expand all Loading... | |
196 void AttemptRestartWithModeSwitch() { | 204 void AttemptRestartWithModeSwitch() { |
197 // The kRestartSwitchMode preference does not exists for Windows 7 and older | 205 // The kRestartSwitchMode preference does not exists for Windows 7 and older |
198 // operating systems so there is no need for OS version check. | 206 // operating systems so there is no need for OS version check. |
199 PrefService* prefs = g_browser_process->local_state(); | 207 PrefService* prefs = g_browser_process->local_state(); |
200 prefs->SetBoolean(prefs::kRestartSwitchMode, true); | 208 prefs->SetBoolean(prefs::kRestartSwitchMode, true); |
201 AttemptRestart(); | 209 AttemptRestart(); |
202 } | 210 } |
203 #endif | 211 #endif |
204 | 212 |
205 void AttemptExit() { | 213 void AttemptExit() { |
214 // Tell everyone that we are shutting down. | |
215 browser_shutdown::SetTryingToQuit(true); | |
216 | |
206 // If we know that all browsers can be closed without blocking, | 217 // If we know that all browsers can be closed without blocking, |
207 // don't notify users of crashes beyond this point. | 218 // don't notify users of crashes beyond this point. |
208 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit | 219 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit |
209 // so crashes during shutdown are still reported in UMA. | 220 // so crashes during shutdown are still reported in UMA. |
210 #if !defined(OS_ANDROID) | 221 #if !defined(OS_ANDROID) |
211 // Android doesn't use Browser. | 222 // Android doesn't use Browser. |
212 if (AreAllBrowsersCloseable()) | 223 if (AreAllBrowsersCloseable()) |
213 MarkAsCleanShutdown(); | 224 MarkAsCleanShutdown(); |
214 #endif | 225 #endif |
215 AttemptExitInternal(); | 226 AttemptExitInternal(); |
216 } | 227 } |
217 | 228 |
218 #if defined(OS_CHROMEOS) | 229 #if defined(OS_CHROMEOS) |
219 // A function called when SIGTERM is received. | 230 // A function called when SIGTERM is received. |
220 void ExitCleanly() { | 231 void ExitCleanly() { |
221 // We always mark exit cleanly because SessionManager may kill | 232 // We always mark exit cleanly because SessionManager may kill |
222 // chrome in 3 seconds after SIGTERM. | 233 // chrome in 3 seconds after SIGTERM. |
223 g_browser_process->EndSession(); | 234 g_browser_process->EndSession(); |
224 | 235 |
236 // Tell everyone that we are shutting down. | |
237 browser_shutdown::SetTryingToQuit(true); | |
238 | |
225 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() | 239 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() |
226 // can be false in following cases. a) power-off b) signout from | 240 // can be false in following cases. a) power-off b) signout from |
227 // screen locker. | 241 // screen locker. |
228 if (!AreAllBrowsersCloseable()) | 242 if (!AreAllBrowsersCloseable()) |
229 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); | 243 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); |
230 AttemptExitInternal(); | 244 AttemptExitInternal(); |
231 } | 245 } |
232 #endif | 246 #endif |
233 | 247 |
234 void SessionEnding() { | 248 void SessionEnding() { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 // environment is still active. | 393 // environment is still active. |
380 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) | 394 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) |
381 return !ash::Shell::HasInstance(); | 395 return !ash::Shell::HasInstance(); |
382 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) | 396 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) |
383 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); | 397 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); |
384 #endif | 398 #endif |
385 return true; | 399 return true; |
386 } | 400 } |
387 | 401 |
388 } // namespace chrome | 402 } // namespace chrome |
OLD | NEW |