Commit 4306c379 authored by jam@chromium.org's avatar jam@chromium.org

Get rid of the ChildProcessInfo class. It was carrying unnecessary data, and...

Get rid of the ChildProcessInfo class. It was carrying unnecessary data, and the fact that some processes inherited from it was confusing. There's now a simpler struct, content::ChildProcessData. BrowserChildProcessHost uses composition instead of inheritence.

BUG=98716
Review URL: http://codereview.chromium.org/8770027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112597 0039d316-1c4b-4281-b951-d872f2087c98
parent 5aa9c09b
...@@ -2723,11 +2723,11 @@ void GetChildProcessHostInfo(ListValue* child_processes) { ...@@ -2723,11 +2723,11 @@ void GetChildProcessHostInfo(ListValue* child_processes) {
// since we need their handle. // since we need their handle.
if ((*iter)->handle() == base::kNullProcessHandle) if ((*iter)->handle() == base::kNullProcessHandle)
continue; continue;
ChildProcessInfo* info = *iter;
DictionaryValue* item = new DictionaryValue; DictionaryValue* item = new DictionaryValue;
item->SetString("name", info->name()); item->SetString("name", iter->name());
item->SetString("type", content::GetProcessTypeNameInEnglish(info->type())); item->SetString("type",
item->SetInteger("pid", base::GetProcId(info->handle())); content::GetProcessTypeNameInEnglish(iter->type()));
item->SetInteger("pid", base::GetProcId(iter->handle()));
child_processes->Append(item); child_processes->Append(item);
} }
} }
......
...@@ -1339,13 +1339,13 @@ void MetricsService::LogChildProcessChange( ...@@ -1339,13 +1339,13 @@ void MetricsService::LogChildProcessChange(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
content::Details<ChildProcessInfo> child_details(details); content::Details<content::ChildProcessData> child_details(details);
const string16& child_name = child_details->name(); const string16& child_name = child_details->name;
if (child_process_stats_buffer_.find(child_name) == if (child_process_stats_buffer_.find(child_name) ==
child_process_stats_buffer_.end()) { child_process_stats_buffer_.end()) {
child_process_stats_buffer_[child_name] = child_process_stats_buffer_[child_name] =
ChildProcessStats(child_details->type()); ChildProcessStats(child_details->type);
} }
ChildProcessStats& stats = child_process_stats_buffer_[child_name]; ChildProcessStats& stats = child_process_stats_buffer_[child_name];
...@@ -1362,7 +1362,7 @@ void MetricsService::LogChildProcessChange( ...@@ -1362,7 +1362,7 @@ void MetricsService::LogChildProcessChange(
stats.process_crashes++; stats.process_crashes++;
// Exclude plugin crashes from the count below because we report them via // Exclude plugin crashes from the count below because we report them via
// a separate UMA metric. // a separate UMA metric.
if (!IsPluginProcess(child_details->type())) { if (!IsPluginProcess(child_details->type)) {
IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); IncrementPrefValue(prefs::kStabilityChildProcessCrashCount);
} }
break; break;
......
...@@ -787,7 +787,7 @@ base::ProcessHandle TaskManagerChildProcessResource::GetProcess() const { ...@@ -787,7 +787,7 @@ base::ProcessHandle TaskManagerChildProcessResource::GetProcess() const {
} }
TaskManager::Resource::Type TaskManagerChildProcessResource::GetType() const { TaskManager::Resource::Type TaskManagerChildProcessResource::GetType() const {
// Translate types to TaskManager::ResourceType, since ChildProcessInfo's type // Translate types to TaskManager::ResourceType, since ChildProcessData's type
// is not available for all TaskManager resources. // is not available for all TaskManager resources.
switch (type_) { switch (type_) {
case content::PROCESS_TYPE_PLUGIN: case content::PROCESS_TYPE_PLUGIN:
...@@ -924,7 +924,7 @@ void TaskManagerChildProcessResourceProvider::StartUpdating() { ...@@ -924,7 +924,7 @@ void TaskManagerChildProcessResourceProvider::StartUpdating() {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::Bind( base::Bind(
&TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo, &TaskManagerChildProcessResourceProvider::RetrieveChildProcessData,
this)); this));
} }
...@@ -952,11 +952,8 @@ void TaskManagerChildProcessResourceProvider::Observe( ...@@ -952,11 +952,8 @@ void TaskManagerChildProcessResourceProvider::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
content::Details<ChildProcessInfo> child_details(details); content::ChildProcessData data =
ChildProcessData data; *content::Details<content::ChildProcessData>(details).ptr();
data.type = child_details->type();
data.name = child_details->name();
data.handle = child_details->handle();
switch (type) { switch (type) {
case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED:
Add(data); Add(data);
...@@ -971,7 +968,7 @@ void TaskManagerChildProcessResourceProvider::Observe( ...@@ -971,7 +968,7 @@ void TaskManagerChildProcessResourceProvider::Observe(
} }
void TaskManagerChildProcessResourceProvider::Add( void TaskManagerChildProcessResourceProvider::Add(
const ChildProcessData& child_process_data) { const content::ChildProcessData& child_process_data) {
if (!updating_) if (!updating_)
return; return;
// Workers are handled by TaskManagerWorkerResourceProvider. // Workers are handled by TaskManagerWorkerResourceProvider.
...@@ -988,14 +985,14 @@ void TaskManagerChildProcessResourceProvider::Add( ...@@ -988,14 +985,14 @@ void TaskManagerChildProcessResourceProvider::Add(
} }
void TaskManagerChildProcessResourceProvider::Remove( void TaskManagerChildProcessResourceProvider::Remove(
const ChildProcessData& child_process_data) { const content::ChildProcessData& child_process_data) {
if (!updating_) if (!updating_)
return; return;
if (child_process_data.type == content::PROCESS_TYPE_WORKER) if (child_process_data.type == content::PROCESS_TYPE_WORKER)
return; return;
ChildProcessMap::iterator iter = resources_.find(child_process_data.handle); ChildProcessMap::iterator iter = resources_.find(child_process_data.handle);
if (iter == resources_.end()) { if (iter == resources_.end()) {
// ChildProcessInfo disconnection notifications are asynchronous, so we // ChildProcessData disconnection notifications are asynchronous, so we
// might be notified for a plugin we don't know anything about (if it was // might be notified for a plugin we don't know anything about (if it was
// closed before the task manager was shown and destroyed after that). // closed before the task manager was shown and destroyed after that).
return; return;
...@@ -1017,7 +1014,7 @@ void TaskManagerChildProcessResourceProvider::Remove( ...@@ -1017,7 +1014,7 @@ void TaskManagerChildProcessResourceProvider::Remove(
} }
void TaskManagerChildProcessResourceProvider::AddToTaskManager( void TaskManagerChildProcessResourceProvider::AddToTaskManager(
const ChildProcessData& child_process_data) { const content::ChildProcessData& child_process_data) {
TaskManagerChildProcessResource* resource = TaskManagerChildProcessResource* resource =
new TaskManagerChildProcessResource( new TaskManagerChildProcessResource(
child_process_data.type, child_process_data.type,
...@@ -1028,14 +1025,14 @@ void TaskManagerChildProcessResourceProvider::AddToTaskManager( ...@@ -1028,14 +1025,14 @@ void TaskManagerChildProcessResourceProvider::AddToTaskManager(
task_manager_->AddResource(resource); task_manager_->AddResource(resource);
} }
// The ChildProcessInfo::Iterator has to be used from the IO thread. // The ChildProcessData::Iterator has to be used from the IO thread.
void TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo() { void TaskManagerChildProcessResourceProvider::RetrieveChildProcessData() {
std::vector<ChildProcessData> child_processes; std::vector<content::ChildProcessData> child_processes;
for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) {
// Only add processes which are already started, since we need their handle. // Only add processes which are already started, since we need their handle.
if ((*iter)->handle() == base::kNullProcessHandle) if ((*iter)->handle() == base::kNullProcessHandle)
continue; continue;
ChildProcessData data; content::ChildProcessData data;
data.type = (*iter)->type(); data.type = (*iter)->type();
data.name = (*iter)->name(); data.name = (*iter)->name();
data.handle = (*iter)->handle(); data.handle = (*iter)->handle();
...@@ -1046,13 +1043,13 @@ void TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo() { ...@@ -1046,13 +1043,13 @@ void TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo() {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind( base::Bind(
&TaskManagerChildProcessResourceProvider::ChildProcessInfoRetreived, &TaskManagerChildProcessResourceProvider::ChildProcessDataRetreived,
this, child_processes)); this, child_processes));
} }
// This is called on the UI thread. // This is called on the UI thread.
void TaskManagerChildProcessResourceProvider::ChildProcessInfoRetreived( void TaskManagerChildProcessResourceProvider::ChildProcessDataRetreived(
const std::vector<ChildProcessData>& child_processes) { const std::vector<content::ChildProcessData>& child_processes) {
for (size_t i = 0; i < child_processes.size(); ++i) for (size_t i = 0; i < child_processes.size(); ++i)
Add(child_processes[i]); Add(child_processes[i]);
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/process_util.h" #include "base/process_util.h"
#include "chrome/browser/task_manager/task_manager.h" #include "chrome/browser/task_manager/task_manager.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/common/process_type.h" #include "content/public/common/process_type.h"
...@@ -288,27 +289,21 @@ class TaskManagerChildProcessResourceProvider ...@@ -288,27 +289,21 @@ class TaskManagerChildProcessResourceProvider
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
private: private:
struct ChildProcessData {
content::ProcessType type;
string16 name;
base::ProcessHandle handle;
};
virtual ~TaskManagerChildProcessResourceProvider(); virtual ~TaskManagerChildProcessResourceProvider();
// Retrieves information about the running ChildProcessHosts (performed in the // Retrieves information about the running ChildProcessHosts (performed in the
// IO thread). // IO thread).
virtual void RetrieveChildProcessInfo(); virtual void RetrieveChildProcessData();
// Notifies the UI thread that the ChildProcessHosts information have been // Notifies the UI thread that the ChildProcessHosts information have been
// retrieved. // retrieved.
virtual void ChildProcessInfoRetreived( virtual void ChildProcessDataRetreived(
const std::vector<ChildProcessData>& child_processes); const std::vector<content::ChildProcessData>& child_processes);
void Add(const ChildProcessData& child_process_data); void Add(const content::ChildProcessData& child_process_data);
void Remove(const ChildProcessData& child_process_data); void Remove(const content::ChildProcessData& child_process_data);
void AddToTaskManager(const ChildProcessData& child_process_data); void AddToTaskManager(const content::ChildProcessData& child_process_data);
TaskManager* task_manager_; TaskManager* task_manager_;
...@@ -316,7 +311,7 @@ class TaskManagerChildProcessResourceProvider ...@@ -316,7 +311,7 @@ class TaskManagerChildProcessResourceProvider
// notifications sent after StopUpdating(). // notifications sent after StopUpdating().
bool updating_; bool updating_;
// Maps the actual resources (the ChildProcessInfo) to the Task Manager // Maps the actual resources (the ChildProcessData) to the Task Manager
// resources. // resources.
typedef std::map<base::ProcessHandle, TaskManagerChildProcessResource*> typedef std::map<base::ProcessHandle, TaskManagerChildProcessResource*>
ChildProcessMap; ChildProcessMap;
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
#include "content/browser/worker_host/worker_service.h" #include "content/browser/worker_host/worker_service.h"
#include "content/browser/worker_host/worker_service_observer.h" #include "content/browser/worker_host/worker_service_observer.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/devtools_agent_host_registry.h" #include "content/public/browser/devtools_agent_host_registry.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/common/process_type.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "grit/theme_resources_standard.h" #include "grit/theme_resources_standard.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -34,15 +34,15 @@ using content::DevToolsAgentHostRegistry; ...@@ -34,15 +34,15 @@ using content::DevToolsAgentHostRegistry;
// only on the UI thread. Destructor may be called on any thread. // only on the UI thread. Destructor may be called on any thread.
class TaskManagerSharedWorkerResource : public TaskManager::Resource { class TaskManagerSharedWorkerResource : public TaskManager::Resource {
public: public:
TaskManagerSharedWorkerResource(const ChildProcessInfo& process_info, TaskManagerSharedWorkerResource(const content::ChildProcessData& process_data,
int routing_id, const GURL& url, int routing_id, const GURL& url,
const string16& name); const string16& name);
virtual ~TaskManagerSharedWorkerResource(); virtual ~TaskManagerSharedWorkerResource();
bool Matches(int process_id, int routing_id) const; bool Matches(int process_id, int routing_id) const;
void UpdateProcessInfo(const ChildProcessInfo& process_info); void UpdateProcessData(const content::ChildProcessData& process_data);
const ChildProcessInfo& process_info() { return process_info_; } const content::ChildProcessData& process_data() { return process_data_; }
private: private:
// TaskManager::Resource methods: // TaskManager::Resource methods:
...@@ -57,7 +57,7 @@ class TaskManagerSharedWorkerResource : public TaskManager::Resource { ...@@ -57,7 +57,7 @@ class TaskManagerSharedWorkerResource : public TaskManager::Resource {
virtual bool SupportNetworkUsage() const OVERRIDE; virtual bool SupportNetworkUsage() const OVERRIDE;
virtual void SetSupportNetworkUsage() OVERRIDE; virtual void SetSupportNetworkUsage() OVERRIDE;
ChildProcessInfo process_info_; content::ChildProcessData process_data_;
int routing_id_; int routing_id_;
string16 title_; string16 title_;
...@@ -69,11 +69,11 @@ class TaskManagerSharedWorkerResource : public TaskManager::Resource { ...@@ -69,11 +69,11 @@ class TaskManagerSharedWorkerResource : public TaskManager::Resource {
SkBitmap* TaskManagerSharedWorkerResource::default_icon_ = NULL; SkBitmap* TaskManagerSharedWorkerResource::default_icon_ = NULL;
TaskManagerSharedWorkerResource::TaskManagerSharedWorkerResource( TaskManagerSharedWorkerResource::TaskManagerSharedWorkerResource(
const ChildProcessInfo& process_info, const content::ChildProcessData& process_data,
int routing_id, int routing_id,
const GURL& url, const GURL& url,
const string16& name) const string16& name)
: process_info_(process_info), : process_data_(process_data),
routing_id_(routing_id) { routing_id_(routing_id) {
title_ = UTF8ToUTF16(url.spec()); title_ = UTF8ToUTF16(url.spec());
if (!name.empty()) if (!name.empty())
...@@ -85,12 +85,12 @@ TaskManagerSharedWorkerResource::~TaskManagerSharedWorkerResource() { ...@@ -85,12 +85,12 @@ TaskManagerSharedWorkerResource::~TaskManagerSharedWorkerResource() {
bool TaskManagerSharedWorkerResource::Matches(int process_id, bool TaskManagerSharedWorkerResource::Matches(int process_id,
int routing_id) const { int routing_id) const {
return process_info_.id() == process_id && routing_id_ == routing_id; return process_data_.id == process_id && routing_id_ == routing_id;
} }
void TaskManagerSharedWorkerResource::UpdateProcessInfo( void TaskManagerSharedWorkerResource::UpdateProcessData(
const ChildProcessInfo& process_info) { const content::ChildProcessData& process_data) {
process_info_ = process_info; process_data_ = process_data;
} }
string16 TaskManagerSharedWorkerResource::GetTitle() const { string16 TaskManagerSharedWorkerResource::GetTitle() const {
...@@ -111,7 +111,7 @@ SkBitmap TaskManagerSharedWorkerResource::GetIcon() const { ...@@ -111,7 +111,7 @@ SkBitmap TaskManagerSharedWorkerResource::GetIcon() const {
} }
base::ProcessHandle TaskManagerSharedWorkerResource::GetProcess() const { base::ProcessHandle TaskManagerSharedWorkerResource::GetProcess() const {
return process_info_.handle(); return process_data_.handle;
} }
TaskManager::Resource::Type TaskManagerSharedWorkerResource::GetType() const { TaskManager::Resource::Type TaskManagerSharedWorkerResource::GetType() const {
...@@ -130,7 +130,7 @@ void TaskManagerSharedWorkerResource::Inspect() const { ...@@ -130,7 +130,7 @@ void TaskManagerSharedWorkerResource::Inspect() const {
return; return;
DevToolsAgentHost* agent_host = DevToolsAgentHost* agent_host =
DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker( DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker(
process_info_.id(), process_data_.id,
routing_id_); routing_id_);
DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host);
} }
...@@ -217,7 +217,8 @@ void TaskManagerWorkerResourceProvider::WorkerCreated( ...@@ -217,7 +217,8 @@ void TaskManagerWorkerResourceProvider::WorkerCreated(
WorkerProcessHost* process, WorkerProcessHost* process,
const WorkerProcessHost::WorkerInstance& instance) { const WorkerProcessHost::WorkerInstance& instance) {
TaskManagerSharedWorkerResource* resource = TaskManagerSharedWorkerResource* resource =
new TaskManagerSharedWorkerResource(*process, instance.worker_route_id(), new TaskManagerSharedWorkerResource(process->data(),
instance.worker_route_id(),
instance.url(), instance.name()); instance.url(), instance.name());
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
...@@ -238,19 +239,19 @@ void TaskManagerWorkerResourceProvider::Observe( ...@@ -238,19 +239,19 @@ void TaskManagerWorkerResourceProvider::Observe(
int type, int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
ChildProcessInfo* process_info = content::ChildProcessData* process_data =
content::Details<ChildProcessInfo>(details).ptr(); content::Details<content::ChildProcessData>(details).ptr();
if (process_info->type() != content::PROCESS_TYPE_WORKER) if (process_data->type != content::PROCESS_TYPE_WORKER)
return; return;
if (type == content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED) { if (type == content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED) {
ProcessIdToWorkerResources::iterator it = ProcessIdToWorkerResources::iterator it =
launching_workers_.find(process_info->id()); launching_workers_.find(process_data->id);
if (it == launching_workers_.end()) if (it == launching_workers_.end())
return; return;
WorkerResourceList& resources = it->second; WorkerResourceList& resources = it->second;
for (WorkerResourceList::iterator r = resources.begin(); for (WorkerResourceList::iterator r = resources.begin();
r !=resources.end(); ++r) { r !=resources.end(); ++r) {
(*r)->UpdateProcessInfo(*process_info); (*r)->UpdateProcessData(*process_data);
task_manager_->AddResource(*r); task_manager_->AddResource(*r);
} }
launching_workers_.erase(it); launching_workers_.erase(it);
...@@ -261,7 +262,7 @@ void TaskManagerWorkerResourceProvider::Observe( ...@@ -261,7 +262,7 @@ void TaskManagerWorkerResourceProvider::Observe(
// workers here when the worker process has been destroyed. // workers here when the worker process has been destroyed.
for (WorkerResourceList::iterator it = resources_.begin(); for (WorkerResourceList::iterator it = resources_.begin();
it !=resources_.end();) { it !=resources_.end();) {
if ((*it)->process_info().id() == process_info->id()) { if ((*it)->process_data().id == process_data->id) {
task_manager_->RemoveResource(*it); task_manager_->RemoveResource(*it);
delete *it; delete *it;
it = resources_.erase(it); it = resources_.erase(it);
...@@ -269,7 +270,7 @@ void TaskManagerWorkerResourceProvider::Observe( ...@@ -269,7 +270,7 @@ void TaskManagerWorkerResourceProvider::Observe(
++it; ++it;
} }
} }
DCHECK(launching_workers_.find(process_info->id()) == DCHECK(launching_workers_.find(process_data->id) ==
launching_workers_.end()); launching_workers_.end());
} }
} }
...@@ -309,7 +310,7 @@ void TaskManagerWorkerResourceProvider::StartObservingWorkers() { ...@@ -309,7 +310,7 @@ void TaskManagerWorkerResourceProvider::StartObservingWorkers() {
for (WorkerProcessHost::Instances::const_iterator i = instances.begin(); for (WorkerProcessHost::Instances::const_iterator i = instances.begin();
i != instances.end(); ++i) { i != instances.end(); ++i) {
holder->resources()->push_back(new TaskManagerSharedWorkerResource( holder->resources()->push_back(new TaskManagerSharedWorkerResource(
**iter, i->worker_route_id(), i->url(), i->name())); (*iter)->data(), i->worker_route_id(), i->url(), i->name()));
} }
} }
...@@ -343,8 +344,8 @@ void TaskManagerWorkerResourceProvider::AddResource( ...@@ -343,8 +344,8 @@ void TaskManagerWorkerResourceProvider::AddResource(
TaskManagerSharedWorkerResource* resource) { TaskManagerSharedWorkerResource* resource) {
DCHECK(updating_); DCHECK(updating_);
resources_.push_back(resource); resources_.push_back(resource);
if (resource->process_info().handle() == base::kNullProcessHandle) { if (resource->process_data().handle == base::kNullProcessHandle) {
int process_id = resource->process_info().id(); int process_id = resource->process_data().id;
launching_workers_[process_id].push_back(resource); launching_workers_[process_id].push_back(resource);
} else { } else {
task_manager_->AddResource(resource); task_manager_->AddResource(resource);
......
...@@ -52,7 +52,7 @@ DictionaryValue* BuildWorkerData( ...@@ -52,7 +52,7 @@ DictionaryValue* BuildWorkerData(
worker_data->SetInteger(kWorkerRouteIdField, instance.worker_route_id()); worker_data->SetInteger(kWorkerRouteIdField, instance.worker_route_id());
worker_data->SetString(kUrlField, instance.url().spec()); worker_data->SetString(kUrlField, instance.url().spec());
worker_data->SetString(kNameField, instance.name()); worker_data->SetString(kNameField, instance.name());
worker_data->SetInteger(kPidField, process->pid()); worker_data->SetInteger(kPidField, base::GetProcId(process->handle()));
return worker_data; return worker_data;
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "content/browser/browser_child_process_host.h" #include "content/browser/browser_child_process_host.h"
#include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include "content/browser/trace_message_filter.h" #include "content/browser/trace_message_filter.h"
#include "content/common/plugin_messages.h" #include "content/common/plugin_messages.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
...@@ -38,36 +40,27 @@ typedef std::list<BrowserChildProcessHost*> ChildProcessList; ...@@ -38,36 +40,27 @@ typedef std::list<BrowserChildProcessHost*> ChildProcessList;
static base::LazyInstance<ChildProcessList> g_child_process_list = static base::LazyInstance<ChildProcessList> g_child_process_list =
LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
// The NotificationTask is used to notify about plugin process connection/ // Helper functions since the child process related notifications happen on the
// disconnection. It is needed because the notifications in the // UI thread.
// NotificationService must happen in the main thread. void ChildNotificationHelper(int notification_type,
class ChildNotificationTask : public Task { content::ChildProcessData data) {
public: content::NotificationService::current()->
ChildNotificationTask( Notify(notification_type, content::NotificationService::AllSources(),
int notification_type, ChildProcessInfo* info) content::Details<content::ChildProcessData>(&data));
: notification_type_(notification_type), info_(*info) { } }
virtual void Run() {
content::NotificationService::current()->
Notify(notification_type_, content::NotificationService::AllSources(),
content::Details<ChildProcessInfo>(&info_));
}
private:
int notification_type_;
ChildProcessInfo info_;
};
} // namespace } // namespace
BrowserChildProcessHost::BrowserChildProcessHost( BrowserChildProcessHost::BrowserChildProcessHost(
content::ProcessType type) content::ProcessType type)
: ChildProcessInfo(type, -1), : ALLOW_THIS_IN_INITIALIZER_LIST(client_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(client_(this)),
#if !defined(OS_WIN) #if !defined(OS_WIN)
ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
#endif #endif
disconnect_was_alive_(false) { disconnect_was_alive_(false) {
data_.type = type;
data_.id = GenerateChildProcessUniqueId();
AddFilter(new TraceMessageFilter); AddFilter(new TraceMessageFilter);
AddFilter(new ProfilerMessageFilter); AddFilter(new ProfilerMessageFilter);
...@@ -129,7 +122,9 @@ void BrowserChildProcessHost::SetTerminateChildOnShutdown( ...@@ -129,7 +122,9 @@ void BrowserChildProcessHost::SetTerminateChildOnShutdown(
void BrowserChildProcessHost::Notify(int type) { void BrowserChildProcessHost::Notify(int type) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, new ChildNotificationTask(type, this)); BrowserThread::UI,
FROM_HERE,
base::Bind(&ChildNotificationHelper, type, data_));
} }
base::TerminationStatus BrowserChildProcessHost::GetChildTerminationStatus( base::TerminationStatus BrowserChildProcessHost::GetChildTerminationStatus(
...@@ -251,21 +246,21 @@ void BrowserChildProcessHost::ClientHook::OnProcessLaunched() { ...@@ -251,21 +246,21 @@ void BrowserChildProcessHost::ClientHook::OnProcessLaunched() {
host_->OnChildDied(); host_->OnChildDied();
return; return;
} }
host_->set_handle(host_->child_process_->GetHandle()); host_->data_.handle = host_->child_process_->GetHandle();
host_->OnProcessLaunched(); host_->OnProcessLaunched();
} }
BrowserChildProcessHost::Iterator::Iterator() BrowserChildProcessHost::Iterator::Iterator()
: all_(true), type_(content::PROCESS_TYPE_UNKNOWN) { : all_(true), type_(content::PROCESS_TYPE_UNKNOWN) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) <<
"ChildProcessInfo::Iterator must be used on the IO thread."; "BrowserChildProcessHost::Iterator must be used on the IO thread.";
iterator_ = g_child_process_list.Get().begin(); iterator_ = g_child_process_list.Get().begin();
} }
BrowserChildProcessHost::Iterator::Iterator(content::ProcessType type) BrowserChildProcessHost::Iterator::Iterator(content::ProcessType type)
: all_(false), type_(type) { : all_(false), type_(type) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) <<
"ChildProcessInfo::Iterator must be used on the IO thread."; "BrowserChildProcessHost::Iterator must be used on the IO thread.";
iterator_ = g_child_process_list.Get().begin(); iterator_ = g_child_process_list.Get().begin();
if (!Done() && (*iterator_)->type() != type_) if (!Done() && (*iterator_)->type() != type_)
++(*this); ++(*this);
......
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
#include <list> #include <list>
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/process.h"
#include "base/synchronization/waitable_event_watcher.h" #include "base/synchronization/waitable_event_watcher.h"
#include "content/browser/child_process_launcher.h" #include "content/browser/child_process_launcher.h"
#include "content/common/child_process_host.h" #include "content/common/child_process_host.h"
#include "content/common/child_process_info.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/common/process_type.h" #include "content/public/browser/child_process_data.h"
namespace base { namespace base {
class WaitableEvent; class WaitableEvent;
...@@ -27,7 +27,6 @@ class WaitableEvent; ...@@ -27,7 +27,6 @@ class WaitableEvent;
// this class. That project lives on the UI thread. // this class. That project lives on the UI thread.
class CONTENT_EXPORT BrowserChildProcessHost : class CONTENT_EXPORT BrowserChildProcessHost :
public ChildProcessHost, public ChildProcessHost,
public ChildProcessInfo,
public ChildProcessLauncher::Client, public ChildProcessLauncher::Client,
public base::WaitableEventWatcher::Delegate { public base::WaitableEventWatcher::Delegate {
public: public:
...@@ -59,6 +58,12 @@ class CONTENT_EXPORT BrowserChildProcessHost : ...@@ -59,6 +58,12 @@ class CONTENT_EXPORT BrowserChildProcessHost :
std::list<BrowserChildProcessHost*>::iterator iterator_; std::list<BrowserChildProcessHost*>::iterator iterator_;
}; };
const content::ChildProcessData& data() const { return data_; }
content::ProcessType type() const { return data_.type; }
const string16& name() const { return data_.name; }
base::ProcessHandle handle() const { return data_.handle; }
int id() const { return data_.id; }
protected: protected:
explicit BrowserChildProcessHost(content::ProcessType type); explicit BrowserChildProcessHost(content::ProcessType type);
...@@ -112,6 +117,9 @@ class CONTENT_EXPORT BrowserChildProcessHost : ...@@ -112,6 +117,9 @@ class CONTENT_EXPORT BrowserChildProcessHost :
// Sends the given notification on the UI thread. // Sends the given notification on the UI thread.
void Notify(int type); void Notify(int type);
void set_name(const string16& name) { data_.name = name; }
void set_handle(base::ProcessHandle handle) { data_.handle = handle; }
private: private:
// By using an internal class as the ChildProcessLauncher::Client, we can // By using an internal class as the ChildProcessLauncher::Client, we can
// intercept OnProcessLaunched and do our own processing before // intercept OnProcessLaunched and do our own processing before
...@@ -124,6 +132,8 @@ class CONTENT_EXPORT BrowserChildProcessHost : ...@@ -124,6 +132,8 @@ class CONTENT_EXPORT BrowserChildProcessHost :
BrowserChildProcessHost* host_; BrowserChildProcessHost* host_;
}; };
content::ChildProcessData data_;
ClientHook client_; ClientHook client_;
scoped_ptr<ChildProcessLauncher> child_process_; scoped_ptr<ChildProcessLauncher> child_process_;
#if defined(OS_WIN) #if defined(OS_WIN)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "base/sys_string_conversions.h" #include "base/sys_string_conversions.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/common/child_process_info.h" #include "content/public/browser/child_process_data.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
...@@ -191,7 +191,7 @@ void MachBroker::Observe(int type, ...@@ -191,7 +191,7 @@ void MachBroker::Observe(int type,
break; break;
case content::NOTIFICATION_CHILD_PROCESS_CRASHED: case content::NOTIFICATION_CHILD_PROCESS_CRASHED:
case content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED: case content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED:
handle = content::Details<ChildProcessInfo>(details)->handle(); handle = content::Details<content::ChildProcessData>(details)->handle;
break; break;
default: default:
NOTREACHED() << "Unexpected notification"; NOTREACHED() << "Unexpected notification";
......
...@@ -92,7 +92,7 @@ class PluginDataRemoverImpl::Context ...@@ -92,7 +92,7 @@ class PluginDataRemoverImpl::Context
// PluginProcessHost::Client methods. // PluginProcessHost::Client methods.
virtual int ID() OVERRIDE { virtual int ID() OVERRIDE {
// Generate a unique identifier for this PluginProcessHostClient. // Generate a unique identifier for this PluginProcessHostClient.
return ChildProcessInfo::GenerateChildProcessUniqueId(); return ChildProcessHost::GenerateChildProcessUniqueId();
} }
virtual bool OffTheRecord() OVERRIDE { virtual bool OffTheRecord() OVERRIDE {
......
...@@ -166,7 +166,6 @@ bool PluginProcessHost::Init(const webkit::WebPluginInfo& info, ...@@ -166,7 +166,6 @@ bool PluginProcessHost::Init(const webkit::WebPluginInfo& info,
const std::string& locale) { const std::string& locale) {
info_ = info; info_ = info;
set_name(info_.name); set_name(info_.name);
set_version(info_.version);
if (!CreateChannel()) if (!CreateChannel())
return false; return false;
......
...@@ -101,14 +101,14 @@ PpapiPluginProcessHost::PpapiPluginProcessHost(net::HostResolver* host_resolver) ...@@ -101,14 +101,14 @@ PpapiPluginProcessHost::PpapiPluginProcessHost(net::HostResolver* host_resolver)
filter_(new PepperMessageFilter(host_resolver)), filter_(new PepperMessageFilter(host_resolver)),
network_observer_(new PluginNetworkObserver(this)), network_observer_(new PluginNetworkObserver(this)),
is_broker_(false), is_broker_(false),
process_id_(ChildProcessInfo::GenerateChildProcessUniqueId()) { process_id_(ChildProcessHost::GenerateChildProcessUniqueId()) {
AddFilter(filter_.get()); AddFilter(filter_.get());
} }
PpapiPluginProcessHost::PpapiPluginProcessHost() PpapiPluginProcessHost::PpapiPluginProcessHost()
: BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_BROKER), : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_BROKER),
is_broker_(true), is_broker_(true),
process_id_(ChildProcessInfo::GenerateChildProcessUniqueId()) { process_id_(ChildProcessHost::GenerateChildProcessUniqueId()) {
} }
bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) { bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) {
...@@ -118,7 +118,6 @@ bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) { ...@@ -118,7 +118,6 @@ bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) {
} else { } else {
set_name(UTF8ToUTF16(info.name)); set_name(UTF8ToUTF16(info.name));
} }
set_version(UTF8ToUTF16(info.version));
if (!CreateChannel()) if (!CreateChannel())
return false; return false;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/time.h" #include "base/time.h"
#include "content/browser/child_process_security_policy.h" #include "content/browser/child_process_security_policy.h"
#include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/common/child_process_info.h" #include "content/common/child_process_host.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
...@@ -18,7 +18,7 @@ MockRenderProcessHost::MockRenderProcessHost( ...@@ -18,7 +18,7 @@ MockRenderProcessHost::MockRenderProcessHost(
: transport_dib_(NULL), : transport_dib_(NULL),
bad_msg_count_(0), bad_msg_count_(0),
factory_(NULL), factory_(NULL),
id_(ChildProcessInfo::GenerateChildProcessUniqueId()), id_(ChildProcessHost::GenerateChildProcessUniqueId()),
browser_context_(browser_context), browser_context_(browser_context),
max_page_id_(-1), max_page_id_(-1),
fast_shutdown_started_(false) { fast_shutdown_started_(false) {
......
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
#include "content/browser/user_metrics.h" #include "content/browser/user_metrics.h"
#include "content/browser/webui/web_ui_factory.h" #include "content/browser/webui/web_ui_factory.h"
#include "content/browser/worker_host/worker_message_filter.h" #include "content/browser/worker_host/worker_message_filter.h"
#include "content/common/child_process_info.h" #include "content/common/child_process_host.h"
#include "content/common/child_process_messages.h" #include "content/common/child_process_messages.h"
#include "content/common/gpu/gpu_messages.h" #include "content/common/gpu/gpu_messages.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
...@@ -283,7 +283,7 @@ RenderProcessHostImpl::RenderProcessHostImpl( ...@@ -283,7 +283,7 @@ RenderProcessHostImpl::RenderProcessHostImpl(
this, &RenderProcessHostImpl::ClearTransportDIBCache)), this, &RenderProcessHostImpl::ClearTransportDIBCache)),
accessibility_enabled_(false), accessibility_enabled_(false),
is_initialized_(false), is_initialized_(false),
id_(ChildProcessInfo::GenerateChildProcessUniqueId()), id_(ChildProcessHost::GenerateChildProcessUniqueId()),
browser_context_(browser_context), browser_context_(browser_context),
sudden_termination_allowed_(true), sudden_termination_allowed_(true),
ignore_input_events_(false) { ignore_input_events_(false) {
...@@ -387,7 +387,7 @@ bool RenderProcessHostImpl::Init(bool is_accessibility_enabled) { ...@@ -387,7 +387,7 @@ bool RenderProcessHostImpl::Init(bool is_accessibility_enabled) {
// Setup the IPC channel. // Setup the IPC channel.
const std::string channel_id = const std::string channel_id =
ChildProcessInfo::GenerateRandomChannelID(this); ChildProcessHost::GenerateRandomChannelID(this);
channel_.reset(new IPC::ChannelProxy( channel_.reset(new IPC::ChannelProxy(
channel_id, IPC::Channel::MODE_SERVER, this, channel_id, IPC::Channel::MODE_SERVER, this,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
#include "base/timer.h" #include "base/timer.h"
#include "content/browser/download/download_resource_handler.h" #include "content/browser/download/download_resource_handler.h"
#include "content/browser/renderer_host/resource_queue.h" #include "content/browser/renderer_host/resource_queue.h"
#include "content/common/child_process_info.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "ipc/ipc_message.h" #include "ipc/ipc_message.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "content/browser/renderer_host/resource_handler.h" #include "content/browser/renderer_host/resource_handler.h"
#include "content/browser/renderer_host/resource_message_filter.h" #include "content/browser/renderer_host/resource_message_filter.h"
#include "content/common/child_process_host.h"
#include "content/common/resource_messages.h" #include "content/common/resource_messages.h"
#include "content/common/view_messages.h" #include "content/common/view_messages.h"
#include "content/public/common/resource_response.h" #include "content/public/common/resource_response.h"
...@@ -161,7 +162,7 @@ class ForwardingFilter : public ResourceMessageFilter { ...@@ -161,7 +162,7 @@ class ForwardingFilter : public ResourceMessageFilter {
public: public:
explicit ForwardingFilter(IPC::Message::Sender* dest) explicit ForwardingFilter(IPC::Message::Sender* dest)
: ResourceMessageFilter( : ResourceMessageFilter(
ChildProcessInfo::GenerateChildProcessUniqueId(), ChildProcessHost::GenerateChildProcessUniqueId(),
content::PROCESS_TYPE_RENDERER, content::PROCESS_TYPE_RENDERER,
content::MockResourceContext::GetInstance(), content::MockResourceContext::GetInstance(),
new MockURLRequestContextSelector( new MockURLRequestContextSelector(
......
...@@ -4,14 +4,18 @@ ...@@ -4,14 +4,18 @@
#include "content/common/child_process_host.h" #include "content/common/child_process_host.h"
#include <limits>
#include "base/atomicops.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/process_util.h" #include "base/process_util.h"
#include "base/rand_util.h"
#include "base/stringprintf.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.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/child_process_messages.h"
#include "content/public/common/content_paths.h" #include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
...@@ -141,7 +145,7 @@ void ChildProcessHost::ForceShutdown() { ...@@ -141,7 +145,7 @@ void ChildProcessHost::ForceShutdown() {
} }
bool ChildProcessHost::CreateChannel() { bool ChildProcessHost::CreateChannel() {
channel_id_ = ChildProcessInfo::GenerateRandomChannelID(this); channel_id_ = GenerateRandomChannelID(this);
channel_.reset(new IPC::Channel( channel_.reset(new IPC::Channel(
channel_id_, IPC::Channel::MODE_SERVER, &listener_)); channel_id_, IPC::Channel::MODE_SERVER, &listener_));
if (!channel_->Connect()) if (!channel_->Connect())
...@@ -193,6 +197,25 @@ void ChildProcessHost::OnAllocateSharedMemory( ...@@ -193,6 +197,25 @@ void ChildProcessHost::OnAllocateSharedMemory(
shared_buf.GiveToProcess(child_process_handle, shared_memory_handle); shared_buf.GiveToProcess(child_process_handle, shared_memory_handle);
} }
std::string ChildProcessHost::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()));
}
int ChildProcessHost::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);
}
void ChildProcessHost::OnChildDied() { void ChildProcessHost::OnChildDied() {
delete this; delete this;
} }
......
...@@ -91,6 +91,19 @@ class CONTENT_EXPORT ChildProcessHost : public IPC::Channel::Listener, ...@@ -91,6 +91,19 @@ class CONTENT_EXPORT ChildProcessHost : public IPC::Channel::Listener,
uint32 buffer_size, base::ProcessHandle child_process, uint32 buffer_size, base::ProcessHandle child_process,
base::SharedMemoryHandle* handle); base::SharedMemoryHandle* handle);
// Generates a unique channel name for a child 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: protected:
ChildProcessHost(); ChildProcessHost();
......
// 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/stringprintf.h"
#include "base/utf_string_conversions.h"
ChildProcessInfo::ChildProcessInfo(content::ProcessType type, int id) :
type_(type) {
if (id == -1)
id_ = GenerateChildProcessUniqueId();
else
id_ = id;
}
ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original)
: type_(original.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_;
name_ = original.name_;
version_ = original.version_;
id_ = original.id_;
process_ = original.process_;
}
return *this;
}
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);
}
// 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"
#include "content/common/content_export.h"
#include "content/public/common/process_type.h"
// Holds information about a child process.
class CONTENT_EXPORT ChildProcessInfo {
public:
ChildProcessInfo(const ChildProcessInfo& original);
virtual ~ChildProcessInfo();
ChildProcessInfo& operator=(const ChildProcessInfo& original);
// Returns the type of the process.
content::ProcessType type() const { return 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.
const string16& name() const { return name_; }
// Returns the version of the exe, this only applies to plugins. Otherwise
// the string is empty.
const string16& 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); }
// 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(content::ProcessType type, int id);
void set_type(content::ProcessType type) { type_ = type; }
void set_name(const string16& name) { name_ = name; }
void set_version(const string16& ver) { version_ = ver; }
void set_handle(base::ProcessHandle handle) { process_.set_handle(handle); }
private:
content::ProcessType type_;
string16 name_;
string16 version_;
int id_;
// The handle to the process.
mutable base::Process process_;
};
#endif // CONTENT_COMMON_CHILD_PROCESS_INFO_H_
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
'public/browser/browser_shutdown.h', 'public/browser/browser_shutdown.h',
'public/browser/browser_thread.h', 'public/browser/browser_thread.h',
'public/browser/browser_thread_delegate.h', 'public/browser/browser_thread_delegate.h',
'public/browser/child_process_data.h',
'public/browser/content_browser_client.h', 'public/browser/content_browser_client.h',
'public/browser/content_ipc_logging.h', 'public/browser/content_ipc_logging.h',
'public/browser/devtools_agent_host_registry.h', 'public/browser/devtools_agent_host_registry.h',
......
...@@ -83,8 +83,6 @@ ...@@ -83,8 +83,6 @@
'common/child_process.h', 'common/child_process.h',
'common/child_process_host.cc', 'common/child_process_host.cc',
'common/child_process_host.h', 'common/child_process_host.h',
'common/child_process_info.cc',
'common/child_process_info.h',
'common/child_process_messages.h', 'common/child_process_messages.h',
'common/child_process_sandbox_support_impl_linux.cc', 'common/child_process_sandbox_support_impl_linux.cc',
'common/child_process_sandbox_support_impl_linux.h', 'common/child_process_sandbox_support_impl_linux.h',
......
// 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_PUBLIC_CHILD_PROCESS_DATA_H_
#define CONTENT_PUBLIC_CHILD_PROCESS_DATA_H_
#pragma once
#include "base/process.h"
#include "base/string16.h"
#include "content/common/content_export.h"
#include "content/public/common/process_type.h"
namespace content {
// Holds information about a child process.
struct ChildProcessData {
// The type of the process.
content::ProcessType type;
// The name of the process. i.e. for plugins it might be Flash, while for
// for workers it might be the domain that it's from.
string16 name;
// 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;
// The handle to the process.
base::ProcessHandle handle;
ChildProcessData() : id(0), handle(base::kNullProcessHandle) {}
};
} // namespace content
#endif // CONTENT_PUBLIC_CHILD_PROCESS_DATA_H_
...@@ -375,27 +375,27 @@ enum NotificationType { ...@@ -375,27 +375,27 @@ enum NotificationType {
// This notification is sent when a child process host has connected to a // This notification is sent when a child process host has connected to a
// child process. There is no usable source, since it is sent from an // child process. There is no usable source, since it is sent from an
// ephemeral task; register for AllSources() to receive this notification. // ephemeral task; register for AllSources() to receive this notification.
// The details are in a Details<ChildProcessInfo>. // The details are in a Details<content::ChildProcessData>.
NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED,
// This message is sent after a ChildProcessHost is disconnected from the // This message is sent after a ChildProcessHost is disconnected from the
// child process. There is no usable source, since it is sent from an // child process. There is no usable source, since it is sent from an
// ephemeral task; register for AllSources() to receive this notification. // ephemeral task; register for AllSources() to receive this notification.
// The details are in a Details<ChildProcessInfo>. // The details are in a Details<content::ChildProcessData>.
NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED, NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED,
// This message is sent when a child process disappears // This message is sent when a child process disappears
// unexpectedly as a result of a crash. There is no usable // unexpectedly as a result of a crash. There is no usable
// source, since it is sent from an ephemeral task; register for // source, since it is sent from an ephemeral task; register for
// AllSources() to receive this notification. The details are in // AllSources() to receive this notification. The details are in
// a Details<ChildProcessInfo>. // a Details<content::ChildProcessData>.
NOTIFICATION_CHILD_PROCESS_CRASHED, NOTIFICATION_CHILD_PROCESS_CRASHED,
// This message is sent when a child process disappears // This message is sent when a child process disappears
// unexpectedly as a result of a termination signal. There is no // unexpectedly as a result of a termination signal. There is no
// usable source, since it is sent from an ephemeral task; // usable source, since it is sent from an ephemeral task;
// register for AllSources() to receive this notification. The // register for AllSources() to receive this notification. The
// details are in a Details<ChildProcessInfo>. // details are in a Details<content::ChildProcessData>.
NOTIFICATION_CHILD_PROCESS_WAS_KILLED, NOTIFICATION_CHILD_PROCESS_WAS_KILLED,
// This message indicates that an instance of a particular child was // This message indicates that an instance of a particular child was
...@@ -405,7 +405,7 @@ enum NotificationType { ...@@ -405,7 +405,7 @@ enum NotificationType {
// //
// There is no usable source, since it is sent from an ephemeral task; // There is no usable source, since it is sent from an ephemeral task;
// register for AllSources() to receive this notification. The details are // register for AllSources() to receive this notification. The details are
// in a Details<ChildProcessInfo>. // in a Details<content::ChildProcessData>.
NOTIFICATION_CHILD_INSTANCE_CREATED, NOTIFICATION_CHILD_INSTANCE_CREATED,
// Saved Pages ------------------------------------------------------------- // Saved Pages -------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment