summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 19:24:14 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 19:24:14 +0000
commit6faf7b1cc2d797140afd3df1211685307488cfcf (patch)
tree65eb681434792a9d5ff31714609efce599d1b37d /content
parentb2e88d83d0596926b6a71d459e6887b70b34e1fd (diff)
downloadchromium_src-6faf7b1cc2d797140afd3df1211685307488cfcf.zip
chromium_src-6faf7b1cc2d797140afd3df1211685307488cfcf.tar.gz
chromium_src-6faf7b1cc2d797140afd3df1211685307488cfcf.tar.bz2
Move ChildProcessHost and ChildProcessInfo to content.
TBR=avi Review URL: http://codereview.chromium.org/6612040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77496 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/browser_child_process_host.h4
-rw-r--r--content/browser/renderer_host/render_message_filter.cc2
-rw-r--r--content/browser/renderer_host/render_process_host.cc2
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host.h2
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_request_info.h2
-rw-r--r--content/browser/renderer_host/resource_message_filter.h2
-rw-r--r--content/common/child_process_host.cc231
-rw-r--r--content/common/child_process_host.h126
-rw-r--r--content/common/child_process_info.cc137
-rw-r--r--content/common/child_process_info.h137
-rw-r--r--content/content_common.gypi4
11 files changed, 642 insertions, 7 deletions
diff --git a/content/browser/browser_child_process_host.h b/content/browser/browser_child_process_host.h
index f57ec5f..2010a79 100644
--- a/content/browser/browser_child_process_host.h
+++ b/content/browser/browser_child_process_host.h
@@ -8,10 +8,10 @@
#include <list>
-#include "chrome/common/child_process_host.h"
-#include "chrome/common/child_process_info.h"
#include "content/browser/child_process_launcher.h"
#include "content/browser/renderer_host/resource_message_filter.h"
+#include "content/common/child_process_host.h"
+#include "content/common/child_process_info.h"
class ResourceDispatcherHost;
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index dcda00c..de62ee9 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -77,7 +77,7 @@
#include "base/file_descriptor_posix.h"
#endif
#if defined(OS_WIN)
-#include "chrome/common/child_process_host.h"
+#include "content/common/child_process_host.h"
#endif
#if defined(USE_NSS)
#include "chrome/browser/ui/crypto_module_password_dialog.h"
diff --git a/content/browser/renderer_host/render_process_host.cc b/content/browser/renderer_host/render_process_host.cc
index 113236d..66c3db3 100644
--- a/content/browser/renderer_host/render_process_host.cc
+++ b/content/browser/renderer_host/render_process_host.cc
@@ -6,11 +6,11 @@
#include "base/rand_util.h"
#include "base/sys_info.h"
-#include "chrome/common/child_process_info.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/notification_service.h"
#include "content/browser/browser_thread.h"
#include "content/browser/child_process_security_policy.h"
+#include "content/common/child_process_info.h"
namespace {
diff --git a/content/browser/renderer_host/resource_dispatcher_host.h b/content/browser/renderer_host/resource_dispatcher_host.h
index 7b5cf3c..12fca85 100644
--- a/content/browser/renderer_host/resource_dispatcher_host.h
+++ b/content/browser/renderer_host/resource_dispatcher_host.h
@@ -22,9 +22,9 @@
#include "base/observer_list.h"
#include "base/scoped_ptr.h"
#include "base/timer.h"
-#include "chrome/common/child_process_info.h"
#include "chrome/common/notification_type.h"
#include "content/browser/renderer_host/resource_queue.h"
+#include "content/common/child_process_info.h"
#include "ipc/ipc_message.h"
#include "net/url_request/url_request.h"
#include "webkit/glue/resource_type.h"
diff --git a/content/browser/renderer_host/resource_dispatcher_host_request_info.h b/content/browser/renderer_host/resource_dispatcher_host_request_info.h
index 2322c43..13b6fa2 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_request_info.h
+++ b/content/browser/renderer_host/resource_dispatcher_host_request_info.h
@@ -10,7 +10,7 @@
#include "base/basictypes.h"
#include "base/time.h"
-#include "chrome/common/child_process_info.h"
+#include "content/common/child_process_info.h"
#include "net/base/load_states.h"
#include "net/url_request/url_request.h"
#include "webkit/glue/resource_type.h"
diff --git a/content/browser/renderer_host/resource_message_filter.h b/content/browser/renderer_host/resource_message_filter.h
index efc6aa0..e3a6833 100644
--- a/content/browser/renderer_host/resource_message_filter.h
+++ b/content/browser/renderer_host/resource_message_filter.h
@@ -6,8 +6,8 @@
#define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_MESSAGE_FILTER_H_
#include "base/scoped_ptr.h"
-#include "chrome/common/child_process_info.h"
#include "content/browser/browser_message_filter.h"
+#include "content/common/child_process_info.h"
class ChromeURLRequestContext;
class ResourceDispatcherHost;
diff --git a/content/common/child_process_host.cc b/content/common/child_process_host.cc
new file mode 100644
index 0000000..c1dce2e
--- /dev/null
+++ b/content/common/child_process_host.cc
@@ -0,0 +1,231 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/child_process_host.h"
+
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/metrics/histogram.h"
+#include "base/path_service.h"
+#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
+#include "content/common/child_process_info.h"
+#include "content/common/child_process_messages.h"
+#include "content/common/content_paths.h"
+#include "content/common/content_switches.h"
+#include "ipc/ipc_logging.h"
+
+#if defined(OS_LINUX)
+#include "base/linux_util.h"
+#endif // OS_LINUX
+
+ChildProcessHost::ChildProcessHost()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(listener_(this)),
+ opening_channel_(false) {
+}
+
+ChildProcessHost::~ChildProcessHost() {
+ for (size_t i = 0; i < filters_.size(); ++i) {
+ filters_[i]->OnChannelClosing();
+ filters_[i]->OnFilterRemoved();
+ }
+}
+
+void ChildProcessHost::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
+ filters_.push_back(filter);
+
+ if (channel_.get())
+ filter->OnFilterAdded(channel_.get());
+}
+
+// static
+FilePath ChildProcessHost::GetChildPath(bool allow_self) {
+ FilePath child_path;
+
+ child_path = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
+ switches::kBrowserSubprocessPath);
+ if (!child_path.empty())
+ return child_path;
+
+#if defined(OS_LINUX)
+ // Use /proc/self/exe rather than our known binary path so updates
+ // can't swap out the binary from underneath us.
+ // When running under Valgrind, forking /proc/self/exe ends up forking the
+ // Valgrind executable, which then crashes. However, it's almost safe to
+ // assume that the updates won't happen while testing with Valgrind tools.
+ if (allow_self && !RunningOnValgrind())
+ return FilePath("/proc/self/exe");
+#endif
+
+ // On most platforms, the child executable is the same as the current
+ // executable.
+ PathService::Get(content::CHILD_PROCESS_EXE, &child_path);
+ return child_path;
+}
+
+#if defined(OS_WIN)
+// static
+void ChildProcessHost::PreCacheFont(LOGFONT font) {
+ // If a child process is running in a sandbox, GetTextMetrics()
+ // can sometimes fail. If a font has not been loaded
+ // previously, GetTextMetrics() will try to load the font
+ // from the font file. However, the sandboxed process does
+ // not have permissions to access any font files and
+ // the call fails. So we make the browser pre-load the
+ // font for us by using a dummy call to GetTextMetrics of
+ // the same font.
+
+ // Maintain a circular queue for the fonts and DCs to be cached.
+ // font_index maintains next available location in the queue.
+ static const int kFontCacheSize = 32;
+ static HFONT fonts[kFontCacheSize] = {0};
+ static HDC hdcs[kFontCacheSize] = {0};
+ static size_t font_index = 0;
+
+ UMA_HISTOGRAM_COUNTS_100("Memory.CachedFontAndDC",
+ fonts[kFontCacheSize-1] ? kFontCacheSize : static_cast<int>(font_index));
+
+ HDC hdc = GetDC(NULL);
+ HFONT font_handle = CreateFontIndirect(&font);
+ DCHECK(NULL != font_handle);
+
+ HGDIOBJ old_font = SelectObject(hdc, font_handle);
+ DCHECK(NULL != old_font);
+
+ TEXTMETRIC tm;
+ BOOL ret = GetTextMetrics(hdc, &tm);
+ DCHECK(ret);
+
+ if (fonts[font_index] || hdcs[font_index]) {
+ // We already have too many fonts, we will delete one and take it's place.
+ DeleteObject(fonts[font_index]);
+ ReleaseDC(NULL, hdcs[font_index]);
+ }
+
+ fonts[font_index] = font_handle;
+ hdcs[font_index] = hdc;
+ font_index = (font_index + 1) % kFontCacheSize;
+}
+#endif // OS_WIN
+
+
+bool ChildProcessHost::CreateChannel() {
+ channel_id_ = ChildProcessInfo::GenerateRandomChannelID(this);
+ channel_.reset(new IPC::Channel(
+ channel_id_, IPC::Channel::MODE_SERVER, &listener_));
+ if (!channel_->Connect())
+ return false;
+
+ for (size_t i = 0; i < filters_.size(); ++i)
+ filters_[i]->OnFilterAdded(channel_.get());
+
+ // Make sure these messages get sent first.
+#if defined(IPC_MESSAGE_LOG_ENABLED)
+ bool enabled = IPC::Logging::GetInstance()->Enabled();
+ Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled));
+#endif
+
+ Send(new ChildProcessMsg_AskBeforeShutdown());
+
+ opening_channel_ = true;
+
+ return true;
+}
+
+void ChildProcessHost::InstanceCreated() {
+ Notify(NotificationType::CHILD_INSTANCE_CREATED);
+}
+
+bool ChildProcessHost::OnMessageReceived(const IPC::Message& msg) {
+ return false;
+}
+
+void ChildProcessHost::OnChannelConnected(int32 peer_pid) {
+}
+
+void ChildProcessHost::OnChannelError() {
+}
+
+bool ChildProcessHost::Send(IPC::Message* message) {
+ if (!channel_.get()) {
+ delete message;
+ return false;
+ }
+ return channel_->Send(message);
+}
+
+void ChildProcessHost::OnChildDied() {
+ delete this;
+}
+
+void ChildProcessHost::ShutdownStarted() {
+}
+
+void ChildProcessHost::Notify(NotificationType type) {
+}
+
+ChildProcessHost::ListenerHook::ListenerHook(ChildProcessHost* host)
+ : host_(host) {
+}
+
+bool ChildProcessHost::ListenerHook::OnMessageReceived(
+ const IPC::Message& msg) {
+#ifdef IPC_MESSAGE_LOG_ENABLED
+ IPC::Logging* logger = IPC::Logging::GetInstance();
+ if (msg.type() == IPC_LOGGING_ID) {
+ logger->OnReceivedLoggingMessage(msg);
+ return true;
+ }
+
+ if (logger->Enabled())
+ logger->OnPreDispatchMessage(msg);
+#endif
+
+ bool handled = false;
+ for (size_t i = 0; i < host_->filters_.size(); ++i) {
+ if (host_->filters_[i]->OnMessageReceived(msg)) {
+ handled = true;
+ break;
+ }
+ }
+
+ if (!handled && msg.type() == ChildProcessHostMsg_ShutdownRequest::ID) {
+ if (host_->CanShutdown())
+ host_->Send(new ChildProcessMsg_Shutdown());
+ handled = true;
+ }
+
+ if (!handled)
+ handled = host_->OnMessageReceived(msg);
+
+#ifdef IPC_MESSAGE_LOG_ENABLED
+ if (logger->Enabled())
+ logger->OnPostDispatchMessage(msg, host_->channel_id_);
+#endif
+ return handled;
+}
+
+void ChildProcessHost::ListenerHook::OnChannelConnected(int32 peer_pid) {
+ host_->opening_channel_ = false;
+ host_->OnChannelConnected(peer_pid);
+ // Notify in the main loop of the connection.
+ host_->Notify(NotificationType::CHILD_PROCESS_HOST_CONNECTED);
+
+ for (size_t i = 0; i < host_->filters_.size(); ++i)
+ host_->filters_[i]->OnChannelConnected(peer_pid);
+}
+
+void ChildProcessHost::ListenerHook::OnChannelError() {
+ host_->opening_channel_ = false;
+ host_->OnChannelError();
+
+ for (size_t i = 0; i < host_->filters_.size(); ++i)
+ host_->filters_[i]->OnChannelError();
+
+ // This will delete host_, which will also destroy this!
+ host_->OnChildDied();
+}
+
+void ChildProcessHost::ForceShutdown() {
+ Send(new ChildProcessMsg_Shutdown());
+}
diff --git a/content/common/child_process_host.h b/content/common/child_process_host.h
new file mode 100644
index 0000000..67b14b5
--- /dev/null
+++ b/content/common/child_process_host.h
@@ -0,0 +1,126 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_COMMON_CHILD_PROCESS_HOST_H_
+#define CONTENT_COMMON_CHILD_PROCESS_HOST_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
+#include <windows.h>
+#endif // defined(OS_WIN)
+
+#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
+#include "content/common/notification_type.h"
+#include "ipc/ipc_channel_proxy.h"
+
+class CommandLine;
+class FilePath;
+
+namespace IPC {
+class Message;
+}
+
+// Provides common functionality for hosting a child process and processing IPC
+// messages between the host and the child process. Subclasses are responsible
+// for the actual launching and terminating of the child processes.
+class ChildProcessHost : public IPC::Channel::Listener,
+ public IPC::Message::Sender {
+ public:
+ virtual ~ChildProcessHost();
+
+ // Returns the pathname to be used for a child process. If a subprocess
+ // pathname was specified on the command line, that will be used. Otherwise,
+ // the default child process pathname will be returned. On most platforms,
+ // this will be the same as the currently-executing process.
+ //
+ // The argument allow_self is used on Linux to indicate that we allow us to
+ // fork from /proc/self/exe rather than using the "real" app path. This
+ // prevents autoupdate from confusing us if it changes the file out from
+ // under us. You will generally want to set this to true, except when there
+ // is an override to the command line (for example, we're forking a renderer
+ // in gdb). In this case, you'd use GetChildPath to get the real executable
+ // file name, and then prepend the GDB command to the command line.
+ //
+ // On failure, returns an empty FilePath.
+ static FilePath GetChildPath(bool allow_self);
+
+#if defined(OS_WIN)
+ // See comments in the cc file. This is a common hack needed for a process
+ // hosting a sandboxed child process. Hence it lives in this file.
+ static void PreCacheFont(LOGFONT font);
+#endif // defined(OS_WIN)
+
+ // IPC::Message::Sender implementation.
+ virtual bool Send(IPC::Message* message);
+
+ protected:
+ ChildProcessHost();
+
+ // Adds an IPC message filter. A reference will be kept to the filter.
+ void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
+
+ // 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();
+
+ // Creates the IPC channel. Returns true iff it succeeded.
+ virtual bool CreateChannel();
+
+ // Notifies us that an instance has been created on this child process.
+ virtual void InstanceCreated();
+
+ // IPC::Channel::Listener implementation:
+ virtual bool OnMessageReceived(const IPC::Message& msg);
+ virtual void OnChannelConnected(int32 peer_pid);
+ virtual void OnChannelError();
+
+ 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.
+ virtual void OnChildDied();
+ // Notifies the derived class that we told the child process to kill itself.
+ virtual void ShutdownStarted();
+ // Subclasses can implement specific notification methods.
+ virtual void Notify(NotificationType type);
+
+ 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 bool OnMessageReceived(const IPC::Message& msg);
+ virtual void OnChannelConnected(int32 peer_pid);
+ virtual void OnChannelError();
+ private:
+ ChildProcessHost* host_;
+ };
+
+ ListenerHook listener_;
+
+ bool opening_channel_; // True while we're waiting the channel to be opened.
+ scoped_ptr<IPC::Channel> channel_;
+ std::string channel_id_;
+
+ // Holds all the IPC message filters. Since this object lives on the IO
+ // thread, we don't have a IPC::ChannelProxy and so we manage filters
+ // manually.
+ std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChildProcessHost);
+};
+
+#endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_
diff --git a/content/common/child_process_info.cc b/content/common/child_process_info.cc
new file mode 100644
index 0000000..4775d7b
--- /dev/null
+++ b/content/common/child_process_info.cc
@@ -0,0 +1,137 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/child_process_info.h"
+
+#include <limits>
+
+#include "base/atomicops.h"
+#include "base/i18n/rtl.h"
+#include "base/logging.h"
+#include "base/process_util.h"
+#include "base/rand_util.h"
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+
+ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) :
+ type_(type),
+ renderer_type_(RENDERER_UNKNOWN) {
+ if (id == -1)
+ id_ = GenerateChildProcessUniqueId();
+ else
+ id_ = id;
+}
+
+ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original)
+ : type_(original.type_),
+ renderer_type_(original.renderer_type_),
+ name_(original.name_),
+ version_(original.version_),
+ id_(original.id_),
+ process_(original.process_) {
+}
+
+ChildProcessInfo::~ChildProcessInfo() {
+}
+
+ChildProcessInfo& ChildProcessInfo::operator=(
+ const ChildProcessInfo& original) {
+ if (&original != this) {
+ type_ = original.type_;
+ renderer_type_ = original.renderer_type_;
+ name_ = original.name_;
+ version_ = original.version_;
+ id_ = original.id_;
+ process_ = original.process_;
+ }
+ return *this;
+}
+
+// static
+std::string ChildProcessInfo::GetTypeNameInEnglish(
+ ChildProcessInfo::ProcessType type) {
+ switch (type) {
+ case BROWSER_PROCESS:
+ return "Browser";
+ case RENDER_PROCESS:
+ return "Tab";
+ case PLUGIN_PROCESS:
+ return "Plug-in";
+ case WORKER_PROCESS:
+ return "Web Worker";
+ case UTILITY_PROCESS:
+ return "Utility";
+ case PROFILE_IMPORT_PROCESS:
+ return "Profile Import helper";
+ case ZYGOTE_PROCESS:
+ return "Zygote";
+ case SANDBOX_HELPER_PROCESS:
+ return "Sandbox helper";
+ case NACL_LOADER_PROCESS:
+ return "Native Client module";
+ case NACL_BROKER_PROCESS:
+ return "Native Client broker";
+ case GPU_PROCESS:
+ return "GPU";
+ case PPAPI_PLUGIN_PROCESS:
+ return "Pepper Plugin";
+ case UNKNOWN_PROCESS:
+ default:
+ DCHECK(false) << "Unknown child process type!";
+ return "Unknown";
+ }
+}
+
+// static
+std::string ChildProcessInfo::GetRendererTypeNameInEnglish(
+ ChildProcessInfo::RendererProcessType type) {
+ switch (type) {
+ case RENDERER_NORMAL:
+ return "Tab";
+ case RENDERER_CHROME:
+ return "Tab (Chrome)";
+ case RENDERER_EXTENSION:
+ return "Extension";
+ case RENDERER_DEVTOOLS:
+ return "Devtools";
+ case RENDERER_INTERSTITIAL:
+ return "Interstitial";
+ case RENDERER_NOTIFICATION:
+ return "Notification";
+ case RENDERER_BACKGROUND_APP:
+ return "Background App";
+ case RENDERER_UNKNOWN:
+ default:
+ NOTREACHED() << "Unknown renderer process type!";
+ return "Unknown";
+ }
+}
+
+// static
+std::string ChildProcessInfo::GetFullTypeNameInEnglish(
+ ChildProcessInfo::ProcessType type,
+ ChildProcessInfo::RendererProcessType rtype) {
+ if (type == RENDER_PROCESS)
+ return GetRendererTypeNameInEnglish(rtype);
+ return GetTypeNameInEnglish(type);
+}
+
+std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) {
+ // Note: the string must start with the current process id, this is how
+ // child processes determine the pid of the parent.
+ // Build the channel ID. This is composed of a unique identifier for the
+ // parent browser process, an identifier for the child instance, and a random
+ // component. We use a random component so that a hacked child process can't
+ // cause denial of service by causing future named pipe creation to fail.
+ return base::StringPrintf("%d.%p.%d",
+ base::GetCurrentProcId(), instance,
+ base::RandInt(0, std::numeric_limits<int>::max()));
+}
+
+// static
+int ChildProcessInfo::GenerateChildProcessUniqueId() {
+ // This function must be threadsafe.
+ static base::subtle::Atomic32 last_unique_child_id = 0;
+ return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1);
+}
diff --git a/content/common/child_process_info.h b/content/common/child_process_info.h
new file mode 100644
index 0000000..e36ee52
--- /dev/null
+++ b/content/common/child_process_info.h
@@ -0,0 +1,137 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_COMMON_CHILD_PROCESS_INFO_H_
+#define CONTENT_COMMON_CHILD_PROCESS_INFO_H_
+#pragma once
+
+#include <string>
+
+#include "base/process.h"
+#include "base/string16.h"
+
+// Holds information about a child process.
+class ChildProcessInfo {
+ public:
+ // NOTE: Do not remove or reorder the elements in this enum, and only add new
+ // items at the end. We depend on these specific values in a histogram.
+ enum ProcessType {
+ UNKNOWN_PROCESS = 1,
+ BROWSER_PROCESS,
+ RENDER_PROCESS,
+ PLUGIN_PROCESS,
+ WORKER_PROCESS,
+ NACL_LOADER_PROCESS,
+ UTILITY_PROCESS,
+ PROFILE_IMPORT_PROCESS,
+ ZYGOTE_PROCESS,
+ SANDBOX_HELPER_PROCESS,
+ NACL_BROKER_PROCESS,
+ GPU_PROCESS,
+ PPAPI_PLUGIN_PROCESS
+ };
+
+ // NOTE: Do not remove or reorder the elements in this enum, and only add new
+ // items at the end. We depend on these specific values in a histogram.
+ enum RendererProcessType {
+ RENDERER_UNKNOWN = 0,
+ RENDERER_NORMAL,
+ RENDERER_CHROME, // WebUI (chrome:// URL)
+ RENDERER_EXTENSION, // chrome-extension://
+ RENDERER_DEVTOOLS, // Web inspector
+ RENDERER_INTERSTITIAL, // malware/phishing interstitial
+ RENDERER_NOTIFICATION, // HTML notification bubble
+ RENDERER_BACKGROUND_APP // hosted app background page
+ };
+
+ ChildProcessInfo(const ChildProcessInfo& original);
+ virtual ~ChildProcessInfo();
+
+ ChildProcessInfo& operator=(const ChildProcessInfo& original);
+
+ // Returns the type of the process.
+ ProcessType type() const { return type_; }
+
+ // Returns the renderer subtype of this process.
+ // Only valid if the type() is RENDER_PROCESS.
+ RendererProcessType renderer_type() const { return renderer_type_; }
+
+ // Returns the name of the process. i.e. for plugins it might be Flash, while
+ // for workers it might be the domain that it's from.
+ std::wstring name() const { return name_; }
+
+ // Returns the version of the exe, this only appliest to plugins. Otherwise
+ // the string is empty.
+ std::wstring version() const { return version_; }
+
+ // Getter to the process handle.
+ base::ProcessHandle handle() const { return process_.handle(); }
+
+ // Getter to the process ID.
+ int pid() const { return process_.pid(); }
+
+ // The unique identifier for this child process. This identifier is NOT a
+ // process ID, and will be unique for all types of child process for
+ // one run of the browser.
+ int id() const { return id_; }
+
+ void SetProcessBackgrounded() const { process_.SetProcessBackgrounded(true); }
+
+ // Returns an English name of the process type, should only be used for non
+ // user-visible strings, or debugging pages like about:memory.
+ static std::string GetFullTypeNameInEnglish(ProcessType type,
+ RendererProcessType rtype);
+ static std::string GetTypeNameInEnglish(ProcessType type);
+ static std::string GetRendererTypeNameInEnglish(RendererProcessType type);
+
+ // We define the < operator so that the ChildProcessInfo can be used as a key
+ // in a std::map.
+ bool operator <(const ChildProcessInfo& rhs) const {
+ if (process_.handle() != rhs.process_.handle())
+ return process_ .handle() < rhs.process_.handle();
+ return false;
+ }
+
+ bool operator ==(const ChildProcessInfo& rhs) const {
+ return process_.handle() == rhs.process_.handle();
+ }
+
+ // Generates a unique channel name for a child renderer/plugin process.
+ // The "instance" pointer value is baked into the channel id.
+ static std::string GenerateRandomChannelID(void* instance);
+
+ // Returns a unique ID to identify a child process. On construction, this
+ // function will be used to generate the id_, but it is also used to generate
+ // IDs for the RenderProcessHost, which doesn't inherit from us, and whose IDs
+ // must be unique for all child processes.
+ //
+ // This function is threadsafe since RenderProcessHost is on the UI thread,
+ // but normally this will be used on the IO thread.
+ static int GenerateChildProcessUniqueId();
+
+ protected:
+ // Derived objects need to use this constructor so we know what type we are.
+ // If the caller has already generated a unique ID for this child process,
+ // it should pass it as the second argument. Otherwise, -1 should be passed
+ // and a unique ID will be automatically generated.
+ ChildProcessInfo(ProcessType type, int id);
+
+ void set_type(ProcessType type) { type_ = type; }
+ void set_renderer_type(RendererProcessType type) { renderer_type_ = type; }
+ void set_name(const std::wstring& name) { name_ = name; }
+ void set_version(const std::wstring& ver) { version_ = ver; }
+ void set_handle(base::ProcessHandle handle) { process_.set_handle(handle); }
+
+ private:
+ ProcessType type_;
+ RendererProcessType renderer_type_;
+ std::wstring name_;
+ std::wstring version_;
+ int id_;
+
+ // The handle to the process.
+ mutable base::Process process_;
+};
+
+#endif // CONTENT_COMMON_CHILD_PROCESS_INFO_H_
diff --git a/content/content_common.gypi b/content/content_common.gypi
index 0925ebb..314487e 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -17,6 +17,10 @@
'sources': [
'common/child_process.cc',
'common/child_process.h',
+ 'common/child_process_host.cc',
+ 'common/child_process_host.h',
+ 'common/child_process_info.cc',
+ 'common/child_process_info.h',
'common/child_process_messages.h',
'common/child_thread.cc',
'common/child_thread.h',