summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-15 06:13:35 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-15 06:13:35 +0000
commitaf391f0f9255a08f839068afee22c10f7b227734 (patch)
tree4798e109dca7a6618760351d3a12df66ea7bc80b /chrome
parentd46e5d7ff190e5790e9fc57e1ac260b5d51eeb12 (diff)
downloadchromium_src-af391f0f9255a08f839068afee22c10f7b227734.zip
chromium_src-af391f0f9255a08f839068afee22c10f7b227734.tar.gz
chromium_src-af391f0f9255a08f839068afee22c10f7b227734.tar.bz2
Improve fast-shutdown path to prevent flakiness
The current pattern used in the fast shutdown path is to send a message to the file thread, and assume that when it responds, then all prior file thread tasks are done. The "response" is a quit message. It is possible that some other quit messages are pending, and may cause us to terminate before the "real" response comes. This changes carefully waits for the real response, and pushes back any extra quit messages that are detected in case other code is waiting for them. r=darin BUG=96639 Review URL: http://codereview.chromium.org/7891065 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101255 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_process_impl.cc23
1 files changed, 21 insertions, 2 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index b2757f5..c67040b 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -107,6 +107,14 @@
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
@@ -281,8 +289,12 @@ BrowserProcessImpl::~BrowserProcessImpl() {
}
#if defined(OS_WIN)
-// Send a QuitTask to the given MessageLoop.
+// 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(MessageLoop* message_loop) {
+ g_end_session_file_thread_has_completed = true;
message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
}
#elif defined(USE_X11)
@@ -346,7 +358,14 @@ void BrowserProcessImpl::EndSession() {
#elif defined(OS_WIN)
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
NewRunnableFunction(PostQuit, MessageLoop::current()));
- MessageLoop::current()->Run();
+ int quits_received = 0;
+ do {
+ 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)
+ MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
#else
NOTIMPLEMENTED();
#endif