0

Move use of ShutdownWatcherHelper after early return

The ShutdownWatcherHelper is only needed if we don't early return,
additionally the early return triggers a DCHECK because
ShutdownWatcherHelper gets destroyed on the UI thread, triggering a
threading assertion because it ends up calling Join().

Also add ScopedAllowIO, in case Terminate fails. If SessionEnding returns we're going to be destroyed by the OS anyway, so we don't really care about any additional IO.

BUG=none
TEST=none
R=jam@chromium.org

Review URL: https://codereview.chromium.org/1839453002

Cr-Commit-Position: refs/heads/master@{#383365}
This commit is contained in:
sky
2016-03-25 14:27:31 -07:00
committed by Commit bot
parent 7e3a038556
commit 0e07a14f1d
2 changed files with 12 additions and 6 deletions

@ -168,6 +168,7 @@ _BANNED_CPP_FUNCTIONS = (
r"^base[\\\/]process[\\\/]process_metrics_linux\.cc$",
r"^blimp[\\\/]engine[\\\/]app[\\\/]blimp_browser_main_parts\.cc$",
r"^chrome[\\\/]browser[\\\/]chromeos[\\\/]boot_times_recorder\.cc$",
r"^chrome[\\\/]browser[\\\/]lifetime[\\\/]application_lifetime\.cc$",
r"^chrome[\\\/]browser[\\\/]chromeos[\\\/]"
"customization_document_browsertest\.cc$",
r"^components[\\\/]crash[\\\/]app[\\\/]breakpad_mac\.mm$",

@ -247,12 +247,6 @@ void SessionEnding() {
// disk as we can as soon as we can, and where we must kill the
// process within a hang timeout to avoid user prompts.
// Start watching for hang during shutdown, and crash it if takes too long.
// We disarm when |shutdown_watcher| object is destroyed, which is when we
// exit this function.
ShutdownWatcherHelper shutdown_watcher;
shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90));
// EndSession is invoked once per frame. Only do something the first time.
static bool already_ended = false;
// We may get called in the middle of shutdown, e.g. http://crbug.com/70852
@ -261,6 +255,17 @@ void SessionEnding() {
return;
already_ended = true;
// ~ShutdownWatcherHelper uses IO (it joins a thread). We'll only trigger that
// if Terminate() fails, which leaves us in a weird state, or the OS is going
// to kill us soon. Either way we don't care about that here.
base::ThreadRestrictions::ScopedAllowIO allow_io;
// Start watching for hang during shutdown, and crash it if takes too long.
// We disarm when |shutdown_watcher| object is destroyed, which is when we
// exit this function.
ShutdownWatcherHelper shutdown_watcher;
shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90));
browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION);
content::NotificationService::current()->Notify(