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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | |
9 #include "base/logging.h" | 8 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
12 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
13 #include "base/process/process.h" | 12 #include "base/process/process.h" |
14 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
15 #include "base/trace_event/trace_event.h" | |
16 #include "build/build_config.h" | 14 #include "build/build_config.h" |
17 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/browser_process_platform_part.h" | 16 #include "chrome/browser/browser_process_platform_part.h" |
19 #include "chrome/browser/browser_shutdown.h" | 17 #include "chrome/browser/browser_shutdown.h" |
20 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
21 #include "chrome/browser/download/download_service.h" | 19 #include "chrome/browser/download/download_service.h" |
22 #include "chrome/browser/lifetime/browser_close_manager.h" | 20 #include "chrome/browser/lifetime/browser_close_manager.h" |
23 #include "chrome/browser/metrics/thread_watcher.h" | 21 #include "chrome/browser/metrics/thread_watcher.h" |
24 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
26 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
28 #include "chrome/browser/ui/browser_iterator.h" | 26 #include "chrome/browser/ui/browser_iterator.h" |
29 #include "chrome/browser/ui/browser_tabstrip.h" | 27 #include "chrome/browser/ui/browser_tabstrip.h" |
30 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
31 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
32 #include "chrome/browser/ui/user_manager.h" | 30 #include "chrome/browser/ui/user_manager.h" |
33 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
34 #include "chrome/common/chrome_switches.h" | |
35 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
36 #include "components/tracing/tracing_switches.h" | |
37 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/navigation_details.h" | 34 #include "content/public/browser/navigation_details.h" |
39 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
40 | 36 |
41 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
42 #include "base/sys_info.h" | 38 #include "base/sys_info.h" |
43 #include "chrome/browser/chromeos/boot_times_recorder.h" | 39 #include "chrome/browser/chromeos/boot_times_recorder.h" |
44 #include "chromeos/dbus/dbus_thread_manager.h" | 40 #include "chromeos/dbus/dbus_thread_manager.h" |
45 #include "chromeos/dbus/session_manager_client.h" | 41 #include "chromeos/dbus/session_manager_client.h" |
46 #include "chromeos/dbus/update_engine_client.h" | 42 #include "chromeos/dbus/update_engine_client.h" |
47 #endif | 43 #endif |
48 | 44 |
49 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
50 #include "base/win/win_util.h" | 46 #include "base/win/win_util.h" |
51 #include "components/browser_watcher/exit_funnel_win.h" | 47 #include "components/browser_watcher/exit_funnel_win.h" |
52 #endif | 48 #endif |
53 | 49 |
54 #if defined(USE_ASH) | |
55 #include "ash/shell.h" | |
56 #endif | |
57 | |
58 namespace chrome { | 50 namespace chrome { |
59 namespace { | 51 namespace { |
60 | 52 |
61 #if !defined(OS_ANDROID) | 53 #if !defined(OS_ANDROID) |
62 // Returns true if all browsers can be closed without user interaction. | 54 // Returns true if all browsers can be closed without user interaction. |
63 // This currently checks if there is pending download, or if it needs to | 55 // This currently checks if there is pending download, or if it needs to |
64 // handle unload handler. | 56 // handle unload handler. |
65 bool AreAllBrowsersCloseable() { | 57 bool AreAllBrowsersCloseable() { |
66 chrome::BrowserIterator browser_it; | 58 chrome::BrowserIterator browser_it; |
67 if (browser_it.done()) | 59 if (browser_it.done()) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker( | 134 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker( |
143 "StartedClosingWindows", false); | 135 "StartedClosingWindows", false); |
144 #endif | 136 #endif |
145 scoped_refptr<BrowserCloseManager> browser_close_manager = | 137 scoped_refptr<BrowserCloseManager> browser_close_manager = |
146 new BrowserCloseManager; | 138 new BrowserCloseManager; |
147 browser_close_manager->StartClosingBrowsers(); | 139 browser_close_manager->StartClosingBrowsers(); |
148 } | 140 } |
149 | 141 |
150 void AttemptUserExit() { | 142 void AttemptUserExit() { |
151 #if defined(OS_CHROMEOS) | 143 #if defined(OS_CHROMEOS) |
152 StartShutdownTracing(); | 144 browser_shutdown::StartShutdownTracing(); |
153 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker("LogoutStarted", | 145 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker("LogoutStarted", |
154 false); | 146 false); |
155 | 147 |
156 PrefService* state = g_browser_process->local_state(); | 148 PrefService* state = g_browser_process->local_state(); |
157 if (state) { | 149 if (state) { |
158 chromeos::BootTimesRecorder::Get()->OnLogoutStarted(state); | 150 chromeos::BootTimesRecorder::Get()->OnLogoutStarted(state); |
159 | 151 |
160 // Login screen should show up in owner's locale. | 152 // Login screen should show up in owner's locale. |
161 std::string owner_locale = state->GetString(prefs::kOwnerLocale); | 153 std::string owner_locale = state->GetString(prefs::kOwnerLocale); |
162 if (!owner_locale.empty() && | 154 if (!owner_locale.empty() && |
(...skipping 11 matching lines...) Expand all Loading... |
174 #else | 166 #else |
175 // Reset the restart bit that might have been set in cancelled restart | 167 // Reset the restart bit that might have been set in cancelled restart |
176 // request. | 168 // request. |
177 UserManager::Hide(); | 169 UserManager::Hide(); |
178 PrefService* pref_service = g_browser_process->local_state(); | 170 PrefService* pref_service = g_browser_process->local_state(); |
179 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); | 171 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); |
180 AttemptExitInternal(false); | 172 AttemptExitInternal(false); |
181 #endif | 173 #endif |
182 } | 174 } |
183 | 175 |
184 void StartShutdownTracing() { | |
185 const base::CommandLine& command_line = | |
186 *base::CommandLine::ForCurrentProcess(); | |
187 if (command_line.HasSwitch(switches::kTraceShutdown)) { | |
188 base::trace_event::TraceConfig trace_config( | |
189 command_line.GetSwitchValueASCII(switches::kTraceShutdown), ""); | |
190 base::trace_event::TraceLog::GetInstance()->SetEnabled( | |
191 trace_config, | |
192 base::trace_event::TraceLog::RECORDING_MODE); | |
193 } | |
194 TRACE_EVENT0("shutdown", "StartShutdownTracing"); | |
195 } | |
196 | |
197 // The Android implementation is in application_lifetime_android.cc | 176 // The Android implementation is in application_lifetime_android.cc |
198 #if !defined(OS_ANDROID) | 177 #if !defined(OS_ANDROID) |
199 void AttemptRestart() { | 178 void AttemptRestart() { |
200 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? | 179 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? |
201 for (chrome::BrowserIterator it; !it.done(); it.Next()) | 180 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
202 content::BrowserContext::SaveSessionState(it->profile()); | 181 content::BrowserContext::SaveSessionState(it->profile()); |
203 | 182 |
204 PrefService* pref_service = g_browser_process->local_state(); | 183 PrefService* pref_service = g_browser_process->local_state(); |
205 pref_service->SetBoolean(prefs::kWasRestarted, true); | 184 pref_service->SetBoolean(prefs::kWasRestarted, true); |
206 | 185 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 } | 377 } |
399 | 378 |
400 void OnAppExiting() { | 379 void OnAppExiting() { |
401 static bool notified = false; | 380 static bool notified = false; |
402 if (notified) | 381 if (notified) |
403 return; | 382 return; |
404 notified = true; | 383 notified = true; |
405 HandleAppExitingForPlatform(); | 384 HandleAppExitingForPlatform(); |
406 } | 385 } |
407 | 386 |
408 bool ShouldStartShutdown(Browser* browser) { | |
409 if (BrowserList::GetInstance(browser->host_desktop_type())->size() > 1) | |
410 return false; | |
411 #if defined(OS_WIN) | |
412 // On Windows 8 the desktop and ASH environments could be active | |
413 // at the same time. | |
414 // We should not start the shutdown process in the following cases:- | |
415 // 1. If the desktop type of the browser going away is ASH and there | |
416 // are browser windows open in the desktop. | |
417 // 2. If the desktop type of the browser going away is desktop and the ASH | |
418 // environment is still active. | |
419 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) | |
420 return !ash::Shell::HasInstance(); | |
421 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) | |
422 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); | |
423 #endif | |
424 return true; | |
425 } | |
426 | |
427 void DisableShutdownForTesting(bool disable_shutdown_for_testing) { | 387 void DisableShutdownForTesting(bool disable_shutdown_for_testing) { |
428 g_disable_shutdown_for_testing = disable_shutdown_for_testing; | 388 g_disable_shutdown_for_testing = disable_shutdown_for_testing; |
429 if (!g_disable_shutdown_for_testing && !WillKeepAlive()) | 389 if (!g_disable_shutdown_for_testing && !WillKeepAlive()) |
430 CloseAllBrowsersIfNeeded(); | 390 CloseAllBrowsersIfNeeded(); |
431 } | 391 } |
432 | 392 |
433 } // namespace chrome | 393 } // namespace chrome |
OLD | NEW |