Index: chrome/browser/child_process_host.cc |
=================================================================== |
--- chrome/browser/child_process_host.cc (revision 44239) |
+++ chrome/browser/child_process_host.cc (working copy) |
@@ -9,6 +9,7 @@ |
#include "base/file_path.h" |
#include "base/histogram.h" |
#include "base/logging.h" |
+#include "base/mp/mp_messages.h" |
#include "base/path_service.h" |
#include "base/process_util.h" |
#include "base/singleton.h" |
@@ -21,7 +22,6 @@ |
#include "chrome/common/env_vars.h" |
#include "chrome/common/notification_service.h" |
#include "chrome/common/notification_type.h" |
-#include "chrome/common/plugin_messages.h" |
#include "chrome/common/process_watcher.h" |
#include "chrome/common/result_codes.h" |
#include "chrome/installer/util/google_update_settings.h" |
@@ -70,16 +70,12 @@ |
ChildProcessHost::ChildProcessHost( |
ProcessType type, ResourceDispatcherHost* resource_dispatcher_host) |
: Receiver(type, -1), |
- ALLOW_THIS_IN_INITIALIZER_LIST(listener_(this)), |
- resource_dispatcher_host_(resource_dispatcher_host), |
- opening_channel_(false) { |
- Singleton<ChildProcessList>::get()->push_back(this); |
+ base::MpChildProcessHost(&context_), |
+ resource_dispatcher_host_(resource_dispatcher_host) { |
} |
ChildProcessHost::~ChildProcessHost() { |
- Singleton<ChildProcessList>::get()->remove(this); |
- |
if (resource_dispatcher_host_) |
resource_dispatcher_host_->CancelRequestsForProcess(id()); |
} |
@@ -130,154 +126,47 @@ |
#endif // OS_MACOSX |
} |
-void ChildProcessHost::Launch( |
-#if defined(OS_WIN) |
- const FilePath& exposed_dir, |
-#elif defined(OS_POSIX) |
- bool use_zygote, |
- const base::environment_vector& environ, |
-#endif |
- CommandLine* cmd_line) { |
- child_process_.reset(new ChildProcessLauncher( |
-#if defined(OS_WIN) |
- exposed_dir, |
-#elif defined(OS_POSIX) |
- use_zygote, |
- environ, |
- channel_->GetClientFileDescriptor(), |
-#endif |
- cmd_line, |
- &listener_)); |
-} |
- |
-bool ChildProcessHost::CreateChannel() { |
- channel_id_ = GenerateRandomChannelID(this); |
- channel_.reset(new IPC::Channel( |
- channel_id_, IPC::Channel::MODE_SERVER, &listener_)); |
- if (!channel_->Connect()) |
- return false; |
- |
- opening_channel_ = true; |
- |
- return true; |
-} |
- |
-void ChildProcessHost::InstanceCreated() { |
- Notify(NotificationType::CHILD_INSTANCE_CREATED); |
-} |
- |
bool ChildProcessHost::Send(IPC::Message* msg) { |
- if (!channel_.get()) { |
- delete msg; |
- return false; |
- } |
- return channel_->Send(msg); |
+ return base::MpChildProcessHost::Send(msg); |
} |
-void ChildProcessHost::Notify(NotificationType type) { |
+void ChildProcessHost::Notify( |
+ base::MpChildProcessHost::MpNotificationType type) { |
+ NotificationType chrome_type(NotificationType::ALL); |
+ switch (type) { |
+ case base::MpChildProcessHost::CHILD_INSTANCE_CREATED: |
+ chrome_type = NotificationType::CHILD_INSTANCE_CREATED; |
+ break; |
+ case base::MpChildProcessHost::CHILD_PROCESS_CRASHED: |
+ chrome_type = NotificationType::CHILD_PROCESS_CRASHED; |
+ break; |
+ case base::MpChildProcessHost::CHILD_PROCESS_HOST_CONNECTED: |
+ chrome_type = NotificationType::CHILD_PROCESS_HOST_CONNECTED; |
+ break; |
+ case base::MpChildProcessHost::CHILD_PROCESS_HOST_DISCONNECTED: |
+ chrome_type = NotificationType::CHILD_PROCESS_HOST_DISCONNECTED; |
+ break; |
+ default: |
+ NOTREACHED(); |
+ } |
ChromeThread::PostTask( |
- ChromeThread::UI, FROM_HERE, new ChildNotificationTask(type, this)); |
+ ChromeThread::UI, FROM_HERE, |
+ new ChildNotificationTask(chrome_type, this)); |
} |
-bool ChildProcessHost::DidChildCrash() { |
- return child_process_->DidProcessCrash(); |
+bool ChildProcessHost::OnDispatchMessageReceived(const IPC::Message& msg, |
+ bool *msg_is_ok) { |
+ return resource_dispatcher_host_->OnMessageReceived(msg, this, msg_is_ok); |
} |
-void ChildProcessHost::OnChildDied() { |
- if (handle() != base::kNullProcessHandle) { |
- bool did_crash = DidChildCrash(); |
- if (did_crash) { |
- OnProcessCrashed(); |
- // Report that this child process crashed. |
- Notify(NotificationType::CHILD_PROCESS_CRASHED); |
- UMA_HISTOGRAM_COUNTS("ChildProcess.Crashes", this->type()); |
- } |
- // Notify in the main loop of the disconnection. |
- Notify(NotificationType::CHILD_PROCESS_HOST_DISCONNECTED); |
- } |
- |
- delete this; |
+void ChildProcessHost::OnProcessLaunched() { |
+ set_handle(GetHandle()); |
} |
-ChildProcessHost::ListenerHook::ListenerHook(ChildProcessHost* host) |
- : host_(host) { |
+int ChildProcessHost::GetType() { |
+ return type(); |
} |
-void ChildProcessHost::ListenerHook::OnMessageReceived( |
- const IPC::Message& msg) { |
-#ifdef IPC_MESSAGE_LOG_ENABLED |
- IPC::Logging* logger = IPC::Logging::current(); |
- if (msg.type() == IPC_LOGGING_ID) { |
- logger->OnReceivedLoggingMessage(msg); |
- return; |
- } |
- |
- if (logger->Enabled()) |
- logger->OnPreDispatchMessage(msg); |
-#endif |
- |
- bool msg_is_ok = true; |
- bool handled = false; |
- |
- if (host_->resource_dispatcher_host_) |
- host_->resource_dispatcher_host_->OnMessageReceived( |
- msg, host_, &msg_is_ok); |
- |
- if (!handled) { |
- if (msg.type() == PluginProcessHostMsg_ShutdownRequest::ID) { |
- // 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. |
- Singleton<ChildProcessList>::get()->remove(host_); |
- if (host_->CanShutdown()) |
- host_->Send(new PluginProcessMsg_Shutdown()); |
- } else { |
- host_->OnMessageReceived(msg); |
- } |
- } |
- |
- if (!msg_is_ok) |
- base::KillProcess(host_->handle(), ResultCodes::KILLED_BAD_MESSAGE, false); |
- |
-#ifdef IPC_MESSAGE_LOG_ENABLED |
- if (logger->Enabled()) |
- logger->OnPostDispatchMessage(msg, host_->channel_id_); |
-#endif |
-} |
- |
-void ChildProcessHost::ListenerHook::OnChannelConnected(int32 peer_pid) { |
- host_->opening_channel_ = false; |
- host_->OnChannelConnected(peer_pid); |
- |
-#if defined(IPC_MESSAGE_LOG_ENABLED) |
- bool enabled = IPC::Logging::current()->Enabled(); |
- host_->Send(new PluginProcessMsg_SetIPCLoggingEnabled(enabled)); |
-#endif |
- |
- host_->Send(new PluginProcessMsg_AskBeforeShutdown()); |
- |
- // Notify in the main loop of the connection. |
- host_->Notify(NotificationType::CHILD_PROCESS_HOST_CONNECTED); |
-} |
- |
-void ChildProcessHost::ListenerHook::OnChannelError() { |
- host_->opening_channel_ = false; |
- host_->OnChannelError(); |
- |
- // This will delete host_, which will also destroy this! |
- 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) { |
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)) << |
@@ -312,8 +201,3 @@ |
bool ChildProcessHost::Iterator::Done() { |
return iterator_ == Singleton<ChildProcessList>::get()->end(); |
} |
- |
-void ChildProcessHost::ForceShutdown() { |
- Singleton<ChildProcessList>::get()->remove(this); |
- Send(new PluginProcessMsg_Shutdown()); |
-} |