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