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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #if defined(OS_WIN) | |
| 10 #include <windows.h> | |
| 11 #endif | |
| 12 | |
| 9 #include "base/bind.h" | 13 #include "base/bind.h" |
| 10 #include "base/logging.h" | 14 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 12 #include "base/process/process.h" | 16 #include "base/process/process.h" |
| 13 #include "base/process/process_handle.h" | 17 #include "base/process/process_handle.h" |
| 14 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 15 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/browser_process_platform_part.h" | 20 #include "chrome/browser/browser_process_platform_part.h" |
| 17 #include "chrome/browser/browser_shutdown.h" | 21 #include "chrome/browser/browser_shutdown.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 40 #include "base/sys_info.h" | 44 #include "base/sys_info.h" |
| 41 #include "chrome/browser/chromeos/boot_times_recorder.h" | 45 #include "chrome/browser/chromeos/boot_times_recorder.h" |
| 42 #include "chromeos/dbus/dbus_thread_manager.h" | 46 #include "chromeos/dbus/dbus_thread_manager.h" |
| 43 #include "chromeos/dbus/power_policy_controller.h" | 47 #include "chromeos/dbus/power_policy_controller.h" |
| 44 #include "chromeos/dbus/session_manager_client.h" | 48 #include "chromeos/dbus/session_manager_client.h" |
| 45 #include "chromeos/dbus/update_engine_client.h" | 49 #include "chromeos/dbus/update_engine_client.h" |
| 46 #endif | 50 #endif |
| 47 | 51 |
| 48 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
| 49 #include "base/win/win_util.h" | 53 #include "base/win/win_util.h" |
| 54 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | |
| 55 #include "chrome/common/chrome_constants.h" | |
| 50 #endif | 56 #endif |
| 51 | 57 |
| 52 namespace chrome { | 58 namespace chrome { |
| 53 namespace { | 59 namespace { |
| 54 | 60 |
| 55 #if !defined(OS_ANDROID) | 61 #if !defined(OS_ANDROID) |
| 56 // Returns true if all browsers can be closed without user interaction. | 62 // Returns true if all browsers can be closed without user interaction. |
| 57 // This currently checks if there is pending download, or if it needs to | 63 // This currently checks if there is pending download, or if it needs to |
| 58 // handle unload handler. | 64 // handle unload handler. |
| 59 bool AreAllBrowsersCloseable() { | 65 bool AreAllBrowsersCloseable() { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 #endif | 187 #endif |
| 182 PrefService* pref_service = g_browser_process->local_state(); | 188 PrefService* pref_service = g_browser_process->local_state(); |
| 183 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); | 189 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); |
| 184 AttemptExitInternal(false); | 190 AttemptExitInternal(false); |
| 185 #endif // defined(OS_CHROMEOS) | 191 #endif // defined(OS_CHROMEOS) |
| 186 } | 192 } |
| 187 | 193 |
| 188 // The Android implementation is in application_lifetime_android.cc | 194 // The Android implementation is in application_lifetime_android.cc |
| 189 #if !defined(OS_ANDROID) | 195 #if !defined(OS_ANDROID) |
| 190 void AttemptRestart() { | 196 void AttemptRestart() { |
| 197 #if defined(OS_WIN) | |
| 198 // On Windows Breakpad will upload crash reports if the breakpad pipe name | |
|
Lei Zhang
2016/06/06 22:56:15
there's a missing comma after "Windows"
dpapad
2016/06/06 23:14:37
Done.
| |
| 199 // environment variable is defined. So we undefine this environment variable | |
| 200 // before restarting, as the restarted processes will inherit their | |
| 201 // environment variables from ours, thus suppressing crash uploads. | |
| 202 if (!ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()) { | |
| 203 HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName); | |
| 204 if (exe_module) { | |
| 205 typedef void (__cdecl *ClearBreakpadPipeEnvVar)(); | |
|
Sigurður Ásgeirsson
2016/06/06 13:40:01
these in-place function type declarations irk me.
dpapad
2016/06/06 17:09:45
I prefer to leave this cleanup to someone with a W
| |
| 206 ClearBreakpadPipeEnvVar clear = reinterpret_cast<ClearBreakpadPipeEnvVar>( | |
| 207 GetProcAddress(exe_module, "ClearBreakpadPipeEnvironmentVariable")); | |
| 208 if (clear) | |
| 209 clear(); | |
| 210 } | |
| 211 } | |
| 212 #endif // defined(OS_WIN) | |
| 213 | |
| 191 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? | 214 // TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead? |
| 192 for (auto* browser : *BrowserList::GetInstance()) | 215 for (auto* browser : *BrowserList::GetInstance()) |
| 193 content::BrowserContext::SaveSessionState(browser->profile()); | 216 content::BrowserContext::SaveSessionState(browser->profile()); |
| 194 | 217 |
| 195 PrefService* pref_service = g_browser_process->local_state(); | 218 PrefService* pref_service = g_browser_process->local_state(); |
| 196 pref_service->SetBoolean(prefs::kWasRestarted, true); | 219 pref_service->SetBoolean(prefs::kWasRestarted, true); |
| 197 | 220 |
| 198 #if defined(OS_CHROMEOS) | 221 #if defined(OS_CHROMEOS) |
| 199 chromeos::BootTimesRecorder::Get()->set_restart_requested(); | 222 chromeos::BootTimesRecorder::Get()->set_restart_requested(); |
| 200 | 223 |
| 201 DCHECK(!g_send_stop_request_to_session_manager); | 224 DCHECK(!g_send_stop_request_to_session_manager); |
| 202 // Make sure we don't send stop request to the session manager. | 225 // Make sure we don't send stop request to the session manager. |
| 203 g_send_stop_request_to_session_manager = false; | 226 g_send_stop_request_to_session_manager = false; |
| 204 // Run exit process in clean stack. | 227 // Run exit process in clean stack. |
| 205 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 228 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 206 base::Bind(&ExitCleanly)); | 229 base::Bind(&ExitCleanly)); |
| 207 #else | 230 #else |
| 208 // Set the flag to restore state after the restart. | 231 // Set the flag to restore state after the restart. |
| 209 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); | 232 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); |
| 210 AttemptExit(); | 233 AttemptExit(); |
| 211 #endif | 234 #endif |
| 212 } | 235 } |
| 213 #endif | 236 #endif // !defined(OS_ANDROID) |
| 214 | 237 |
| 215 void AttemptExit() { | 238 void AttemptExit() { |
| 216 #if defined(OS_CHROMEOS) | 239 #if defined(OS_CHROMEOS) |
| 217 // On ChromeOS, user exit and system exits are the same. | 240 // On ChromeOS, user exit and system exits are the same. |
| 218 AttemptUserExit(); | 241 AttemptUserExit(); |
| 219 #else | 242 #else |
| 220 // If we know that all browsers can be closed without blocking, | 243 // If we know that all browsers can be closed without blocking, |
| 221 // don't notify users of crashes beyond this point. | 244 // don't notify users of crashes beyond this point. |
| 222 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit | 245 // Note that MarkAsCleanShutdown() does not set UMA's exit cleanly bit |
| 223 // so crashes during shutdown are still reported in UMA. | 246 // so crashes during shutdown are still reported in UMA. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 void OnAppExiting() { | 380 void OnAppExiting() { |
| 358 static bool notified = false; | 381 static bool notified = false; |
| 359 if (notified) | 382 if (notified) |
| 360 return; | 383 return; |
| 361 notified = true; | 384 notified = true; |
| 362 HandleAppExitingForPlatform(); | 385 HandleAppExitingForPlatform(); |
| 363 } | 386 } |
| 364 #endif // !defined(OS_ANDROID) | 387 #endif // !defined(OS_ANDROID) |
| 365 | 388 |
| 366 } // namespace chrome | 389 } // namespace chrome |
| OLD | NEW |