Chromium Code Reviews| 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/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/browser_process_platform_part.h" | 17 #include "chrome/browser/browser_process_platform_part.h" |
| 17 #include "chrome/browser/browser_shutdown.h" | 18 #include "chrome/browser/browser_shutdown.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/download/download_service.h" | 20 #include "chrome/browser/download/download_service.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker( | 119 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker( |
| 119 "StartedClosingWindows", false); | 120 "StartedClosingWindows", false); |
| 120 #endif | 121 #endif |
| 121 scoped_refptr<BrowserCloseManager> browser_close_manager = | 122 scoped_refptr<BrowserCloseManager> browser_close_manager = |
| 122 new BrowserCloseManager; | 123 new BrowserCloseManager; |
| 123 browser_close_manager->StartClosingBrowsers(); | 124 browser_close_manager->StartClosingBrowsers(); |
| 124 } | 125 } |
| 125 | 126 |
| 126 void AttemptUserExit() { | 127 void AttemptUserExit() { |
| 127 #if defined(OS_CHROMEOS) | 128 #if defined(OS_CHROMEOS) |
| 129 StartShutdownTracing(); | |
| 128 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutStarted", false); | 130 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutStarted", false); |
| 129 // Write /tmp/uptime-logout-started as well. | 131 // Write /tmp/uptime-logout-started as well. |
| 130 const char kLogoutStarted[] = "logout-started"; | 132 const char kLogoutStarted[] = "logout-started"; |
| 131 chromeos::BootTimesLoader::Get()->RecordCurrentStats(kLogoutStarted); | 133 chromeos::BootTimesLoader::Get()->RecordCurrentStats(kLogoutStarted); |
| 132 | 134 |
| 133 // Login screen should show up in owner's locale. | 135 // Login screen should show up in owner's locale. |
| 134 PrefService* state = g_browser_process->local_state(); | 136 PrefService* state = g_browser_process->local_state(); |
| 135 if (state) { | 137 if (state) { |
| 136 std::string owner_locale = state->GetString(prefs::kOwnerLocale); | 138 std::string owner_locale = state->GetString(prefs::kOwnerLocale); |
| 137 if (!owner_locale.empty() && | 139 if (!owner_locale.empty() && |
| 138 state->GetString(prefs::kApplicationLocale) != owner_locale && | 140 state->GetString(prefs::kApplicationLocale) != owner_locale && |
| 139 !state->IsManagedPreference(prefs::kApplicationLocale)) { | 141 !state->IsManagedPreference(prefs::kApplicationLocale)) { |
| 140 state->SetString(prefs::kApplicationLocale, owner_locale); | 142 state->SetString(prefs::kApplicationLocale, owner_locale); |
| 143 TRACE_EVENT0("shutdown", "CommitPendingWrite"); | |
| 141 state->CommitPendingWrite(); | 144 state->CommitPendingWrite(); |
| 142 } | 145 } |
| 143 } | 146 } |
| 144 g_session_manager_requested_shutdown = false; | 147 g_session_manager_requested_shutdown = false; |
| 145 // On ChromeOS, always terminate the browser, regardless of the result of | 148 // On ChromeOS, always terminate the browser, regardless of the result of |
| 146 // AreAllBrowsersCloseable(). See crbug.com/123107. | 149 // AreAllBrowsersCloseable(). See crbug.com/123107. |
| 147 chrome::NotifyAndTerminate(true); | 150 chrome::NotifyAndTerminate(true); |
| 148 #else | 151 #else |
| 149 // Reset the restart bit that might have been set in cancelled restart | 152 // Reset the restart bit that might have been set in cancelled restart |
| 150 // request. | 153 // request. |
| 151 PrefService* pref_service = g_browser_process->local_state(); | 154 PrefService* pref_service = g_browser_process->local_state(); |
| 152 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); | 155 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); |
| 153 AttemptExitInternal(); | 156 AttemptExitInternal(); |
| 154 #endif | 157 #endif |
| 155 } | 158 } |
| 156 | 159 |
| 160 void StartShutdownTracing() { | |
|
James Cook
2013/09/03 21:23:36
optional nit: MaybeStartShutdownTracing()?
Mr4D (OOO till 08-26)
2013/09/03 22:18:58
For what Chrome is concerned the tracing gets star
| |
| 161 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 162 if (command_line.HasSwitch(switches::kTraceShutdown)) { | |
| 163 base::debug::CategoryFilter category_filter( | |
| 164 command_line.GetSwitchValueASCII(switches::kTraceShutdown)); | |
| 165 base::debug::TraceLog::GetInstance()->SetEnabled( | |
| 166 category_filter, | |
| 167 base::debug::TraceLog::RECORD_UNTIL_FULL); | |
| 168 } | |
| 169 TRACE_EVENT0("shutdown", "AttemptUserExit"); | |
|
James Cook
2013/09/03 21:23:36
Are you sure you want to do this here, since somet
Mr4D (OOO till 08-26)
2013/09/03 22:18:58
Indeed - Done.
| |
| 170 } | |
| 171 | |
| 157 // The Android implementation is in application_lifetime_android.cc | 172 // The Android implementation is in application_lifetime_android.cc |
| 158 #if !defined(OS_ANDROID) | 173 #if !defined(OS_ANDROID) |
| 159 void AttemptRestart() { | 174 void AttemptRestart() { |
| 160 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? | 175 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? |
| 161 for (chrome::BrowserIterator it; !it.done(); it.Next()) | 176 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
| 162 content::BrowserContext::SaveSessionState(it->profile()); | 177 content::BrowserContext::SaveSessionState(it->profile()); |
| 163 | 178 |
| 164 PrefService* pref_service = g_browser_process->local_state(); | 179 PrefService* pref_service = g_browser_process->local_state(); |
| 165 pref_service->SetBoolean(prefs::kWasRestarted, true); | 180 pref_service->SetBoolean(prefs::kWasRestarted, true); |
| 166 | 181 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 // environment is still active. | 379 // environment is still active. |
| 365 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) | 380 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) |
| 366 return !ash::Shell::HasInstance(); | 381 return !ash::Shell::HasInstance(); |
| 367 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) | 382 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) |
| 368 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); | 383 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); |
| 369 #endif | 384 #endif |
| 370 return true; | 385 return true; |
| 371 } | 386 } |
| 372 | 387 |
| 373 } // namespace chrome | 388 } // namespace chrome |
| OLD | NEW |