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/debug/trace_event.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/field_trial.h" | |
| 15 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 16 #include "base/process/kill.h" | 15 #include "base/process/kill.h" |
| 17 #include "base/process/process_handle.h" | 16 #include "base/process/process_handle.h" |
| 18 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 19 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/browser_process_platform_part.h" | 19 #include "chrome/browser/browser_process_platform_part.h" |
| 21 #include "chrome/browser/browser_shutdown.h" | 20 #include "chrome/browser/browser_shutdown.h" |
| 22 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 23 #include "chrome/browser/download/download_service.h" | 22 #include "chrome/browser/download/download_service.h" |
| 24 #include "chrome/browser/lifetime/browser_close_manager.h" | 23 #include "chrome/browser/lifetime/browser_close_manager.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 // can be false in following cases. a) power-off b) signout from | 243 // can be false in following cases. a) power-off b) signout from |
| 245 // screen locker. | 244 // screen locker. |
| 246 if (!AreAllBrowsersCloseable()) | 245 if (!AreAllBrowsersCloseable()) |
| 247 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); | 246 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); |
| 248 else | 247 else |
| 249 browser_shutdown::OnShutdownStarting(browser_shutdown::BROWSER_EXIT); | 248 browser_shutdown::OnShutdownStarting(browser_shutdown::BROWSER_EXIT); |
| 250 AttemptExitInternal(true); | 249 AttemptExitInternal(true); |
| 251 } | 250 } |
| 252 #endif | 251 #endif |
| 253 | 252 |
| 254 namespace { | |
| 255 | |
| 256 bool ExperimentUseBrokenSynchronization() { | |
| 257 const std::string group_name = | |
| 258 base::FieldTrialList::FindFullName("WindowsLogoffRace"); | |
| 259 return group_name == "BrokenSynchronization"; | |
| 260 } | |
| 261 | |
| 262 } // namespace | |
| 263 | |
| 264 void SessionEnding() { | 253 void SessionEnding() { |
| 265 // This is a time-limited shutdown where we need to write as much to | 254 // This is a time-limited shutdown where we need to write as much to |
| 266 // disk as we can as soon as we can, and where we must kill the | 255 // disk as we can as soon as we can, and where we must kill the |
| 267 // process within a hang timeout to avoid user prompts. | 256 // process within a hang timeout to avoid user prompts. |
| 268 | 257 |
| 269 // Start watching for hang during shutdown, and crash it if takes too long. | 258 // Start watching for hang during shutdown, and crash it if takes too long. |
| 270 // We disarm when |shutdown_watcher| object is destroyed, which is when we | 259 // We disarm when |shutdown_watcher| object is destroyed, which is when we |
| 271 // exit this function. | 260 // exit this function. |
| 272 ShutdownWatcherHelper shutdown_watcher; | 261 ShutdownWatcherHelper shutdown_watcher; |
| 273 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); | 262 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 287 content::NotificationService::AllSources(), | 276 content::NotificationService::AllSources(), |
| 288 content::NotificationService::NoDetails()); | 277 content::NotificationService::NoDetails()); |
| 289 | 278 |
| 290 // Write important data first. | 279 // Write important data first. |
| 291 g_browser_process->EndSession(); | 280 g_browser_process->EndSession(); |
| 292 | 281 |
| 293 #if defined(OS_WIN) | 282 #if defined(OS_WIN) |
| 294 base::win::SetShouldCrashOnProcessDetach(false); | 283 base::win::SetShouldCrashOnProcessDetach(false); |
| 295 #endif | 284 #endif |
| 296 | 285 |
| 297 if (ExperimentUseBrokenSynchronization()) { | 286 // On Windows 7 and later, the system will consider the process ripe for |
| 298 CloseAllBrowsers(); | 287 // termination as soon as it hides or destroys its windows. Since any |
| 299 | 288 // execution past that point will be non-deterministically cut short, we |
| 300 // Send out notification. This is used during testing so that the test | 289 // might as well put ourselves out of that misery deterministically. |
| 301 // harness can properly shutdown before we exit. | 290 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); |
|
gab
2015/12/03 19:12:29
I just realized that this made this the behavior o
| |
| 302 content::NotificationService::current()->Notify( | |
| 303 chrome::NOTIFICATION_SESSION_END, | |
| 304 content::NotificationService::AllSources(), | |
| 305 content::NotificationService::NoDetails()); | |
| 306 | |
| 307 // This will end by terminating the process. | |
| 308 content::ImmediateShutdownAndExitProcess(); | |
| 309 } else { | |
| 310 // On Windows 7 and later, the system will consider the process ripe for | |
| 311 // termination as soon as it hides or destroys its windows. Since any | |
| 312 // execution past that point will be non-deterministically cut short, we | |
| 313 // might as well put ourselves out of that misery deterministically. | |
| 314 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); | |
| 315 } | |
| 316 } | 291 } |
| 317 | 292 |
| 318 void IncrementKeepAliveCount() { | 293 void IncrementKeepAliveCount() { |
| 319 // Increment the browser process refcount as long as we're keeping the | 294 // Increment the browser process refcount as long as we're keeping the |
| 320 // application alive. | 295 // application alive. |
| 321 if (!WillKeepAlive()) | 296 if (!WillKeepAlive()) |
| 322 g_browser_process->AddRefModule(); | 297 g_browser_process->AddRefModule(); |
| 323 ++g_keep_alive_count; | 298 ++g_keep_alive_count; |
| 324 } | 299 } |
| 325 | 300 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 // environment is still active. | 395 // environment is still active. |
| 421 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) | 396 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) |
| 422 return !ash::Shell::HasInstance(); | 397 return !ash::Shell::HasInstance(); |
| 423 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) | 398 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) |
| 424 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); | 399 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); |
| 425 #endif | 400 #endif |
| 426 return true; | 401 return true; |
| 427 } | 402 } |
| 428 | 403 |
| 429 } // namespace chrome | 404 } // namespace chrome |
| OLD | NEW |