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

Unified Diff: chrome/common/child_process_host.cc

Issue 2885017: Moved common parts of ChildProcessHost into chrome/common and created a Brows... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Code review changes Created 10 years, 6 months 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 | « chrome/common/child_process_host.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/child_process_host.cc
===================================================================
--- chrome/common/child_process_host.cc (revision 51385)
+++ chrome/common/child_process_host.cc (working copy)
@@ -2,87 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/child_process_host.h"
+#include "chrome/common/child_process_host.h"
#include "base/command_line.h"
-#include "base/compiler_specific.h"
-#include "base/file_path.h"
-#include "base/histogram.h"
-#include "base/logging.h"
#include "base/path_service.h"
-#include "base/process_util.h"
-#include "base/singleton.h"
-#include "base/stl_util-inl.h"
-#include "base/string_util.h"
-#include "base/waitable_event.h"
-#include "chrome/browser/chrome_thread.h"
+#include "chrome/common/child_process_info.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
-#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"
#if defined(OS_LINUX)
#include "base/linux_util.h"
#endif // OS_LINUX
-#if defined(OS_POSIX)
-// This is defined in chrome/browser/google_update_settings_posix.cc. It's the
-// static string containing the user's unique GUID. We send this in the crash
-// report.
-namespace google_update {
-extern std::string posix_guid;
-} // namespace google_update
-#endif // OS_POSIX
-
-
-namespace {
-
-typedef std::list<ChildProcessHost*> ChildProcessList;
-
-// The NotificationTask is used to notify about plugin process connection/
-// disconnection. It is needed because the notifications in the
-// NotificationService must happen in the main thread.
-class ChildNotificationTask : public Task {
- public:
- ChildNotificationTask(
- NotificationType notification_type, ChildProcessInfo* info)
- : notification_type_(notification_type), info_(*info) { }
-
- virtual void Run() {
- NotificationService::current()->
- Notify(notification_type_, NotificationService::AllSources(),
- Details<ChildProcessInfo>(&info_));
- }
-
- private:
- NotificationType notification_type_;
- ChildProcessInfo info_;
-};
-
-} // namespace
-
-
-ChildProcessHost::ChildProcessHost(
- ProcessType type, ResourceDispatcherHost* resource_dispatcher_host)
- : Receiver(type, -1),
- ALLOW_THIS_IN_INITIALIZER_LIST(listener_(this)),
- resource_dispatcher_host_(resource_dispatcher_host),
+ChildProcessHost::ChildProcessHost()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(listener_(this)),
opening_channel_(false) {
- Singleton<ChildProcessList>::get()->push_back(this);
}
-
ChildProcessHost::~ChildProcessHost() {
- Singleton<ChildProcessList>::get()->remove(this);
-
- if (resource_dispatcher_host_)
- resource_dispatcher_host_->CancelRequestsForProcess(id());
}
// static
@@ -114,52 +53,8 @@
return child_path;
}
-// static
-void ChildProcessHost::SetCrashReporterCommandLine(CommandLine* command_line) {
-#if defined(USE_LINUX_BREAKPAD)
- const bool unattended = (getenv(env_vars::kHeadless) != NULL);
- if (unattended || GoogleUpdateSettings::GetCollectStatsConsent()) {
- command_line->AppendSwitchWithValue(switches::kEnableCrashReporter,
- ASCIIToWide(google_update::posix_guid +
- "," +
- base::GetLinuxDistro()));
- }
-#elif defined(OS_MACOSX)
- if (GoogleUpdateSettings::GetCollectStatsConsent())
- command_line->AppendSwitchWithValue(switches::kEnableCrashReporter,
- ASCIIToWide(google_update::posix_guid));
-#endif // OS_MACOSX
-}
-
-// static
-void ChildProcessHost::TerminateAll() {
- // Make a copy since the ChildProcessHost dtor mutates the original list.
- ChildProcessList copy = *(Singleton<ChildProcessList>::get());
- STLDeleteElements(&copy);
-}
-
-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_id_ = ChildProcessInfo::GenerateRandomChannelID(this);
channel_.reset(new IPC::Channel(
channel_id_, IPC::Channel::MODE_SERVER, &listener_));
if (!channel_->Connect())
@@ -174,7 +69,7 @@
Notify(NotificationType::CHILD_INSTANCE_CREATED);
}
-bool ChildProcessHost::Send(IPC::Message* msg) {
+bool ChildProcessHost::SendOnChannel(IPC::Message* msg) {
if (!channel_.get()) {
delete msg;
return false;
@@ -182,28 +77,7 @@
return channel_->Send(msg);
}
-void ChildProcessHost::Notify(NotificationType type) {
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE, new ChildNotificationTask(type, this));
-}
-
-bool ChildProcessHost::DidChildCrash() {
- return child_process_->DidProcessCrash();
-}
-
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;
}
@@ -224,29 +98,17 @@
logger->OnPreDispatchMessage(msg);
#endif
- bool msg_is_ok = true;
- bool handled = false;
+ bool handled = host_->InterceptMessageFromChild(msg);
- if (host_->resource_dispatcher_host_) {
- handled = 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());
+ host_->SendOnChannel(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_);
@@ -259,10 +121,10 @@
#if defined(IPC_MESSAGE_LOG_ENABLED)
bool enabled = IPC::Logging::current()->Enabled();
- host_->Send(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
+ host_->SendOnChannel(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
#endif
- host_->Send(new PluginProcessMsg_AskBeforeShutdown());
+ host_->SendOnChannel(new PluginProcessMsg_AskBeforeShutdown());
// Notify in the main loop of the connection.
host_->Notify(NotificationType::CHILD_PROCESS_HOST_CONNECTED);
@@ -276,53 +138,6 @@
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)) <<
- "ChildProcessInfo::Iterator must be used on the IO thread.";
- iterator_ = Singleton<ChildProcessList>::get()->begin();
-}
-
-ChildProcessHost::Iterator::Iterator(ProcessType type)
- : all_(false), type_(type) {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)) <<
- "ChildProcessInfo::Iterator must be used on the IO thread.";
- iterator_ = Singleton<ChildProcessList>::get()->begin();
- if (!Done() && (*iterator_)->type() != type_)
- ++(*this);
-}
-
-ChildProcessHost* ChildProcessHost::Iterator::operator++() {
- do {
- ++iterator_;
- if (Done())
- break;
-
- if (!all_ && (*iterator_)->type() != type_)
- continue;
-
- return *iterator_;
- } while (true);
-
- return NULL;
-}
-
-bool ChildProcessHost::Iterator::Done() {
- return iterator_ == Singleton<ChildProcessList>::get()->end();
-}
-
void ChildProcessHost::ForceShutdown() {
- Singleton<ChildProcessList>::get()->remove(this);
- Send(new PluginProcessMsg_Shutdown());
+ SendOnChannel(new PluginProcessMsg_Shutdown());
}
« no previous file with comments | « chrome/common/child_process_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698