diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 01:57:53 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-02 01:57:53 +0000 |
commit | 4306c379b6950cd71d016d345beedc5884158af4 (patch) | |
tree | c99e60d36cb4f55469667b9855b91398e991d22d | |
parent | 5aa9c09bfbe70e1e87642c2333e54cffaa71838c (diff) | |
download | chromium_src-4306c379b6950cd71d016d345beedc5884158af4.zip chromium_src-4306c379b6950cd71d016d345beedc5884158af4.tar.gz chromium_src-4306c379b6950cd71d016d345beedc5884158af4.tar.bz2 |
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
24 files changed, 185 insertions, 263 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index ab9e5cf..3f9c93a 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -2723,11 +2723,11 @@ void GetChildProcessHostInfo(ListValue* child_processes) { // since we need their handle. if ((*iter)->handle() == base::kNullProcessHandle) continue; - ChildProcessInfo* info = *iter; DictionaryValue* item = new DictionaryValue; - item->SetString("name", info->name()); - item->SetString("type", content::GetProcessTypeNameInEnglish(info->type())); - item->SetInteger("pid", base::GetProcId(info->handle())); + item->SetString("name", iter->name()); + item->SetString("type", + content::GetProcessTypeNameInEnglish(iter->type())); + item->SetInteger("pid", base::GetProcId(iter->handle())); child_processes->Append(item); } } diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index 51afe17..54519dd 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -1339,13 +1339,13 @@ void MetricsService::LogChildProcessChange( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - content::Details<ChildProcessInfo> child_details(details); - const string16& child_name = child_details->name(); + content::Details<content::ChildProcessData> child_details(details); + const string16& child_name = child_details->name; if (child_process_stats_buffer_.find(child_name) == child_process_stats_buffer_.end()) { child_process_stats_buffer_[child_name] = - ChildProcessStats(child_details->type()); + ChildProcessStats(child_details->type); } ChildProcessStats& stats = child_process_stats_buffer_[child_name]; @@ -1362,7 +1362,7 @@ void MetricsService::LogChildProcessChange( stats.process_crashes++; // Exclude plugin crashes from the count below because we report them via // a separate UMA metric. - if (!IsPluginProcess(child_details->type())) { + if (!IsPluginProcess(child_details->type)) { IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); } break; diff --git a/chrome/browser/task_manager/task_manager_resource_providers.cc b/chrome/browser/task_manager/task_manager_resource_providers.cc index 8e1cc11..7b3658f 100644 --- a/chrome/browser/task_manager/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager/task_manager_resource_providers.cc @@ -787,7 +787,7 @@ base::ProcessHandle TaskManagerChildProcessResource::GetProcess() 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. switch (type_) { case content::PROCESS_TYPE_PLUGIN: @@ -924,7 +924,7 @@ void TaskManagerChildProcessResourceProvider::StartUpdating() { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::Bind( - &TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo, + &TaskManagerChildProcessResourceProvider::RetrieveChildProcessData, this)); } @@ -952,11 +952,8 @@ void TaskManagerChildProcessResourceProvider::Observe( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - content::Details<ChildProcessInfo> child_details(details); - ChildProcessData data; - data.type = child_details->type(); - data.name = child_details->name(); - data.handle = child_details->handle(); + content::ChildProcessData data = + *content::Details<content::ChildProcessData>(details).ptr(); switch (type) { case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: Add(data); @@ -971,7 +968,7 @@ void TaskManagerChildProcessResourceProvider::Observe( } void TaskManagerChildProcessResourceProvider::Add( - const ChildProcessData& child_process_data) { + const content::ChildProcessData& child_process_data) { if (!updating_) return; // Workers are handled by TaskManagerWorkerResourceProvider. @@ -988,14 +985,14 @@ void TaskManagerChildProcessResourceProvider::Add( } void TaskManagerChildProcessResourceProvider::Remove( - const ChildProcessData& child_process_data) { + const content::ChildProcessData& child_process_data) { if (!updating_) return; if (child_process_data.type == content::PROCESS_TYPE_WORKER) return; ChildProcessMap::iterator iter = resources_.find(child_process_data.handle); 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 // closed before the task manager was shown and destroyed after that). return; @@ -1017,7 +1014,7 @@ void TaskManagerChildProcessResourceProvider::Remove( } void TaskManagerChildProcessResourceProvider::AddToTaskManager( - const ChildProcessData& child_process_data) { + const content::ChildProcessData& child_process_data) { TaskManagerChildProcessResource* resource = new TaskManagerChildProcessResource( child_process_data.type, @@ -1028,14 +1025,14 @@ void TaskManagerChildProcessResourceProvider::AddToTaskManager( task_manager_->AddResource(resource); } -// The ChildProcessInfo::Iterator has to be used from the IO thread. -void TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo() { - std::vector<ChildProcessData> child_processes; +// The ChildProcessData::Iterator has to be used from the IO thread. +void TaskManagerChildProcessResourceProvider::RetrieveChildProcessData() { + std::vector<content::ChildProcessData> child_processes; for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { // Only add processes which are already started, since we need their handle. if ((*iter)->handle() == base::kNullProcessHandle) continue; - ChildProcessData data; + content::ChildProcessData data; data.type = (*iter)->type(); data.name = (*iter)->name(); data.handle = (*iter)->handle(); @@ -1046,13 +1043,13 @@ void TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo() { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind( - &TaskManagerChildProcessResourceProvider::ChildProcessInfoRetreived, + &TaskManagerChildProcessResourceProvider::ChildProcessDataRetreived, this, child_processes)); } // This is called on the UI thread. -void TaskManagerChildProcessResourceProvider::ChildProcessInfoRetreived( - const std::vector<ChildProcessData>& child_processes) { +void TaskManagerChildProcessResourceProvider::ChildProcessDataRetreived( + const std::vector<content::ChildProcessData>& child_processes) { for (size_t i = 0; i < child_processes.size(); ++i) Add(child_processes[i]); } diff --git a/chrome/browser/task_manager/task_manager_resource_providers.h b/chrome/browser/task_manager/task_manager_resource_providers.h index fea7e64..6999afb 100644 --- a/chrome/browser/task_manager/task_manager_resource_providers.h +++ b/chrome/browser/task_manager/task_manager_resource_providers.h @@ -13,6 +13,7 @@ #include "base/compiler_specific.h" #include "base/process_util.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_registrar.h" #include "content/public/common/process_type.h" @@ -288,27 +289,21 @@ class TaskManagerChildProcessResourceProvider const content::NotificationDetails& details) OVERRIDE; private: - struct ChildProcessData { - content::ProcessType type; - string16 name; - base::ProcessHandle handle; - }; - virtual ~TaskManagerChildProcessResourceProvider(); // Retrieves information about the running ChildProcessHosts (performed in the // IO thread). - virtual void RetrieveChildProcessInfo(); + virtual void RetrieveChildProcessData(); // Notifies the UI thread that the ChildProcessHosts information have been // retrieved. - virtual void ChildProcessInfoRetreived( - const std::vector<ChildProcessData>& child_processes); + virtual void ChildProcessDataRetreived( + const std::vector<content::ChildProcessData>& child_processes); - void Add(const ChildProcessData& child_process_data); - void Remove(const ChildProcessData& child_process_data); + void Add(const content::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_; @@ -316,7 +311,7 @@ class TaskManagerChildProcessResourceProvider // notifications sent after StopUpdating(). bool updating_; - // Maps the actual resources (the ChildProcessInfo) to the Task Manager + // Maps the actual resources (the ChildProcessData) to the Task Manager // resources. typedef std::map<base::ProcessHandle, TaskManagerChildProcessResource*> ChildProcessMap; diff --git a/chrome/browser/task_manager/task_manager_worker_resource_provider.cc b/chrome/browser/task_manager/task_manager_worker_resource_provider.cc index 734da89..5331486 100644 --- a/chrome/browser/task_manager/task_manager_worker_resource_provider.cc +++ b/chrome/browser/task_manager/task_manager_worker_resource_provider.cc @@ -16,10 +16,10 @@ #include "content/browser/worker_host/worker_service.h" #include "content/browser/worker_host/worker_service_observer.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/notification_service.h" #include "content/public/browser/notification_types.h" -#include "content/public/common/process_type.h" #include "grit/generated_resources.h" #include "grit/theme_resources_standard.h" #include "ui/base/l10n/l10n_util.h" @@ -34,15 +34,15 @@ using content::DevToolsAgentHostRegistry; // only on the UI thread. Destructor may be called on any thread. class TaskManagerSharedWorkerResource : public TaskManager::Resource { public: - TaskManagerSharedWorkerResource(const ChildProcessInfo& process_info, + TaskManagerSharedWorkerResource(const content::ChildProcessData& process_data, int routing_id, const GURL& url, const string16& name); virtual ~TaskManagerSharedWorkerResource(); bool Matches(int process_id, int routing_id) const; - void UpdateProcessInfo(const ChildProcessInfo& process_info); - const ChildProcessInfo& process_info() { return process_info_; } + void UpdateProcessData(const content::ChildProcessData& process_data); + const content::ChildProcessData& process_data() { return process_data_; } private: // TaskManager::Resource methods: @@ -57,7 +57,7 @@ class TaskManagerSharedWorkerResource : public TaskManager::Resource { virtual bool SupportNetworkUsage() const OVERRIDE; virtual void SetSupportNetworkUsage() OVERRIDE; - ChildProcessInfo process_info_; + content::ChildProcessData process_data_; int routing_id_; string16 title_; @@ -69,11 +69,11 @@ class TaskManagerSharedWorkerResource : public TaskManager::Resource { SkBitmap* TaskManagerSharedWorkerResource::default_icon_ = NULL; TaskManagerSharedWorkerResource::TaskManagerSharedWorkerResource( - const ChildProcessInfo& process_info, + const content::ChildProcessData& process_data, int routing_id, const GURL& url, const string16& name) - : process_info_(process_info), + : process_data_(process_data), routing_id_(routing_id) { title_ = UTF8ToUTF16(url.spec()); if (!name.empty()) @@ -85,12 +85,12 @@ TaskManagerSharedWorkerResource::~TaskManagerSharedWorkerResource() { bool TaskManagerSharedWorkerResource::Matches(int process_id, 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( - const ChildProcessInfo& process_info) { - process_info_ = process_info; +void TaskManagerSharedWorkerResource::UpdateProcessData( + const content::ChildProcessData& process_data) { + process_data_ = process_data; } string16 TaskManagerSharedWorkerResource::GetTitle() const { @@ -111,7 +111,7 @@ SkBitmap TaskManagerSharedWorkerResource::GetIcon() const { } base::ProcessHandle TaskManagerSharedWorkerResource::GetProcess() const { - return process_info_.handle(); + return process_data_.handle; } TaskManager::Resource::Type TaskManagerSharedWorkerResource::GetType() const { @@ -130,7 +130,7 @@ void TaskManagerSharedWorkerResource::Inspect() const { return; DevToolsAgentHost* agent_host = DevToolsAgentHostRegistry::GetDevToolsAgentHostForWorker( - process_info_.id(), + process_data_.id, routing_id_); DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); } @@ -217,7 +217,8 @@ void TaskManagerWorkerResourceProvider::WorkerCreated( WorkerProcessHost* process, const WorkerProcessHost::WorkerInstance& instance) { TaskManagerSharedWorkerResource* resource = - new TaskManagerSharedWorkerResource(*process, instance.worker_route_id(), + new TaskManagerSharedWorkerResource(process->data(), + instance.worker_route_id(), instance.url(), instance.name()); BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, @@ -238,19 +239,19 @@ void TaskManagerWorkerResourceProvider::Observe( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - ChildProcessInfo* process_info = - content::Details<ChildProcessInfo>(details).ptr(); - if (process_info->type() != content::PROCESS_TYPE_WORKER) + content::ChildProcessData* process_data = + content::Details<content::ChildProcessData>(details).ptr(); + if (process_data->type != content::PROCESS_TYPE_WORKER) return; if (type == content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED) { ProcessIdToWorkerResources::iterator it = - launching_workers_.find(process_info->id()); + launching_workers_.find(process_data->id); if (it == launching_workers_.end()) return; WorkerResourceList& resources = it->second; for (WorkerResourceList::iterator r = resources.begin(); r !=resources.end(); ++r) { - (*r)->UpdateProcessInfo(*process_info); + (*r)->UpdateProcessData(*process_data); task_manager_->AddResource(*r); } launching_workers_.erase(it); @@ -261,7 +262,7 @@ void TaskManagerWorkerResourceProvider::Observe( // workers here when the worker process has been destroyed. for (WorkerResourceList::iterator it = resources_.begin(); it !=resources_.end();) { - if ((*it)->process_info().id() == process_info->id()) { + if ((*it)->process_data().id == process_data->id) { task_manager_->RemoveResource(*it); delete *it; it = resources_.erase(it); @@ -269,7 +270,7 @@ void TaskManagerWorkerResourceProvider::Observe( ++it; } } - DCHECK(launching_workers_.find(process_info->id()) == + DCHECK(launching_workers_.find(process_data->id) == launching_workers_.end()); } } @@ -309,7 +310,7 @@ void TaskManagerWorkerResourceProvider::StartObservingWorkers() { for (WorkerProcessHost::Instances::const_iterator i = instances.begin(); i != instances.end(); ++i) { 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( TaskManagerSharedWorkerResource* resource) { DCHECK(updating_); resources_.push_back(resource); - if (resource->process_info().handle() == base::kNullProcessHandle) { - int process_id = resource->process_info().id(); + if (resource->process_data().handle == base::kNullProcessHandle) { + int process_id = resource->process_data().id; launching_workers_[process_id].push_back(resource); } else { task_manager_->AddResource(resource); diff --git a/chrome/browser/ui/webui/workers_ui.cc b/chrome/browser/ui/webui/workers_ui.cc index 521740f..0adb0f1 100644 --- a/chrome/browser/ui/webui/workers_ui.cc +++ b/chrome/browser/ui/webui/workers_ui.cc @@ -52,7 +52,7 @@ DictionaryValue* BuildWorkerData( worker_data->SetInteger(kWorkerRouteIdField, instance.worker_route_id()); worker_data->SetString(kUrlField, instance.url().spec()); worker_data->SetString(kNameField, instance.name()); - worker_data->SetInteger(kPidField, process->pid()); + worker_data->SetInteger(kPidField, base::GetProcId(process->handle())); return worker_data; } diff --git a/content/browser/browser_child_process_host.cc b/content/browser/browser_child_process_host.cc index 09b77ee..fa63338 100644 --- a/content/browser/browser_child_process_host.cc +++ b/content/browser/browser_child_process_host.cc @@ -4,6 +4,7 @@ #include "content/browser/browser_child_process_host.h" +#include "base/bind.h" #include "base/command_line.h" #include "base/file_path.h" #include "base/lazy_instance.h" @@ -18,6 +19,7 @@ #include "content/browser/trace_message_filter.h" #include "content/common/plugin_messages.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/notification_service.h" #include "content/public/browser/notification_types.h" @@ -38,36 +40,27 @@ typedef std::list<BrowserChildProcessHost*> ChildProcessList; static base::LazyInstance<ChildProcessList> g_child_process_list = LAZY_INSTANCE_INITIALIZER; -// 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( - int notification_type, ChildProcessInfo* info) - : 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_; -}; +// Helper functions since the child process related notifications happen on the +// UI thread. +void ChildNotificationHelper(int notification_type, + content::ChildProcessData data) { + content::NotificationService::current()-> + Notify(notification_type, content::NotificationService::AllSources(), + content::Details<content::ChildProcessData>(&data)); +} } // namespace BrowserChildProcessHost::BrowserChildProcessHost( content::ProcessType type) - : ChildProcessInfo(type, -1), - ALLOW_THIS_IN_INITIALIZER_LIST(client_(this)), + : ALLOW_THIS_IN_INITIALIZER_LIST(client_(this)), #if !defined(OS_WIN) ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), #endif disconnect_was_alive_(false) { + data_.type = type; + data_.id = GenerateChildProcessUniqueId(); + AddFilter(new TraceMessageFilter); AddFilter(new ProfilerMessageFilter); @@ -129,7 +122,9 @@ void BrowserChildProcessHost::SetTerminateChildOnShutdown( void BrowserChildProcessHost::Notify(int type) { BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, new ChildNotificationTask(type, this)); + BrowserThread::UI, + FROM_HERE, + base::Bind(&ChildNotificationHelper, type, data_)); } base::TerminationStatus BrowserChildProcessHost::GetChildTerminationStatus( @@ -251,21 +246,21 @@ void BrowserChildProcessHost::ClientHook::OnProcessLaunched() { host_->OnChildDied(); return; } - host_->set_handle(host_->child_process_->GetHandle()); + host_->data_.handle = host_->child_process_->GetHandle(); host_->OnProcessLaunched(); } BrowserChildProcessHost::Iterator::Iterator() : all_(true), type_(content::PROCESS_TYPE_UNKNOWN) { 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(); } BrowserChildProcessHost::Iterator::Iterator(content::ProcessType type) : all_(false), type_(type) { 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(); if (!Done() && (*iterator_)->type() != type_) ++(*this); diff --git a/content/browser/browser_child_process_host.h b/content/browser/browser_child_process_host.h index f256669..a201c30 100644 --- a/content/browser/browser_child_process_host.h +++ b/content/browser/browser_child_process_host.h @@ -9,12 +9,12 @@ #include <list> #include "base/memory/weak_ptr.h" +#include "base/process.h" #include "base/synchronization/waitable_event_watcher.h" #include "content/browser/child_process_launcher.h" #include "content/common/child_process_host.h" -#include "content/common/child_process_info.h" #include "content/common/content_export.h" -#include "content/public/common/process_type.h" +#include "content/public/browser/child_process_data.h" namespace base { class WaitableEvent; @@ -27,7 +27,6 @@ class WaitableEvent; // this class. That project lives on the UI thread. class CONTENT_EXPORT BrowserChildProcessHost : public ChildProcessHost, - public ChildProcessInfo, public ChildProcessLauncher::Client, public base::WaitableEventWatcher::Delegate { public: @@ -59,6 +58,12 @@ class CONTENT_EXPORT BrowserChildProcessHost : 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: explicit BrowserChildProcessHost(content::ProcessType type); @@ -112,6 +117,9 @@ class CONTENT_EXPORT BrowserChildProcessHost : // Sends the given notification on the UI thread. void Notify(int type); + void set_name(const string16& name) { data_.name = name; } + void set_handle(base::ProcessHandle handle) { data_.handle = handle; } + private: // By using an internal class as the ChildProcessLauncher::Client, we can // intercept OnProcessLaunched and do our own processing before @@ -124,6 +132,8 @@ class CONTENT_EXPORT BrowserChildProcessHost : BrowserChildProcessHost* host_; }; + content::ChildProcessData data_; + ClientHook client_; scoped_ptr<ChildProcessLauncher> child_process_; #if defined(OS_WIN) diff --git a/content/browser/mach_broker_mac.cc b/content/browser/mach_broker_mac.cc index 8dea5f5..01007a0 100644 --- a/content/browser/mach_broker_mac.cc +++ b/content/browser/mach_broker_mac.cc @@ -15,7 +15,7 @@ #include "base/sys_string_conversions.h" #include "base/threading/platform_thread.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/notification_service.h" #include "content/public/browser/notification_types.h" @@ -191,7 +191,7 @@ void MachBroker::Observe(int type, break; case content::NOTIFICATION_CHILD_PROCESS_CRASHED: case content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED: - handle = content::Details<ChildProcessInfo>(details)->handle(); + handle = content::Details<content::ChildProcessData>(details)->handle; break; default: NOTREACHED() << "Unexpected notification"; diff --git a/content/browser/plugin_data_remover_impl.cc b/content/browser/plugin_data_remover_impl.cc index 21a6f9e..da0dbfc 100644 --- a/content/browser/plugin_data_remover_impl.cc +++ b/content/browser/plugin_data_remover_impl.cc @@ -92,7 +92,7 @@ class PluginDataRemoverImpl::Context // PluginProcessHost::Client methods. virtual int ID() OVERRIDE { // Generate a unique identifier for this PluginProcessHostClient. - return ChildProcessInfo::GenerateChildProcessUniqueId(); + return ChildProcessHost::GenerateChildProcessUniqueId(); } virtual bool OffTheRecord() OVERRIDE { diff --git a/content/browser/plugin_process_host.cc b/content/browser/plugin_process_host.cc index afba6ab..91c22c4 100644 --- a/content/browser/plugin_process_host.cc +++ b/content/browser/plugin_process_host.cc @@ -166,7 +166,6 @@ bool PluginProcessHost::Init(const webkit::WebPluginInfo& info, const std::string& locale) { info_ = info; set_name(info_.name); - set_version(info_.version); if (!CreateChannel()) return false; diff --git a/content/browser/ppapi_plugin_process_host.cc b/content/browser/ppapi_plugin_process_host.cc index 6dbd6ad..8b5faef 100644 --- a/content/browser/ppapi_plugin_process_host.cc +++ b/content/browser/ppapi_plugin_process_host.cc @@ -101,14 +101,14 @@ PpapiPluginProcessHost::PpapiPluginProcessHost(net::HostResolver* host_resolver) filter_(new PepperMessageFilter(host_resolver)), network_observer_(new PluginNetworkObserver(this)), is_broker_(false), - process_id_(ChildProcessInfo::GenerateChildProcessUniqueId()) { + process_id_(ChildProcessHost::GenerateChildProcessUniqueId()) { AddFilter(filter_.get()); } PpapiPluginProcessHost::PpapiPluginProcessHost() : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_BROKER), is_broker_(true), - process_id_(ChildProcessInfo::GenerateChildProcessUniqueId()) { + process_id_(ChildProcessHost::GenerateChildProcessUniqueId()) { } bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) { @@ -118,7 +118,6 @@ bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) { } else { set_name(UTF8ToUTF16(info.name)); } - set_version(UTF8ToUTF16(info.version)); if (!CreateChannel()) return false; diff --git a/content/browser/renderer_host/mock_render_process_host.cc b/content/browser/renderer_host/mock_render_process_host.cc index 52dc3cc..bc0d9d8 100644 --- a/content/browser/renderer_host/mock_render_process_host.cc +++ b/content/browser/renderer_host/mock_render_process_host.cc @@ -9,7 +9,7 @@ #include "base/time.h" #include "content/browser/child_process_security_policy.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_types.h" @@ -18,7 +18,7 @@ MockRenderProcessHost::MockRenderProcessHost( : transport_dib_(NULL), bad_msg_count_(0), factory_(NULL), - id_(ChildProcessInfo::GenerateChildProcessUniqueId()), + id_(ChildProcessHost::GenerateChildProcessUniqueId()), browser_context_(browser_context), max_page_id_(-1), fast_shutdown_started_(false) { diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 31f2bf7..e9bf8f0 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -78,7 +78,7 @@ #include "content/browser/user_metrics.h" #include "content/browser/webui/web_ui_factory.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/gpu/gpu_messages.h" #include "content/public/browser/notification_service.h" @@ -283,7 +283,7 @@ RenderProcessHostImpl::RenderProcessHostImpl( this, &RenderProcessHostImpl::ClearTransportDIBCache)), accessibility_enabled_(false), is_initialized_(false), - id_(ChildProcessInfo::GenerateChildProcessUniqueId()), + id_(ChildProcessHost::GenerateChildProcessUniqueId()), browser_context_(browser_context), sudden_termination_allowed_(true), ignore_input_events_(false) { @@ -387,7 +387,7 @@ bool RenderProcessHostImpl::Init(bool is_accessibility_enabled) { // Setup the IPC channel. const std::string channel_id = - ChildProcessInfo::GenerateRandomChannelID(this); + ChildProcessHost::GenerateRandomChannelID(this); channel_.reset(new IPC::ChannelProxy( channel_id, IPC::Channel::MODE_SERVER, this, BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); diff --git a/content/browser/renderer_host/resource_dispatcher_host.h b/content/browser/renderer_host/resource_dispatcher_host.h index f56338f..38cd1eb 100644 --- a/content/browser/renderer_host/resource_dispatcher_host.h +++ b/content/browser/renderer_host/resource_dispatcher_host.h @@ -25,8 +25,8 @@ #include "base/timer.h" #include "content/browser/download/download_resource_handler.h" #include "content/browser/renderer_host/resource_queue.h" -#include "content/common/child_process_info.h" #include "content/common/content_export.h" +#include "content/public/browser/child_process_data.h" #include "content/public/browser/notification_types.h" #include "ipc/ipc_message.h" #include "net/url_request/url_request.h" diff --git a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc index a3c7736..ae610be 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc +++ b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc @@ -21,6 +21,7 @@ #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_message_filter.h" +#include "content/common/child_process_host.h" #include "content/common/resource_messages.h" #include "content/common/view_messages.h" #include "content/public/common/resource_response.h" @@ -161,7 +162,7 @@ class ForwardingFilter : public ResourceMessageFilter { public: explicit ForwardingFilter(IPC::Message::Sender* dest) : ResourceMessageFilter( - ChildProcessInfo::GenerateChildProcessUniqueId(), + ChildProcessHost::GenerateChildProcessUniqueId(), content::PROCESS_TYPE_RENDERER, content::MockResourceContext::GetInstance(), new MockURLRequestContextSelector( diff --git a/content/common/child_process_host.cc b/content/common/child_process_host.cc index 08afafb..fd1de4a 100644 --- a/content/common/child_process_host.cc +++ b/content/common/child_process_host.cc @@ -4,14 +4,18 @@ #include "content/common/child_process_host.h" +#include <limits> + +#include "base/atomicops.h" #include "base/command_line.h" #include "base/file_path.h" #include "base/logging.h" #include "base/metrics/histogram.h" #include "base/path_service.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 "content/common/child_process_info.h" #include "content/common/child_process_messages.h" #include "content/public/common/content_paths.h" #include "content/public/common/content_switches.h" @@ -141,7 +145,7 @@ void ChildProcessHost::ForceShutdown() { } bool ChildProcessHost::CreateChannel() { - channel_id_ = ChildProcessInfo::GenerateRandomChannelID(this); + channel_id_ = GenerateRandomChannelID(this); channel_.reset(new IPC::Channel( channel_id_, IPC::Channel::MODE_SERVER, &listener_)); if (!channel_->Connect()) @@ -193,6 +197,25 @@ void ChildProcessHost::OnAllocateSharedMemory( 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() { delete this; } diff --git a/content/common/child_process_host.h b/content/common/child_process_host.h index eaf09ae..be73fa1 100644 --- a/content/common/child_process_host.h +++ b/content/common/child_process_host.h @@ -91,6 +91,19 @@ class CONTENT_EXPORT ChildProcessHost : public IPC::Channel::Listener, uint32 buffer_size, base::ProcessHandle child_process, 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: ChildProcessHost(); diff --git a/content/common/child_process_info.cc b/content/common/child_process_info.cc deleted file mode 100644 index 3bac3b4..0000000 --- a/content/common/child_process_info.cc +++ /dev/null @@ -1,65 +0,0 @@ -// 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); -} diff --git a/content/common/child_process_info.h b/content/common/child_process_info.h deleted file mode 100644 index 881c0d7..0000000 --- a/content/common/child_process_info.h +++ /dev/null @@ -1,83 +0,0 @@ -// 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_ diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 01ef454..416a8e2 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -28,6 +28,7 @@ 'public/browser/browser_shutdown.h', 'public/browser/browser_thread.h', 'public/browser/browser_thread_delegate.h', + 'public/browser/child_process_data.h', 'public/browser/content_browser_client.h', 'public/browser/content_ipc_logging.h', 'public/browser/devtools_agent_host_registry.h', diff --git a/content/content_common.gypi b/content/content_common.gypi index ad7cf85..b4891f8 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -83,8 +83,6 @@ '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_process_sandbox_support_impl_linux.cc', 'common/child_process_sandbox_support_impl_linux.h', diff --git a/content/public/browser/child_process_data.h b/content/public/browser/child_process_data.h new file mode 100644 index 0000000..46a10ac --- /dev/null +++ b/content/public/browser/child_process_data.h @@ -0,0 +1,38 @@ +// 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_ diff --git a/content/public/browser/notification_types.h b/content/public/browser/notification_types.h index 8acc092..aa29994 100644 --- a/content/public/browser/notification_types.h +++ b/content/public/browser/notification_types.h @@ -375,27 +375,27 @@ enum NotificationType { // 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 // 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, // This message is sent after a ChildProcessHost is disconnected from the // child process. There is no usable source, since it is sent from an // 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, // This message is sent when a child process disappears // unexpectedly as a result of a crash. There is no usable // source, since it is sent from an ephemeral task; register for // AllSources() to receive this notification. The details are in - // a Details<ChildProcessInfo>. + // a Details<content::ChildProcessData>. NOTIFICATION_CHILD_PROCESS_CRASHED, // This message is sent when a child process disappears // unexpectedly as a result of a termination signal. There is no // usable source, since it is sent from an ephemeral task; // 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, // This message indicates that an instance of a particular child was @@ -405,7 +405,7 @@ enum NotificationType { // // There is no usable source, since it is sent from an ephemeral task; // register for AllSources() to receive this notification. The details are - // in a Details<ChildProcessInfo>. + // in a Details<content::ChildProcessData>. NOTIFICATION_CHILD_INSTANCE_CREATED, // Saved Pages ------------------------------------------------------------- |