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

Unified Diff: content/common/child_process_host.h

Issue 8774040: Don't make classes derive from ChildProcessHost, and instead have them use it through composition... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix linker errors on posix Created 9 years 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 | « content/browser/worker_host/worker_process_host.cc ('k') | content/common/child_process_host.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/child_process_host.h
===================================================================
--- content/common/child_process_host.h (revision 112722)
+++ content/common/child_process_host.h (working copy)
@@ -21,12 +21,12 @@
class FilePath;
-namespace IPC {
-class Message;
+namespace content {
+class ChildProcessHostDelegate;
}
// Provides common functionality for hosting a child process and processing IPC
-// messages between the host and the child process. Subclasses are responsible
+// messages between the host and the child process. Users are responsible
// for the actual launching and terminating of the child processes.
class CONTENT_EXPORT ChildProcessHost : public IPC::Channel::Listener,
public IPC::Message::Sender {
@@ -80,6 +80,8 @@
// On failure, returns an empty FilePath.
static FilePath GetChildPath(int flags);
+ explicit ChildProcessHost(content::ChildProcessHostDelegate* delegate);
+
// IPC::Message::Sender implementation.
virtual bool Send(IPC::Message* message) OVERRIDE;
@@ -87,7 +89,7 @@
void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
// Public and static for reuse by RenderMessageFilter.
- static void OnAllocateSharedMemory(
+ static void AllocateSharedMemory(
uint32 buffer_size, base::ProcessHandle child_process,
base::SharedMemoryHandle* handle);
@@ -104,68 +106,30 @@
// but normally this will be used on the IO thread.
static int GenerateChildProcessUniqueId();
- protected:
- ChildProcessHost();
-
- // Derived classes return true if it's ok to shut down the child process.
- virtual bool CanShutdown() = 0;
-
// Send the shutdown message to the child process.
// Does not check if CanShutdown is true.
- virtual void ForceShutdown();
+ void ForceShutdown();
// Creates the IPC channel. Returns true iff it succeeded.
- virtual bool CreateChannel();
+ bool CreateChannel();
- // IPC::Channel::Listener implementation:
- virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
- virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
- virtual void OnChannelError() OVERRIDE;
-
bool opening_channel() { return opening_channel_; }
const std::string& channel_id() { return channel_id_; }
IPC::Channel* channel() { return channel_.get(); }
- // Called when the child process goes away. See OnChildDisconnected().
- virtual void OnChildDied();
-
- // Called when the child process unexpected closes the IPC channel. The
- // default action is to call OnChildDied(). Subclasses might want to override
- // this behavior.
- virtual void OnChildDisconnected();
-
- // Notifies the derived class that we told the child process to kill itself.
- virtual void ShutdownStarted();
-
private:
- // 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 {
- public:
- explicit ListenerHook(ChildProcessHost* host);
- virtual ~ListenerHook();
+ // IPC::Channel::Listener methods:
+ virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
+ virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
+ virtual void OnChannelError() OVERRIDE;
- void Shutdown();
+ // Message handlers:
+ void OnShutdownRequest();
+ void OnAllocateSharedMemory(uint32 buffer_size,
+ base::SharedMemoryHandle* handle);
- // IPC::Channel::Listener methods:
- virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
- virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
- virtual void OnChannelError() OVERRIDE;
-
- bool Send(IPC::Message* message);
-
- private:
- void OnShutdownRequest();
- void OnAllocateSharedMemory(uint32 buffer_size,
- base::SharedMemoryHandle* handle);
- ChildProcessHost* host_;
- base::ProcessHandle peer_handle_;
- DISALLOW_COPY_AND_ASSIGN(ListenerHook);
- };
-
- ListenerHook listener_;
-
+ content::ChildProcessHostDelegate* delegate_;
+ base::ProcessHandle peer_handle_;
bool opening_channel_; // True while we're waiting the channel to be opened.
scoped_ptr<IPC::Channel> channel_;
std::string channel_id_;
« no previous file with comments | « content/browser/worker_host/worker_process_host.cc ('k') | content/common/child_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698