Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1112)

Unified Diff: chrome/browser/browser_process_impl.cc

Issue 170023002: Don't use nested message loop during EndSession (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/browser_process_impl.cc
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 56956070c03252fad6a2f5a6cc7e37a9d6250508..3007deb6b7c19679379aafa6335466d006548de1 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -129,18 +129,11 @@
static const int kUpdateCheckIntervalHours = 6;
#endif
-#if defined(OS_WIN)
-// Attest to the fact that the call to the file thread to save preferences has
-// run, and it is safe to terminate. This avoids the potential of some other
-// task prematurely terminating our waiting message loop by posting a
-// QuitTask().
-static bool g_end_session_file_thread_has_completed = false;
-#endif
-
-#if defined(USE_X11)
-// How long to wait for the File thread to complete during EndSession, on
-// Linux. We have a timeout here because we're unable to run the UI messageloop
-// and there's some deadlock risk. Our only option is to exit anyway.
+#if defined(USE_X11) || defined(OS_WIN)
+// How long to wait for the File thread to complete during EndSession, on Linux
+// and Windows. We have a timeout here because we're unable to run the UI
+// messageloop and there's some deadlock risk. Our only option is to exit
+// anyway.
static const int kEndSessionTimeoutSeconds = 10;
#endif
@@ -314,16 +307,7 @@ void BrowserProcessImpl::PostDestroyThreads() {
io_thread_.reset();
}
-#if defined(OS_WIN)
-// Send a QuitTask to the given MessageLoop when the (file) thread has processed
-// our (other) recent requests (to save preferences).
-// Change the boolean so that the receiving thread will know that we did indeed
-// send the QuitTask that terminated the message loop.
-static void PostQuit(base::MessageLoop* message_loop) {
- g_end_session_file_thread_has_completed = true;
- message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
-}
-#elif defined(USE_X11)
+#if defined(USE_X11) || defined(OS_WIN)
static void Signal(base::WaitableEvent* event) {
event->Signal();
}
@@ -405,8 +389,18 @@ void BrowserProcessImpl::EndSession() {
// We must write that the profile and metrics service shutdown cleanly,
// otherwise on startup we'll think we crashed. So we block until done and
// then proceed with normal shutdown.
-#if defined(USE_X11)
- // Can't run a local loop on linux. Instead create a waitable event.
+#if defined(USE_X11) || defined(OS_WIN)
+ // Create a waitable event to block on file writing being complete.
+ //
+ // On Windows, we previously posted a message to FILE and then ran a nested
+ // message loop, waiting for that message to be processed until quitting.
+ // However, doing so means that other messages will also be processed. In
+ // particular, if the GPU process host notices that the GPU has been killed
+ // during shutdown, it races exiting the nested loop with the process host
+ // blocking the message loop attempting to re-establish a connection to the
+ // GPU process synchronously. Because the system may not be allowing
+ // processes to launch, this can result in a hang. See
+ // http://crbug.com/318527.
scoped_ptr<base::WaitableEvent> done_writing(
new base::WaitableEvent(false, false));
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
@@ -417,20 +411,6 @@ void BrowserProcessImpl::EndSession() {
base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds))) {
ignore_result(done_writing.release());
}
-
-#elif defined(OS_WIN)
- BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
- base::Bind(PostQuit, base::MessageLoop::current()));
- int quits_received = 0;
- do {
- base::MessageLoop::current()->Run();
- ++quits_received;
- } while (!g_end_session_file_thread_has_completed);
- // If we did get extra quits, then we should re-post them to the message loop.
- while (--quits_received > 0) {
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::MessageLoop::QuitClosure());
- }
#else
NOTIMPLEMENTED();
#endif
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698