Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: chrome/browser/lifetime/application_lifetime.cc

Issue 25603004: Leave apps running on Windows and Linux when quitting Chrome from the wrench menu. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, send the APP_TERMINATING action here. Otherwise,
benwells 2013/10/20 23:46:22 Please update this comment too, it doesn't capture
Sam McNally 2013/10/21 04:31:03 Done.
100 // it will be sent by RemoveBrowser() when the last browser has closed. 105 // it will be sent by RemoveBrowser() when the last browser has closed.
101 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() || 106 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() ||
102 chrome::GetTotalBrowserCount() == 0) { 107 (chrome::GetTotalBrowserCount() == 0 &&
103 // Tell everyone that we are shutting down. 108 (browser_shutdown::IsTryingToQuit() || !chrome::WillKeepAlive()))) {
104 browser_shutdown::SetTryingToQuit(true);
105 109
106 #if defined(ENABLE_SESSION_SERVICE) 110 #if defined(ENABLE_SESSION_SERVICE)
107 // If ShuttingDownWithoutClosingBrowsers() returns true, the session 111 // If ShuttingDownWithoutClosingBrowsers() returns true, the session
108 // services may not get a chance to shut down normally, so explicitly shut 112 // 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. 113 // them down here to ensure they have a chance to persist their data.
110 ProfileManager::ShutdownSessionServices(); 114 ProfileManager::ShutdownSessionServices();
111 #endif 115 #endif
112 116
113 chrome::NotifyAndTerminate(true); 117 chrome::NotifyAndTerminate(true);
114 chrome::OnAppExiting(); 118 chrome::OnAppExiting();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 base::debug::TraceLog::GetInstance()->SetEnabled( 169 base::debug::TraceLog::GetInstance()->SetEnabled(
166 category_filter, 170 category_filter,
167 base::debug::TraceLog::RECORD_UNTIL_FULL); 171 base::debug::TraceLog::RECORD_UNTIL_FULL);
168 } 172 }
169 TRACE_EVENT0("shutdown", "StartShutdownTracing"); 173 TRACE_EVENT0("shutdown", "StartShutdownTracing");
170 } 174 }
171 175
172 // The Android implementation is in application_lifetime_android.cc 176 // The Android implementation is in application_lifetime_android.cc
173 #if !defined(OS_ANDROID) 177 #if !defined(OS_ANDROID)
174 void AttemptRestart() { 178 void AttemptRestart() {
179 // Tell everyone that we are shutting down.
180 browser_shutdown::SetTryingToQuit(true);
181
175 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? 182 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead?
176 for (chrome::BrowserIterator it; !it.done(); it.Next()) 183 for (chrome::BrowserIterator it; !it.done(); it.Next())
177 content::BrowserContext::SaveSessionState(it->profile()); 184 content::BrowserContext::SaveSessionState(it->profile());
178 185
179 PrefService* pref_service = g_browser_process->local_state(); 186 PrefService* pref_service = g_browser_process->local_state();
180 pref_service->SetBoolean(prefs::kWasRestarted, true); 187 pref_service->SetBoolean(prefs::kWasRestarted, true);
181 188
182 #if defined(OS_CHROMEOS) 189 #if defined(OS_CHROMEOS)
183 // For CrOS instead of browser restart (which is not supported) perform a full 190 // 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. 191 // sign out. Session will be only restored if user has that setting set.
(...skipping 11 matching lines...) Expand all
196 void AttemptRestartWithModeSwitch() { 203 void AttemptRestartWithModeSwitch() {
197 // The kRestartSwitchMode preference does not exists for Windows 7 and older 204 // The kRestartSwitchMode preference does not exists for Windows 7 and older
198 // operating systems so there is no need for OS version check. 205 // operating systems so there is no need for OS version check.
199 PrefService* prefs = g_browser_process->local_state(); 206 PrefService* prefs = g_browser_process->local_state();
200 prefs->SetBoolean(prefs::kRestartSwitchMode, true); 207 prefs->SetBoolean(prefs::kRestartSwitchMode, true);
201 AttemptRestart(); 208 AttemptRestart();
202 } 209 }
203 #endif 210 #endif
204 211
205 void AttemptExit() { 212 void AttemptExit() {
213 // Tell everyone that we are shutting down.
214 browser_shutdown::SetTryingToQuit(true);
215
206 // If we know that all browsers can be closed without blocking, 216 // If we know that all browsers can be closed without blocking,
207 // don't notify users of crashes beyond this point. 217 // don't notify users of crashes beyond this point.
208 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit 218 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit
209 // so crashes during shutdown are still reported in UMA. 219 // so crashes during shutdown are still reported in UMA.
210 #if !defined(OS_ANDROID) 220 #if !defined(OS_ANDROID)
211 // Android doesn't use Browser. 221 // Android doesn't use Browser.
212 if (AreAllBrowsersCloseable()) 222 if (AreAllBrowsersCloseable())
213 MarkAsCleanShutdown(); 223 MarkAsCleanShutdown();
214 #endif 224 #endif
215 AttemptExitInternal(); 225 AttemptExitInternal();
216 } 226 }
217 227
218 #if defined(OS_CHROMEOS) 228 #if defined(OS_CHROMEOS)
219 // A function called when SIGTERM is received. 229 // A function called when SIGTERM is received.
220 void ExitCleanly() { 230 void ExitCleanly() {
221 // We always mark exit cleanly because SessionManager may kill 231 // We always mark exit cleanly because SessionManager may kill
222 // chrome in 3 seconds after SIGTERM. 232 // chrome in 3 seconds after SIGTERM.
223 g_browser_process->EndSession(); 233 g_browser_process->EndSession();
224 234
235 // Tell everyone that we are shutting down.
236 browser_shutdown::SetTryingToQuit(true);
237
225 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() 238 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable()
226 // can be false in following cases. a) power-off b) signout from 239 // can be false in following cases. a) power-off b) signout from
227 // screen locker. 240 // screen locker.
228 if (!AreAllBrowsersCloseable()) 241 if (!AreAllBrowsersCloseable())
229 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); 242 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION);
230 AttemptExitInternal(); 243 AttemptExitInternal();
231 } 244 }
232 #endif 245 #endif
233 246
234 void SessionEnding() { 247 void SessionEnding() {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // environment is still active. 392 // environment is still active.
380 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) 393 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE)
381 return !ash::Shell::HasInstance(); 394 return !ash::Shell::HasInstance();
382 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) 395 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH)
383 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); 396 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty();
384 #endif 397 #endif
385 return true; 398 return true;
386 } 399 }
387 400
388 } // namespace chrome 401 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698