diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 02:41:38 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 02:41:38 +0000 |
commit | cd69619bc053d527b7c82aac81c605157b28d01f (patch) | |
tree | f5a50afb86bd0ee0e0dae9a23213dcfaf1b9105e /chrome/browser/child_process_launcher.cc | |
parent | 980dbfd913c463f5fa8f1b5943327fe5e4799b20 (diff) | |
download | chromium_src-cd69619bc053d527b7c82aac81c605157b28d01f.zip chromium_src-cd69619bc053d527b7c82aac81c605157b28d01f.tar.gz chromium_src-cd69619bc053d527b7c82aac81c605157b28d01f.tar.bz2 |
Revert 46384 - Fix race in zygote_host_linux where socket was being read from and written to on different threads.
Made ZygoteHost methods all run on PROCESS_LAUNCHER thread. PostTask in linux from UI thread to PROCESS_LAUNCHER thread for DidProcessCrash. Changed DidProcessCrash to answer via a callback, which occurs asynchronously on linux. Rework cases in nacl_host, browser_render_process_host, and child_process_host where this method was being called to fit the callback model.
BUG=31737
TEST=none
Review URL: http://codereview.chromium.org/1695026
TBR=kkania@chromium.org
Review URL: http://codereview.chromium.org/1933007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46429 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/child_process_launcher.cc')
-rw-r--r-- | chrome/browser/child_process_launcher.cc | 80 |
1 files changed, 23 insertions, 57 deletions
diff --git a/chrome/browser/child_process_launcher.cc b/chrome/browser/child_process_launcher.cc index ff7a9d2..206d8a7 100644 --- a/chrome/browser/child_process_launcher.cc +++ b/chrome/browser/child_process_launcher.cc @@ -182,14 +182,14 @@ class ChildProcessLauncher::Context client_thread_id_, FROM_HERE, NewRunnableMethod( this, - &ChildProcessLauncher::Context::NotifyProcessLaunched, + &ChildProcessLauncher::Context::Notify, #if defined(OS_LINUX) use_zygote, #endif handle)); } - void NotifyProcessLaunched( + void Notify( #if defined(OS_LINUX) bool zygote, #endif @@ -206,59 +206,6 @@ class ChildProcessLauncher::Context } } - void DetermineDidProcessCrash() { - DCHECK(ChromeThread::CurrentlyOn(client_thread_id_)); - base::ProcessHandle handle = process_.handle(); -#if defined(OS_LINUX) - if (zygote_) { - ChromeThread::PostTask( - ChromeThread::PROCESS_LAUNCHER, FROM_HERE, - NewRunnableMethod(this, - &Context::DetermineDidProcessCrashInternal, - handle)); - } else -#endif - { - DetermineDidProcessCrashInternal(handle); - } - } - - void DetermineDidProcessCrashInternal(base::ProcessHandle handle) { - bool did_crash, child_exited; -#if defined(OS_LINUX) - if (zygote_) { - did_crash = Singleton<ZygoteHost>()->DidProcessCrash(handle, - &child_exited); - ChromeThread::PostTask( - client_thread_id_, FROM_HERE, - NewRunnableMethod(this, - &Context::OnDidProcessCrashDetermined, - child_exited, did_crash)); - } else -#endif - { - did_crash = base::DidProcessCrash(&child_exited, handle); - OnDidProcessCrashDetermined(child_exited, did_crash); - } - } - - void OnDidProcessCrashDetermined(bool child_exited, bool did_crash) { - DCHECK(ChromeThread::CurrentlyOn(client_thread_id_)); - - // POSIX: If the process crashed, then the kernel closed the socket for it - // and so the child has already died by the time we get here. Since - // DidProcessCrash called waitpid with WNOHANG, it'll reap the process. - // However, if DidProcessCrash didn't reap the child, we'll need to in - // Terminate via ProcessWatcher. So we can't close the handle here. - if (child_exited) - process_.Close(); - - if (client_) - client_->OnDidProcessCrashDetermined(did_crash); - // The client may have deleted us in the callback. Do not add anything - // after this point. - } - void Terminate() { if (!process_.handle()) return; @@ -348,8 +295,27 @@ base::ProcessHandle ChildProcessLauncher::GetHandle() { return context_->process_.handle(); } -void ChildProcessLauncher::DetermineDidProcessCrash() { - context_->DetermineDidProcessCrash(); +bool ChildProcessLauncher::DidProcessCrash() { + bool did_crash, child_exited; + base::ProcessHandle handle = context_->process_.handle(); +#if defined(OS_LINUX) + if (context_->zygote_) { + did_crash = Singleton<ZygoteHost>()->DidProcessCrash(handle, &child_exited); + } else +#endif + { + did_crash = base::DidProcessCrash(&child_exited, handle); + } + + // POSIX: If the process crashed, then the kernel closed the socket for it + // and so the child has already died by the time we get here. Since + // DidProcessCrash called waitpid with WNOHANG, it'll reap the process. + // However, if DidProcessCrash didn't reap the child, we'll need to in + // Terminate via ProcessWatcher. So we can't close the handle here. + if (child_exited) + context_->process_.Close(); + + return did_crash; } void ChildProcessLauncher::SetProcessBackgrounded(bool background) { |