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.h | |
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.h')
-rw-r--r-- | chrome/common/child_process_host.h | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/chrome/common/child_process_host.h b/chrome/common/child_process_host.h index a79eaf2..94bdafd 100644 --- a/chrome/common/child_process_host.h +++ b/chrome/common/child_process_host.h @@ -13,6 +13,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" +#include "chrome/browser/child_process_launcher.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "ipc/ipc_channel.h" @@ -25,7 +26,8 @@ class NotificationType; // [Browser]RenderProcessHost is the main exception that doesn't derive from // this class. That project lives on the UI thread. class ChildProcessHost : public ResourceDispatcherHost::Receiver, - public IPC::Channel::Listener { + public IPC::Channel::Listener, + public ChildProcessLauncher::Client { public: virtual ~ChildProcessHost(); @@ -70,16 +72,21 @@ class ChildProcessHost : public ResourceDispatcherHost::Receiver, ChildProcessHost(ProcessType type, ResourceDispatcherHost* resource_dispatcher_host); + // Derived classes call this to launch the child process asynchronously. + void Launch( +#if defined(OS_WIN) + const FilePath& exposed_dir, +#elif defined(OS_POSIX) + const base::environment_vector& environ, +#endif + CommandLine* cmd_line); + // Derived classes return true if it's ok to shut down the child process. virtual bool CanShutdown() = 0; // Creates the IPC channel. Returns true iff it succeeded. bool CreateChannel(); - // Once the subclass gets a handle to the process, it needs to tell - // ChildProcessHost using this function. - void SetHandle(base::ProcessHandle handle); - // Notifies us that an instance has been created on this child process. void InstanceCreated(); @@ -88,11 +95,15 @@ class ChildProcessHost : public ResourceDispatcherHost::Receiver, virtual void OnChannelConnected(int32 peer_pid) { } virtual void OnChannelError() { } + // ChildProcessLauncher::Client implementation. + virtual void OnProcessLaunched() {} + + // Derived classes can override this to know if the process crashed. + virtual void OnProcessCrashed() {} + bool opening_channel() { return opening_channel_; } const std::string& channel_id() { return channel_id_; } - const IPC::Channel& channel() const { return *channel_; } - private: // Sends the given notification to the notification service on the UI thread. void Notify(NotificationType type); @@ -103,28 +114,24 @@ class ChildProcessHost : public ResourceDispatcherHost::Receiver, // By using an internal class as the IPC::Channel::Listener, we can intercept // OnMessageReceived/OnChannelConnected and do our own processing before // calling the subclass' implementation. - class ListenerHook : public IPC::Channel::Listener { + class ListenerHook : public IPC::Channel::Listener, + public ChildProcessLauncher::Client { public: explicit ListenerHook(ChildProcessHost* host); virtual void OnMessageReceived(const IPC::Message& msg); virtual void OnChannelConnected(int32 peer_pid); virtual void OnChannelError(); + virtual void OnProcessLaunched(); private: ChildProcessHost* host_; }; ListenerHook listener_; - ResourceDispatcherHost* resource_dispatcher_host_; - - // True while we're waiting the channel to be opened. - bool opening_channel_; - - // The IPC::Channel. + bool opening_channel_; // True while we're waiting the channel to be opened. scoped_ptr<IPC::Channel> channel_; - - // IPC Channel's id. std::string channel_id_; + scoped_ptr<ChildProcessLauncher> child_process_; }; #endif // CHROME_COMMON_CHILD_PROCESS_HOST_H_ |