| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/metrics/thread_watcher.h" | 24 #include "chrome/browser/metrics/thread_watcher.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
| 29 #include "chrome/browser/ui/browser_iterator.h" | 29 #include "chrome/browser/ui/browser_iterator.h" |
| 30 #include "chrome/browser/ui/browser_tabstrip.h" | 30 #include "chrome/browser/ui/browser_tabstrip.h" |
| 31 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
| 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 33 #include "chrome/browser/ui/user_manager.h" | 33 #include "chrome/browser/ui/user_manager.h" |
| 34 #include "chrome/common/chrome_constants.h" |
| 34 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 36 #include "content/public/browser/browser_shutdown.h" | 37 #include "content/public/browser/browser_shutdown.h" |
| 37 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/navigation_details.h" | 39 #include "content/public/browser/navigation_details.h" |
| 39 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
| 40 | 41 |
| 41 #if defined(OS_CHROMEOS) | 42 #if defined(OS_CHROMEOS) |
| 42 #include "base/sys_info.h" | 43 #include "base/sys_info.h" |
| 43 #include "chrome/browser/chromeos/boot_times_loader.h" | 44 #include "chrome/browser/chromeos/boot_times_loader.h" |
| 44 #include "chromeos/dbus/dbus_thread_manager.h" | 45 #include "chromeos/dbus/dbus_thread_manager.h" |
| 45 #include "chromeos/dbus/session_manager_client.h" | 46 #include "chromeos/dbus/session_manager_client.h" |
| 46 #include "chromeos/dbus/update_engine_client.h" | 47 #include "chromeos/dbus/update_engine_client.h" |
| 47 #endif | 48 #endif |
| 48 | 49 |
| 49 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 50 #include "base/win/win_util.h" | 51 #include "base/win/win_util.h" |
| 52 #include "components/browser_watcher/exit_funnel_win.h" |
| 51 #endif | 53 #endif |
| 52 | 54 |
| 53 namespace chrome { | 55 namespace chrome { |
| 54 namespace { | 56 namespace { |
| 55 | 57 |
| 56 #if !defined(OS_ANDROID) | 58 #if !defined(OS_ANDROID) |
| 57 // Returns true if all browsers can be closed without user interaction. | 59 // Returns true if all browsers can be closed without user interaction. |
| 58 // This currently checks if there is pending download, or if it needs to | 60 // This currently checks if there is pending download, or if it needs to |
| 59 // handle unload handler. | 61 // handle unload handler. |
| 60 bool AreAllBrowsersCloseable() { | 62 bool AreAllBrowsersCloseable() { |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // screen locker. | 246 // screen locker. |
| 245 if (!AreAllBrowsersCloseable()) | 247 if (!AreAllBrowsersCloseable()) |
| 246 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); | 248 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); |
| 247 else | 249 else |
| 248 browser_shutdown::OnShutdownStarting(browser_shutdown::BROWSER_EXIT); | 250 browser_shutdown::OnShutdownStarting(browser_shutdown::BROWSER_EXIT); |
| 249 AttemptExitInternal(true); | 251 AttemptExitInternal(true); |
| 250 } | 252 } |
| 251 #endif | 253 #endif |
| 252 | 254 |
| 253 void SessionEnding() { | 255 void SessionEnding() { |
| 256 #if defined(OS_WIN) |
| 257 browser_watcher::ExitFunnel funnel; |
| 258 |
| 259 funnel.Init(kBrowserExitCodesRegistryPath, base::GetCurrentProcessHandle()); |
| 260 funnel.RecordEvent(L"SessionEnding"); |
| 261 #endif |
| 254 // This is a time-limited shutdown where we need to write as much to | 262 // This is a time-limited shutdown where we need to write as much to |
| 255 // disk as we can as soon as we can, and where we must kill the | 263 // disk as we can as soon as we can, and where we must kill the |
| 256 // process within a hang timeout to avoid user prompts. | 264 // process within a hang timeout to avoid user prompts. |
| 257 | 265 |
| 258 // Start watching for hang during shutdown, and crash it if takes too long. | 266 // Start watching for hang during shutdown, and crash it if takes too long. |
| 259 // We disarm when |shutdown_watcher| object is destroyed, which is when we | 267 // We disarm when |shutdown_watcher| object is destroyed, which is when we |
| 260 // exit this function. | 268 // exit this function. |
| 261 ShutdownWatcherHelper shutdown_watcher; | 269 ShutdownWatcherHelper shutdown_watcher; |
| 262 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); | 270 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); |
| 263 | 271 |
| 264 // EndSession is invoked once per frame. Only do something the first time. | 272 // EndSession is invoked once per frame. Only do something the first time. |
| 265 static bool already_ended = false; | 273 static bool already_ended = false; |
| 266 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 | 274 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 |
| 267 // In this case, do nothing. | 275 // In this case, do nothing. |
| 268 if (already_ended || !content::NotificationService::current()) | 276 if (already_ended || !content::NotificationService::current()) |
| 269 return; | 277 return; |
| 270 already_ended = true; | 278 already_ended = true; |
| 271 | 279 |
| 272 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); | 280 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); |
| 273 | 281 |
| 274 content::NotificationService::current()->Notify( | 282 content::NotificationService::current()->Notify( |
| 275 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | 283 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
| 276 content::NotificationService::AllSources(), | 284 content::NotificationService::AllSources(), |
| 277 content::NotificationService::NoDetails()); | 285 content::NotificationService::NoDetails()); |
| 278 | 286 |
| 287 #if defined(OS_WIN) |
| 288 funnel.RecordEvent(L"EndSession"); |
| 289 #endif |
| 279 // Write important data first. | 290 // Write important data first. |
| 280 g_browser_process->EndSession(); | 291 g_browser_process->EndSession(); |
| 281 | 292 |
| 282 #if defined(OS_WIN) | 293 #if defined(OS_WIN) |
| 283 base::win::SetShouldCrashOnProcessDetach(false); | 294 base::win::SetShouldCrashOnProcessDetach(false); |
| 284 #endif | 295 #endif |
| 285 | 296 |
| 297 #if defined(OS_WIN) |
| 298 // KillProcess ought to terminate the process without further ado, so if |
| 299 // execution gets to this point, presumably this is normal exit. |
| 300 funnel.RecordEvent(L"KillProcess"); |
| 301 #endif |
| 302 |
| 286 // On Windows 7 and later, the system will consider the process ripe for | 303 // On Windows 7 and later, the system will consider the process ripe for |
| 287 // termination as soon as it hides or destroys its windows. Since any | 304 // termination as soon as it hides or destroys its windows. Since any |
| 288 // execution past that point will be non-deterministically cut short, we | 305 // execution past that point will be non-deterministically cut short, we |
| 289 // might as well put ourselves out of that misery deterministically. | 306 // might as well put ourselves out of that misery deterministically. |
| 290 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); | 307 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); |
| 291 } | 308 } |
| 292 | 309 |
| 293 void IncrementKeepAliveCount() { | 310 void IncrementKeepAliveCount() { |
| 294 // Increment the browser process refcount as long as we're keeping the | 311 // Increment the browser process refcount as long as we're keeping the |
| 295 // application alive. | 312 // application alive. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 // environment is still active. | 412 // environment is still active. |
| 396 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) | 413 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) |
| 397 return !ash::Shell::HasInstance(); | 414 return !ash::Shell::HasInstance(); |
| 398 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) | 415 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) |
| 399 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); | 416 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); |
| 400 #endif | 417 #endif |
| 401 return true; | 418 return true; |
| 402 } | 419 } |
| 403 | 420 |
| 404 } // namespace chrome | 421 } // namespace chrome |
| OLD | NEW |