diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-21 20:32:30 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-21 20:32:30 +0000 |
commit | fb1277e8766d447b967cfa959020b14c388e806e (patch) | |
tree | 1414679bfc830ff403c90fb1e8aa56a0180b514b /chrome/common/child_process_host.cc | |
parent | 51549da314ab40bfce645bb6c5875c4e5ec12f67 (diff) | |
download | chromium_src-fb1277e8766d447b967cfa959020b14c388e806e.zip chromium_src-fb1277e8766d447b967cfa959020b14c388e806e.tar.gz chromium_src-fb1277e8766d447b967cfa959020b14c388e806e.tar.bz2 |
Launch all child processes asynchronously so as not to block the IO thread.
BUG=6844, 27935
Review URL: http://codereview.chromium.org/402097
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/child_process_host.cc')
-rw-r--r-- | chrome/common/child_process_host.cc | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/chrome/common/child_process_host.cc b/chrome/common/child_process_host.cc index ca586d7..077eca5 100644 --- a/chrome/common/child_process_host.cc +++ b/chrome/common/child_process_host.cc @@ -79,9 +79,6 @@ ChildProcessHost::~ChildProcessHost() { Singleton<ChildProcessList>::get()->remove(this); resource_dispatcher_host_->CancelRequestsForProcess(id()); - - if (handle()) - ProcessWatcher::EnsureProcessTerminated(handle()); } // static @@ -132,6 +129,24 @@ void ChildProcessHost::SetCrashReporterCommandLine(CommandLine* command_line) { #endif // OS_MACOSX } +void ChildProcessHost::Launch( +#if defined(OS_WIN) + const FilePath& exposed_dir, +#elif defined(OS_POSIX) + const base::environment_vector& environ, +#endif + CommandLine* cmd_line) { + child_process_.reset(new ChildProcessLauncher( +#if defined(OS_WIN) + exposed_dir, +#elif defined(OS_POSIX) + environ, + channel_->GetClientFileDescriptor(), +#endif + cmd_line, + &listener_)); +} + bool ChildProcessHost::CreateChannel() { channel_id_ = GenerateRandomChannelID(this); channel_.reset(new IPC::Channel( @@ -144,11 +159,6 @@ bool ChildProcessHost::CreateChannel() { return true; } -void ChildProcessHost::SetHandle(base::ProcessHandle process) { - DCHECK(!handle()); - set_handle(process); -} - void ChildProcessHost::InstanceCreated() { Notify(NotificationType::CHILD_INSTANCE_CREATED); } @@ -167,19 +177,16 @@ void ChildProcessHost::Notify(NotificationType type) { } void ChildProcessHost::OnChildDied() { - DCHECK(handle()); - - bool did_crash = base::DidProcessCrash(NULL, handle()); - if (did_crash) { - // Report that this child process crashed. - Notify(NotificationType::CHILD_PROCESS_CRASHED); + if (child_process_->GetHandle()) { + bool did_crash = child_process_->DidProcessCrash(); + if (did_crash) { + OnProcessCrashed(); + // Report that this child process crashed. + Notify(NotificationType::CHILD_PROCESS_CRASHED); + } + // Notify in the main loop of the disconnection. + Notify(NotificationType::CHILD_PROCESS_HOST_DISCONNECTED); } - // Notify in the main loop of the disconnection. - Notify(NotificationType::CHILD_PROCESS_HOST_DISCONNECTED); - - // On POSIX, once we've called DidProcessCrash, handle() is no longer - // valid. Ensure the destructor doesn't try to use it. - set_handle(base::kNullProcessHandle); delete this; } @@ -249,6 +256,16 @@ void ChildProcessHost::ListenerHook::OnChannelError() { host_->OnChildDied(); } +void ChildProcessHost::ListenerHook::OnProcessLaunched() { + if (!host_->child_process_->GetHandle()) { + delete this; + return; + } + + host_->set_handle(host_->child_process_->GetHandle()); + host_->OnProcessLaunched(); +} + ChildProcessHost::Iterator::Iterator() : all_(true), type_(UNKNOWN_PROCESS) { |