diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 20:24:49 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 20:24:49 +0000 |
commit | 4cb4310995f3b92adceb1e44b792726f7fc8249c (patch) | |
tree | 1b8217ee615f97dee3e42aa5794488fb6e31f058 /content/browser/browser_child_process_host.cc | |
parent | 9d43955551544e2954c4e085c8b34c866543f38e (diff) | |
download | chromium_src-4cb4310995f3b92adceb1e44b792726f7fc8249c.zip chromium_src-4cb4310995f3b92adceb1e44b792726f7fc8249c.tar.gz chromium_src-4cb4310995f3b92adceb1e44b792726f7fc8249c.tar.bz2 |
Don't make classes derive from ChildProcessHost, and instead have them use it through composition. This cleans up the code and makes it easier to understand (as well as more closely conform to the Google C++ style guide). It also makes it possible to add an interface around ChildProcessHost in a future change.
BUG=98716
Review URL: http://codereview.chromium.org/8774040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112769 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/browser_child_process_host.cc')
-rw-r--r-- | content/browser/browser_child_process_host.cc | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/content/browser/browser_child_process_host.cc b/content/browser/browser_child_process_host.cc index 508dade..3e56b6e 100644 --- a/content/browser/browser_child_process_host.cc +++ b/content/browser/browser_child_process_host.cc @@ -17,6 +17,7 @@ #include "content/browser/profiler_message_filter.h" #include "content/browser/renderer_host/resource_message_filter.h" #include "content/browser/trace_message_filter.h" +#include "content/common/child_process_host.h" #include "content/common/plugin_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_data.h" @@ -59,10 +60,11 @@ BrowserChildProcessHost::BrowserChildProcessHost( #endif disconnect_was_alive_(false) { data_.type = type; - data_.id = GenerateChildProcessUniqueId(); + data_.id = ChildProcessHost::GenerateChildProcessUniqueId(); - AddFilter(new TraceMessageFilter); - AddFilter(new ProfilerMessageFilter); + child_process_host_.reset(new ChildProcessHost(this)); + child_process_host_->AddFilter(new TraceMessageFilter); + child_process_host_->AddFilter(new ProfilerMessageFilter); g_child_process_list.Get().push_back(this); } @@ -96,7 +98,7 @@ void BrowserChildProcessHost::Launch( #elif defined(OS_POSIX) use_zygote, environ, - channel()->TakeClientFileDescriptor(), + child_process_host()->channel()->TakeClientFileDescriptor(), #endif cmd_line, &client_)); @@ -112,7 +114,7 @@ base::ProcessHandle BrowserChildProcessHost::GetChildProcessHandle() const { void BrowserChildProcessHost::ForceShutdown() { g_child_process_list.Get().remove(this); - ChildProcessHost::ForceShutdown(); + child_process_host_->ForceShutdown(); } void BrowserChildProcessHost::SetTerminateChildOnShutdown( @@ -132,11 +134,19 @@ base::TerminationStatus BrowserChildProcessHost::GetChildTerminationStatus( return child_process_->GetChildTerminationStatus(exit_code); } +bool BrowserChildProcessHost::OnMessageReceived(const IPC::Message& message) { + return false; +} + void BrowserChildProcessHost::OnChannelConnected(int32 peer_pid) { Notify(content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED); } -// The ChildProcessHost default implementation calls OnChildDied() always but at +bool BrowserChildProcessHost::CanShutdown() { + return true; +} + +// Normally a ChildProcessHostDelegate deletes itself from this callback, but at // this layer and below we need to have the final child process exit code to // properly bucket crashes vs kills. On Windows we can do this if we wait until // the process handle is signaled; on the rest of the platforms, we schedule a @@ -212,7 +222,7 @@ void BrowserChildProcessHost::OnChildDisconnected() { content::PROCESS_TYPE_MAX); // Notify in the main loop of the disconnection. Notify(content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED); - OnChildDied(); + delete this; } // The child process handle has been signaled so the exit code is finally @@ -226,13 +236,17 @@ void BrowserChildProcessHost::OnWaitableEventSignaled( GetExitCodeProcess(waitable_event->Release(), &exit_code); delete waitable_event; if (exit_code == STILL_ACTIVE) { - OnChildDied(); + delete this; } else { BrowserChildProcessHost::OnChildDisconnected(); } #endif } +bool BrowserChildProcessHost::Send(IPC::Message* message) { + return child_process_host_->Send(message); +} + void BrowserChildProcessHost::ShutdownStarted() { // Must remove the process from the list now, in case it gets used for a // new instance before our watcher tells us that the process terminated. @@ -245,7 +259,7 @@ BrowserChildProcessHost::ClientHook::ClientHook(BrowserChildProcessHost* host) void BrowserChildProcessHost::ClientHook::OnProcessLaunched() { if (!host_->child_process_->GetHandle()) { - host_->OnChildDied(); + delete host_; return; } host_->data_.handle = host_->child_process_->GetHandle(); |