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/ui/browser_list.h" | 5 #include "chrome/browser/ui/browser_list.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/browser_shutdown.h" | 12 #include "chrome/browser/browser_shutdown.h" |
13 #include "chrome/browser/download/download_service.h" | 13 #include "chrome/browser/download/download_service.h" |
14 #include "chrome/browser/metrics/thread_watcher.h" | 14 #include "chrome/browser/metrics/thread_watcher.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_tabstrip.h" | 19 #include "chrome/browser/ui/browser_tabstrip.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "content/public/browser/browser_shutdown.h" | 25 #include "content/public/browser/browser_shutdown.h" |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/navigation_details.h" | 27 #include "content/public/browser/navigation_details.h" |
28 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
29 | 29 |
30 #if defined(OS_ANDROID) | |
31 #include "chrome/browser/lifetime/application_lifetime_android.h" | |
32 #endif | |
33 | |
30 #if defined(OS_MACOSX) | 34 #if defined(OS_MACOSX) |
31 #include "chrome/browser/chrome_browser_application_mac.h" | 35 #include "chrome/browser/chrome_browser_application_mac.h" |
32 #endif | 36 #endif |
33 | 37 |
34 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
35 #include "base/chromeos/chromeos_version.h" | 39 #include "base/chromeos/chromeos_version.h" |
36 #include "chrome/browser/chromeos/boot_times_loader.h" | 40 #include "chrome/browser/chromeos/boot_times_loader.h" |
37 #include "chrome/browser/chromeos/login/user_manager.h" | 41 #include "chrome/browser/chromeos/login/user_manager.h" |
38 #include "chromeos/dbus/dbus_thread_manager.h" | 42 #include "chromeos/dbus/dbus_thread_manager.h" |
39 #include "chromeos/dbus/session_manager_client.h" | 43 #include "chromeos/dbus/session_manager_client.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 (*i)->profile()->SetExitType(Profile::EXIT_NORMAL); | 83 (*i)->profile()->SetExitType(Profile::EXIT_NORMAL); |
80 } | 84 } |
81 } | 85 } |
82 | 86 |
83 void AttemptExitInternal() { | 87 void AttemptExitInternal() { |
84 content::NotificationService::current()->Notify( | 88 content::NotificationService::current()->Notify( |
85 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | 89 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
86 content::NotificationService::AllSources(), | 90 content::NotificationService::AllSources(), |
87 content::NotificationService::NoDetails()); | 91 content::NotificationService::NoDetails()); |
88 | 92 |
89 #if !defined(OS_MACOSX) | 93 #if defined(OS_ANDROID) |
90 // On most platforms, closing all windows causes the application to exit. | 94 // Tell the Java code to finish() the Activity. |
91 CloseAllBrowsers(); | 95 TerminateAndroid(); |
92 #else | 96 #elif defined(OS_MACOSX) |
93 // On the Mac, the application continues to run once all windows are closed. | 97 // On the Mac, the application continues to run once all windows are closed. |
94 // Terminate will result in a CloseAllBrowsers() call, and once (and if) | 98 // Terminate will result in a CloseAllBrowsers() call, and once (and if) |
95 // that is done, will cause the application to exit cleanly. | 99 // that is done, will cause the application to exit cleanly. |
96 chrome_browser_application_mac::Terminate(); | 100 chrome_browser_application_mac::Terminate(); |
101 #else | |
102 // On most platforms, closing all windows causes the application to exit. | |
103 CloseAllBrowsers(); | |
97 #endif | 104 #endif |
98 } | 105 } |
99 | 106 |
100 void NotifyAppTerminating() { | 107 void NotifyAppTerminating() { |
101 static bool notified = false; | 108 static bool notified = false; |
102 if (notified) | 109 if (notified) |
103 return; | 110 return; |
104 notified = true; | 111 notified = true; |
105 content::NotificationService::current()->Notify( | 112 content::NotificationService::current()->Notify( |
106 chrome::NOTIFICATION_APP_TERMINATING, | 113 chrome::NOTIFICATION_APP_TERMINATING, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 NotifyAndTerminate(true); | 236 NotifyAndTerminate(true); |
230 #else | 237 #else |
231 // Reset the restart bit that might have been set in cancelled restart | 238 // Reset the restart bit that might have been set in cancelled restart |
232 // request. | 239 // request. |
233 PrefService* pref_service = g_browser_process->local_state(); | 240 PrefService* pref_service = g_browser_process->local_state(); |
234 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); | 241 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); |
235 AttemptExitInternal(); | 242 AttemptExitInternal(); |
236 #endif | 243 #endif |
237 } | 244 } |
238 | 245 |
246 // The Android implementation is in application_lifetime_android.cc | |
247 #if !defined(OS_ANDROID) | |
239 void AttemptRestart() { | 248 void AttemptRestart() { |
240 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? | 249 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? |
241 BrowserList::const_iterator it; | 250 BrowserList::const_iterator it; |
242 for (it = BrowserList::begin(); it != BrowserList::end(); ++it) | 251 for (it = BrowserList::begin(); it != BrowserList::end(); ++it) |
243 content::BrowserContext::SaveSessionState((*it)->profile()); | 252 content::BrowserContext::SaveSessionState((*it)->profile()); |
244 | 253 |
245 PrefService* pref_service = g_browser_process->local_state(); | 254 PrefService* pref_service = g_browser_process->local_state(); |
246 pref_service->SetBoolean(prefs::kWasRestarted, true); | 255 pref_service->SetBoolean(prefs::kWasRestarted, true); |
247 | 256 |
248 #if defined(OS_CHROMEOS) | 257 #if defined(OS_CHROMEOS) |
249 // For CrOS instead of browser restart (which is not supported) perform a full | 258 // For CrOS instead of browser restart (which is not supported) perform a full |
250 // sign out. Session will be only restored if user has that setting set. | 259 // sign out. Session will be only restored if user has that setting set. |
251 // Same session restore behavior happens in case of full restart after update. | 260 // Same session restore behavior happens in case of full restart after update. |
252 AttemptUserExit(); | 261 AttemptUserExit(); |
253 #else | 262 #else |
254 // Set the flag to restore state after the restart. | 263 // Set the flag to restore state after the restart. |
255 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); | 264 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); |
256 AttemptExit(); | 265 AttemptExit(); |
257 #endif | 266 #endif |
258 } | 267 } |
268 #endif | |
259 | 269 |
260 #if defined(OS_WIN) | 270 #if defined(OS_WIN) |
261 void AttemptRestartWithModeSwitch() { | 271 void AttemptRestartWithModeSwitch() { |
262 // The kRestartSwitchMode preference does not exists for Windows 7 and older | 272 // The kRestartSwitchMode preference does not exists for Windows 7 and older |
263 // operating systems so there is no need for OS version check. | 273 // operating systems so there is no need for OS version check. |
264 PrefService* prefs = g_browser_process->local_state(); | 274 PrefService* prefs = g_browser_process->local_state(); |
265 prefs->SetBoolean(prefs::kRestartSwitchMode, true); | 275 prefs->SetBoolean(prefs::kRestartSwitchMode, true); |
266 browser::AttemptRestart(); | 276 browser::AttemptRestart(); |
267 } | 277 } |
268 #endif | 278 #endif |
269 | 279 |
270 void AttemptExit() { | 280 void AttemptExit() { |
271 // If we know that all browsers can be closed without blocking, | 281 // If we know that all browsers can be closed without blocking, |
272 // don't notify users of crashes beyond this point. | 282 // don't notify users of crashes beyond this point. |
273 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit | 283 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit |
274 // so crashes during shutdown are still reported in UMA. | 284 // so crashes during shutdown are still reported in UMA. |
285 #if !defined(OS_ANDROID) | |
286 // Android doesn't use Browser. | |
Nico
2013/01/15 20:33:27
So you don't need the call to MarkAsCleanShutdown(
gone
2013/01/15 22:18:54
Yeah, AreAllBrowsersCloseable() goes through a lis
| |
275 if (AreAllBrowsersCloseable()) | 287 if (AreAllBrowsersCloseable()) |
276 MarkAsCleanShutdown(); | 288 MarkAsCleanShutdown(); |
289 #endif | |
277 AttemptExitInternal(); | 290 AttemptExitInternal(); |
278 } | 291 } |
279 | 292 |
280 #if defined(OS_CHROMEOS) | 293 #if defined(OS_CHROMEOS) |
281 // A function called when SIGTERM is received. | 294 // A function called when SIGTERM is received. |
282 void ExitCleanly() { | 295 void ExitCleanly() { |
283 // We always mark exit cleanly because SessionManager may kill | 296 // We always mark exit cleanly because SessionManager may kill |
284 // chrome in 3 seconds after SIGTERM. | 297 // chrome in 3 seconds after SIGTERM. |
285 g_browser_process->EndSession(); | 298 g_browser_process->EndSession(); |
286 | 299 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 MessageLoop::current()) | 375 MessageLoop::current()) |
363 CloseAllBrowsers(); | 376 CloseAllBrowsers(); |
364 } | 377 } |
365 } | 378 } |
366 | 379 |
367 bool WillKeepAlive() { | 380 bool WillKeepAlive() { |
368 return g_keep_alive_count > 0; | 381 return g_keep_alive_count > 0; |
369 } | 382 } |
370 | 383 |
371 } // namespace browser | 384 } // namespace browser |
OLD | NEW |