diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-20 07:51:54 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-20 07:51:54 +0000 |
commit | f177ffd84b0f1b94de05fa0166520783cb5cddb9 (patch) | |
tree | 54f755e0de2d845cd2d8b481f08c528911ce62d2 /content | |
parent | 57c1b56f4ae39e8cb1cd805fb46653423d4e5456 (diff) | |
download | chromium_src-f177ffd84b0f1b94de05fa0166520783cb5cddb9.zip chromium_src-f177ffd84b0f1b94de05fa0166520783cb5cddb9.tar.gz chromium_src-f177ffd84b0f1b94de05fa0166520783cb5cddb9.tar.bz2 |
Revert 118415 - Add a Content API around BrowserChildProcessHost, similar to what was done with ChildProcessHost. Now classes like PluginProcessHost don't derive from it, but instead use composition.
I've also moved the iterator class into its own file in the public directory. Since classes don't derive from BrowserChildProcessHost and so can't static_cast from it, I added a template helper that does this.
BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9150017
TBR=jam@chromium.org
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118420 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
33 files changed, 387 insertions, 677 deletions
diff --git a/content/browser/browser_child_process_host.cc b/content/browser/browser_child_process_host.cc index fee30a2..9bd3b21 100644 --- a/content/browser/browser_child_process_host.cc +++ b/content/browser/browser_child_process_host.cc @@ -20,7 +20,6 @@ #include "content/common/child_process_host_impl.h" #include "content/common/plugin_messages.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/browser_child_process_host_delegate.h" #include "content/public/browser/child_process_data.h" #include "content/public/browser/content_browser_client.h" #include "content/public/browser/notification_service.h" @@ -34,48 +33,31 @@ #include "base/bind.h" #endif -using content::BrowserChildProcessHostDelegate; using content::BrowserThread; -using content::ChildProcessData; using content::ChildProcessHost; using content::ChildProcessHostImpl; namespace { -static base::LazyInstance<BrowserChildProcessHost::BrowserChildProcessList> - g_child_process_list = LAZY_INSTANCE_INITIALIZER; +typedef std::list<BrowserChildProcessHost*> BrowserChildProcessList; +static base::LazyInstance<BrowserChildProcessList> g_child_process_list = + LAZY_INSTANCE_INITIALIZER; // Helper functions since the child process related notifications happen on the // UI thread. void ChildNotificationHelper(int notification_type, - const ChildProcessData& data) { + const content::ChildProcessData& data) { content::NotificationService::current()-> Notify(notification_type, content::NotificationService::AllSources(), - content::Details<const ChildProcessData>(&data)); + content::Details<const content::ChildProcessData>(&data)); } } // namespace -namespace content { - -BrowserChildProcessHost* BrowserChildProcessHost::Create( - ProcessType type, - BrowserChildProcessHostDelegate* delegate) { - return new ::BrowserChildProcessHost(type, delegate); -} - -} // namespace content - -BrowserChildProcessHost::BrowserChildProcessList* - BrowserChildProcessHost::GetIterator() { - return g_child_process_list.Pointer(); -} - BrowserChildProcessHost::BrowserChildProcessHost( - content::ProcessType type, - BrowserChildProcessHostDelegate* delegate) + content::ProcessType type) : data_(type), - delegate_(delegate), + ALLOW_THIS_IN_INITIALIZER_LIST(client_(this)), #if !defined(OS_WIN) ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), #endif @@ -95,7 +77,6 @@ BrowserChildProcessHost::~BrowserChildProcessHost() { // static void BrowserChildProcessHost::TerminateAll() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); // Make a copy since the BrowserChildProcessHost dtor mutates the original // list. BrowserChildProcessList copy = g_child_process_list.Get(); @@ -110,10 +91,9 @@ void BrowserChildProcessHost::Launch( const base::environment_vector& environ, #endif CommandLine* cmd_line) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); content::GetContentClient()->browser()->AppendExtraCommandLineSwitches( - cmd_line, data_.id); + cmd_line, data().id); child_process_.reset(new ChildProcessLauncher( #if defined(OS_WIN) @@ -121,24 +101,13 @@ void BrowserChildProcessHost::Launch( #elif defined(OS_POSIX) use_zygote, environ, - child_process_host_->TakeClientFileDescriptor(), + child_process_host()->TakeClientFileDescriptor(), #endif cmd_line, - this)); + &client_)); } -const ChildProcessData& BrowserChildProcessHost::GetData() const { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - return data_; -} - -ChildProcessHost* BrowserChildProcessHost::GetHost() const { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - return child_process_host_.get(); -} - -base::ProcessHandle BrowserChildProcessHost::GetHandle() const { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); +base::ProcessHandle BrowserChildProcessHost::GetChildProcessHandle() const { DCHECK(child_process_.get()) << "Requesting a child process handle before launching."; DCHECK(child_process_->GetHandle()) @@ -147,24 +116,20 @@ base::ProcessHandle BrowserChildProcessHost::GetHandle() const { } void BrowserChildProcessHost::SetName(const string16& name) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); data_.name = name; } void BrowserChildProcessHost::SetHandle(base::ProcessHandle handle) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); data_.handle = handle; } void BrowserChildProcessHost::ForceShutdown() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); g_child_process_list.Get().remove(this); child_process_host_->ForceShutdown(); } void BrowserChildProcessHost::SetTerminateChildOnShutdown( - bool terminate_on_shutdown) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + bool terminate_on_shutdown) { child_process_->SetTerminateChildOnShutdown(terminate_on_shutdown); } @@ -175,29 +140,23 @@ void BrowserChildProcessHost::Notify(int type) { base::Bind(&ChildNotificationHelper, type, data_)); } -base::TerminationStatus BrowserChildProcessHost::GetTerminationStatus( +base::TerminationStatus BrowserChildProcessHost::GetChildTerminationStatus( int* exit_code) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); if (!child_process_.get()) // If the delegate doesn't use Launch() helper. - return base::GetTerminationStatus(data_.handle, exit_code); + return base::GetTerminationStatus(data().handle, exit_code); return child_process_->GetChildTerminationStatus(exit_code); } bool BrowserChildProcessHost::OnMessageReceived(const IPC::Message& message) { - return delegate_->OnMessageReceived(message); + return false; } void BrowserChildProcessHost::OnChannelConnected(int32 peer_pid) { Notify(content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED); - delegate_->OnChannelConnected(peer_pid); -} - -void BrowserChildProcessHost::OnChannelError() { - delegate_->OnChannelError(); } bool BrowserChildProcessHost::CanShutdown() { - return delegate_->CanShutdown(); + return true; } // Normally a ChildProcessHostDelegate deletes itself from this callback, but at @@ -208,21 +167,21 @@ bool BrowserChildProcessHost::CanShutdown() { // may be called twice: once from the actual channel error and once from // OnWaitableEventSignaled() or the delayed task. void BrowserChildProcessHost::OnChildDisconnected() { - DCHECK(data_.handle != base::kNullProcessHandle); + DCHECK(data().handle != base::kNullProcessHandle); int exit_code; - base::TerminationStatus status = GetTerminationStatus(&exit_code); + base::TerminationStatus status = GetChildTerminationStatus(&exit_code); switch (status) { case base::TERMINATION_STATUS_PROCESS_CRASHED: case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: { - delegate_->OnProcessCrashed(exit_code); + OnProcessCrashed(exit_code); // Report that this child process crashed. Notify(content::NOTIFICATION_CHILD_PROCESS_CRASHED); UMA_HISTOGRAM_ENUMERATION("ChildProcess.Crashed", - data_.type, + data().type, content::PROCESS_TYPE_MAX); if (disconnect_was_alive_) { UMA_HISTOGRAM_ENUMERATION("ChildProcess.CrashedWasAlive", - data_.type, + data().type, content::PROCESS_TYPE_MAX); } break; @@ -230,11 +189,11 @@ void BrowserChildProcessHost::OnChildDisconnected() { case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: { // Report that this child process was killed. UMA_HISTOGRAM_ENUMERATION("ChildProcess.Killed", - data_.type, + data().type, content::PROCESS_TYPE_MAX); if (disconnect_was_alive_) { UMA_HISTOGRAM_ENUMERATION("ChildProcess.KilledWasAlive", - data_.type, + data().type, content::PROCESS_TYPE_MAX); } break; @@ -244,14 +203,14 @@ void BrowserChildProcessHost::OnChildDisconnected() { // code. if (disconnect_was_alive_) { UMA_HISTOGRAM_ENUMERATION("ChildProcess.DisconnectedAlive", - data_.type, + data().type, content::PROCESS_TYPE_MAX); break; } disconnect_was_alive_ = true; #if defined(OS_WIN) child_watcher_.StartWatching( - new base::WaitableEvent(data_.handle), this); + new base::WaitableEvent(data().handle), this); #else // On non-Windows platforms, give the child process some time to die after // disconnecting the channel so that the exit code and termination status @@ -271,7 +230,7 @@ void BrowserChildProcessHost::OnChildDisconnected() { break; } UMA_HISTOGRAM_ENUMERATION("ChildProcess.Disconnected", - data_.type, + data().type, content::PROCESS_TYPE_MAX); // Notify in the main loop of the disconnection. Notify(content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED); @@ -306,12 +265,50 @@ void BrowserChildProcessHost::ShutdownStarted() { g_child_process_list.Get().remove(this); } +BrowserChildProcessHost::ClientHook::ClientHook(BrowserChildProcessHost* host) + : host_(host) { +} -void BrowserChildProcessHost::OnProcessLaunched() { - if (!child_process_->GetHandle()) { - delete this; +void BrowserChildProcessHost::ClientHook::OnProcessLaunched() { + if (!host_->child_process_->GetHandle()) { + delete host_; return; } - data_.handle = child_process_->GetHandle(); - delegate_->OnProcessLaunched(); + host_->data_.handle = host_->child_process_->GetHandle(); + host_->OnProcessLaunched(); +} + +BrowserChildProcessHost::Iterator::Iterator() + : all_(true), type_(content::PROCESS_TYPE_UNKNOWN) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << + "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)) << + "BrowserChildProcessHost::Iterator must be used on the IO thread."; + iterator_ = g_child_process_list.Get().begin(); + if (!Done() && (*iterator_)->data().type != type_) + ++(*this); +} + +BrowserChildProcessHost* BrowserChildProcessHost::Iterator::operator++() { + do { + ++iterator_; + if (Done()) + break; + + if (!all_ && (*iterator_)->data().type != type_) + continue; + + return *iterator_; + } while (true); + + return NULL; +} + +bool BrowserChildProcessHost::Iterator::Done() { + return iterator_ == g_child_process_list.Get().end(); } diff --git a/content/browser/browser_child_process_host.h b/content/browser/browser_child_process_host.h index 45d2a22..3fac085 100644 --- a/content/browser/browser_child_process_host.h +++ b/content/browser/browser_child_process_host.h @@ -14,52 +14,116 @@ #include "base/process.h" #include "base/synchronization/waitable_event_watcher.h" #include "content/browser/child_process_launcher.h" -#include "content/public/browser/browser_child_process_host.h" +#include "content/common/content_export.h" #include "content/public/browser/child_process_data.h" #include "content/public/common/child_process_host_delegate.h" +#include "ipc/ipc_message.h" + +namespace base { +class WaitableEvent; +} namespace content { -class BrowserChildProcessHostIterator; +class ChildProcessHost; } -// Plugins/workers and other child processes that live on the IO thread use this -// class. RenderProcessHostImpl is the main exception that doesn't use this -/// class because it lives on the UI thread. +// Plugins/workers and other child processes that live on the IO thread should +// derive from this class. +// +// [Browser]RenderProcessHost is the main exception that doesn't derive from +// this class. That project lives on the UI thread. class CONTENT_EXPORT BrowserChildProcessHost : - public NON_EXPORTED_BASE(content::BrowserChildProcessHost), public NON_EXPORTED_BASE(content::ChildProcessHostDelegate), public ChildProcessLauncher::Client, - public base::WaitableEventWatcher::Delegate { + public base::WaitableEventWatcher::Delegate, + public IPC::Message::Sender { public: - BrowserChildProcessHost(content::ProcessType type, - content::BrowserChildProcessHostDelegate* delegate); virtual ~BrowserChildProcessHost(); + virtual void OnWaitableEventSignaled( + base::WaitableEvent* waitable_event) OVERRIDE; + // Terminates all child processes and deletes each BrowserChildProcessHost // instance. static void TerminateAll(); - // BrowserChildProcessHost implementation: + // The Iterator class allows iteration through either all child processes, or + // ones of a specific type, depending on which constructor is used. Note that + // this should be done from the IO thread and that the iterator should not be + // kept around as it may be invalidated on subsequent event processing in the + // event loop. + class CONTENT_EXPORT Iterator { + public: + Iterator(); + explicit Iterator(content::ProcessType type); + BrowserChildProcessHost* operator->() { return *iterator_; } + BrowserChildProcessHost* operator*() { return *iterator_; } + BrowserChildProcessHost* operator++(); + bool Done(); + + private: + bool all_; + content::ProcessType type_; + std::list<BrowserChildProcessHost*>::iterator iterator_; + }; + + // IPC::Message::Sender override virtual bool Send(IPC::Message* message) OVERRIDE; - virtual void Launch( + + const content::ChildProcessData& data() const { return data_; } + bool disconnect_was_alive() const { return disconnect_was_alive_; } + + protected: + explicit BrowserChildProcessHost(content::ProcessType type); + + // Derived classes call this to launch the child process asynchronously. + void Launch( #if defined(OS_WIN) const FilePath& exposed_dir, #elif defined(OS_POSIX) bool use_zygote, const base::environment_vector& environ, #endif - CommandLine* cmd_line) OVERRIDE; - virtual const content::ChildProcessData& GetData() const OVERRIDE; - virtual content::ChildProcessHost* GetHost() const OVERRIDE; - virtual base::TerminationStatus GetTerminationStatus(int* exit_code) OVERRIDE; - virtual void SetName(const string16& name) OVERRIDE; - virtual void SetHandle(base::ProcessHandle handle) OVERRIDE; + CommandLine* cmd_line); - bool disconnect_was_alive() const { return disconnect_was_alive_; } + // TODO(jam): below is what will be in the BrowserChildProcessHostDelegate + // interface. + + // ChildProcessLauncher::Client implementation. + virtual void OnProcessLaunched() OVERRIDE {} + + // Derived classes can override this to know if the process crashed. + // |exit_code| is the status returned when the process crashed (for + // posix, as returned from waitpid(), for Windows, as returned from + // GetExitCodeProcess()). + virtual void OnProcessCrashed(int exit_code) {} + + // Overrides from ChildProcessHostDelegate + virtual bool CanShutdown() OVERRIDE; + virtual void OnChildDisconnected() OVERRIDE; + virtual void ShutdownStarted() OVERRIDE; + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; + + // Returns the termination status of a child. |exit_code| is the + // status returned when the process exited (for posix, as returned + // from waitpid(), for Windows, as returned from + // GetExitCodeProcess()). |exit_code| may be NULL. + base::TerminationStatus GetChildTerminationStatus(int* exit_code); // Returns the handle of the child process. This can be called only after // OnProcessLaunched is called or it will be invalid and may crash. - base::ProcessHandle GetHandle() const; + base::ProcessHandle GetChildProcessHandle() const; + + // Sets the user-visible name of the process. + void SetName(const string16& name); + + // Set the handle of the process. BrowserChildProcessHost will do this when + // the Launch method is used to start the process. However if the owner + // of this object doesn't call Launch and starts the process in another way, + // they need to call this method so that the process handle is associated with + // this object. + void SetHandle(base::ProcessHandle handle); // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown void ForceShutdown(); @@ -71,35 +135,26 @@ class CONTENT_EXPORT BrowserChildProcessHost : // Sends the given notification on the UI thread. void Notify(int type); - content::BrowserChildProcessHostDelegate* delegate() const { - return delegate_; + content::ChildProcessHost* child_process_host() const { + return child_process_host_.get(); } - typedef std::list<BrowserChildProcessHost*> BrowserChildProcessList; private: - friend class content::BrowserChildProcessHostIterator; - - static BrowserChildProcessList* GetIterator(); - - // ChildProcessHostDelegate implementation: - virtual bool CanShutdown() OVERRIDE; - virtual void OnChildDisconnected() OVERRIDE; - virtual void ShutdownStarted() OVERRIDE; - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; - virtual void OnChannelError() OVERRIDE; - - // ChildProcessLauncher::Client implementation. - virtual void OnProcessLaunched() OVERRIDE; - - // public base::WaitableEventWatcher::Delegate implementation: - virtual void OnWaitableEventSignaled( - base::WaitableEvent* waitable_event) OVERRIDE; + // By using an internal class as the ChildProcessLauncher::Client, we can + // intercept OnProcessLaunched and do our own processing before + // calling the subclass' implementation. + class ClientHook : public ChildProcessLauncher::Client { + public: + explicit ClientHook(BrowserChildProcessHost* host); + virtual void OnProcessLaunched() OVERRIDE; + private: + BrowserChildProcessHost* host_; + }; content::ChildProcessData data_; - content::BrowserChildProcessHostDelegate* delegate_; scoped_ptr<content::ChildProcessHost> child_process_host_; + ClientHook client_; scoped_ptr<ChildProcessLauncher> child_process_; #if defined(OS_WIN) base::WaitableEventWatcher child_watcher_; diff --git a/content/browser/browser_process_sub_thread.cc b/content/browser/browser_process_sub_thread.cc index 2b42da1..35566f0 100644 --- a/content/browser/browser_process_sub_thread.cc +++ b/content/browser/browser_process_sub_thread.cc @@ -69,7 +69,7 @@ void BrowserProcessSubThread::IOThreadPreCleanUp() { // If any child processes are still running, terminate them and // and delete the BrowserChildProcessHost instances to release whatever // IO thread only resources they are referencing. - ::BrowserChildProcessHost::TerminateAll(); + BrowserChildProcessHost::TerminateAll(); } void BrowserProcessSubThread::IOThreadPostCleanUp() { diff --git a/content/browser/content_ipc_logging.cc b/content/browser/content_ipc_logging.cc index 45b7a2e..4c9e8ea 100644 --- a/content/browser/content_ipc_logging.cc +++ b/content/browser/content_ipc_logging.cc @@ -7,7 +7,6 @@ #include "base/bind.h" #include "content/browser/browser_child_process_host.h" #include "content/common/child_process_messages.h" -#include "content/public/browser/browser_child_process_host_iterator.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_process_host.h" #include "ipc/ipc_logging.h" @@ -19,9 +18,9 @@ namespace content { void EnableIPCLoggingForChildProcesses(bool enabled) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserChildProcessHostIterator i; // default constr references a singleton + BrowserChildProcessHost::Iterator i; // default constr references a singleton while (!i.Done()) { - i.Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); + i->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); ++i; } } diff --git a/content/browser/debugger/worker_devtools_manager.cc b/content/browser/debugger/worker_devtools_manager.cc index 217c946..2405fb7 100644 --- a/content/browser/debugger/worker_devtools_manager.cc +++ b/content/browser/debugger/worker_devtools_manager.cc @@ -15,7 +15,6 @@ #include "content/browser/worker_host/worker_service_impl.h" #include "content/common/devtools_messages.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_observer.h" #include "content/public/browser/notification_registrar.h" @@ -293,7 +292,8 @@ void WorkerDevToolsManager::WorkerCreated( instance.resource_context())) { worker->Send(new DevToolsAgentMsg_PauseWorkerContextOnStart( instance.worker_route_id())); - WorkerId new_worker_id(worker->GetData().id, instance.worker_route_id()); + WorkerId new_worker_id( + worker->data().id, instance.worker_route_id()); paused_workers_[new_worker_id] = it->old_worker_id; terminated_workers_.erase(it); return; @@ -305,12 +305,12 @@ void WorkerDevToolsManager::WorkerDestroyed( WorkerProcessHost* worker, int worker_route_id) { InspectedWorkersList::iterator it = FindInspectedWorker( - worker->GetData().id, + worker->data().id, worker_route_id); if (it == inspected_workers_.end()) return; - WorkerId worker_id(worker->GetData().id, worker_route_id); + WorkerId worker_id(worker->data().id, worker_route_id); terminated_workers_.push_back(TerminatedInspectedWorker( worker_id, it->worker_url, @@ -323,7 +323,7 @@ void WorkerDevToolsManager::WorkerDestroyed( void WorkerDevToolsManager::WorkerContextStarted(WorkerProcessHost* process, int worker_route_id) { - WorkerId new_worker_id(process->GetData().id, worker_route_id); + WorkerId new_worker_id(process->data().id, worker_route_id); PausedWorkers::iterator it = paused_workers_.find(new_worker_id); if (it == paused_workers_.end()) return; @@ -362,7 +362,7 @@ WorkerDevToolsManager::FindInspectedWorker( int host_id, int route_id) { InspectedWorkersList::iterator it = inspected_workers_.begin(); while (it != inspected_workers_.end()) { - if (it->host->GetData().id == host_id && it->route_id == route_id) + if (it->host->data().id == host_id && it->route_id == route_id) break; ++it; } @@ -370,9 +370,10 @@ WorkerDevToolsManager::FindInspectedWorker( } static WorkerProcessHost* FindWorkerProcess(int worker_process_id) { - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { - if (iter.GetData().id == worker_process_id) - return *iter; + BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); + for (; !iter.Done(); ++iter) { + if (iter->data().id == worker_process_id) + return static_cast<WorkerProcessHost*>(*iter); } return NULL; } diff --git a/content/browser/debugger/worker_devtools_manager.h b/content/browser/debugger/worker_devtools_manager.h index d2b2c023..8ee9c1c 100644 --- a/content/browser/debugger/worker_devtools_manager.h +++ b/content/browser/debugger/worker_devtools_manager.h @@ -7,7 +7,6 @@ #pragma once #include <list> -#include <map> #include <string> #include "base/basictypes.h" diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc index 258c12a..1b15780 100644 --- a/content/browser/gpu/gpu_process_host.cc +++ b/content/browser/gpu/gpu_process_host.cc @@ -15,7 +15,6 @@ #include "base/process_util.h" #include "base/string_piece.h" #include "base/threading/thread.h" -#include "content/browser/browser_child_process_host.h" #include "content/browser/gpu/gpu_data_manager.h" #include "content/browser/gpu/gpu_process_host_ui_shim.h" #include "content/browser/renderer_host/render_widget_host.h" @@ -161,13 +160,12 @@ class GpuMainThread : public base::Thread { DISALLOW_COPY_AND_ASSIGN(GpuMainThread); }; -// static -bool GpuProcessHost::HostIsValid(GpuProcessHost* host) { +static bool HostIsValid(GpuProcessHost* host) { if (!host) return false; // Check if the GPU process has died and the host is about to be destroyed. - if (host->process_->disconnect_was_alive()) + if (host->disconnect_was_alive()) return false; // The Gpu process is invalid if it's not using software, the card is @@ -247,7 +245,8 @@ GpuProcessHost* GpuProcessHost::FromID(int host_id) { } GpuProcessHost::GpuProcessHost(int host_id) - : host_id_(host_id), + : BrowserChildProcessHost(content::PROCESS_TYPE_GPU), + host_id_(host_id), gpu_process_(base::kNullProcessHandle), in_process_(false), software_rendering_(false) { @@ -270,8 +269,6 @@ GpuProcessHost::GpuProcessHost(int host_id) BrowserThread::UI, FROM_HERE, base::Bind(base::IgnoreResult(&GpuProcessHostUIShim::Create), host_id)); - - process_.reset(new BrowserChildProcessHost(content::PROCESS_TYPE_GPU, this)); } GpuProcessHost::~GpuProcessHost() { @@ -283,7 +280,7 @@ GpuProcessHost::~GpuProcessHost() { GPU_PROCESS_LIFETIME_EVENT_MAX); int exit_code; - base::TerminationStatus status = process_->GetTerminationStatus(&exit_code); + base::TerminationStatus status = GetChildTerminationStatus(&exit_code); UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessTerminationStatus", status, base::TERMINATION_STATUS_MAX_ENUM); @@ -314,7 +311,7 @@ GpuProcessHost::~GpuProcessHost() { } bool GpuProcessHost::Init() { - std::string channel_id = process_->GetHost()->CreateChannel(); + std::string channel_id = child_process_host()->CreateChannel(); if (channel_id.empty()) return false; @@ -353,12 +350,12 @@ void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { bool GpuProcessHost::Send(IPC::Message* msg) { DCHECK(CalledOnValidThread()); - if (process_->GetHost()->IsChannelOpening()) { + if (child_process_host()->IsChannelOpening()) { queued_messages_.push(msg); return true; } - return process_->Send(msg); + return BrowserChildProcessHost::Send(msg); } bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { @@ -374,6 +371,7 @@ bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { } void GpuProcessHost::OnChannelConnected(int32 peer_pid) { + BrowserChildProcessHost::OnChannelConnected(peer_pid); while (!queued_messages_.empty()) { Send(queued_messages_.front()); queued_messages_.pop(); @@ -491,7 +489,7 @@ void GpuProcessHost::OnProcessLaunched() { // to such requests require that the GPU process handle be known. base::ProcessHandle child_handle = in_process_ ? - base::GetCurrentProcessHandle() : process_->GetData().handle; + base::GetCurrentProcessHandle() : data().handle; #if defined(OS_WIN) DuplicateHandle(base::GetCurrentProcessHandle(), @@ -512,6 +510,7 @@ void GpuProcessHost::OnProcessCrashed(int exit_code) { // The gpu process is too unstable to use. Disable it for current session. gpu_enabled_ = false; } + BrowserChildProcessHost::OnProcessCrashed(exit_code); } bool GpuProcessHost::software_rendering() { @@ -520,7 +519,7 @@ bool GpuProcessHost::software_rendering() { void GpuProcessHost::ForceShutdown() { g_hosts_by_id.Pointer()->Remove(host_id_); - process_->ForceShutdown(); + BrowserChildProcessHost::ForceShutdown(); } bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { @@ -590,7 +589,7 @@ bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { if (!gpu_launcher.empty()) cmd_line->PrependWrapper(gpu_launcher); - process_->Launch( + Launch( #if defined(OS_WIN) FilePath(), #elif defined(OS_POSIX) diff --git a/content/browser/gpu/gpu_process_host.h b/content/browser/gpu/gpu_process_host.h index 51245d7..29ec0df 100644 --- a/content/browser/gpu/gpu_process_host.h +++ b/content/browser/gpu/gpu_process_host.h @@ -11,22 +11,22 @@ #include "base/callback.h" #include "base/memory/linked_ptr.h" -#include "base/process.h" #include "base/threading/non_thread_safe.h" +#include "content/browser/browser_child_process_host.h" #include "content/common/content_export.h" #include "content/common/gpu/gpu_process_launch_causes.h" -#include "content/public/browser/browser_child_process_host_delegate.h" #include "content/public/common/gpu_info.h" -#include "ipc/ipc_message.h" #include "ui/gfx/native_widget_types.h" -class GpuMainThread; struct GPUCreateCommandBufferConfig; -class BrowserChildProcessHost; +namespace IPC { +class Message; +} + +class GpuMainThread; -class GpuProcessHost : public content::BrowserChildProcessHostDelegate, - public IPC::Message::Sender, +class GpuProcessHost : public BrowserChildProcessHost, public base::NonThreadSafe { public: static bool gpu_enabled() { return gpu_enabled_; } @@ -52,9 +52,12 @@ class GpuProcessHost : public content::BrowserChildProcessHostDelegate, static GpuProcessHost* FromID(int host_id); int host_id() const { return host_id_; } - // IPC::Message::Sender implementation: virtual bool Send(IPC::Message* msg) OVERRIDE; + // ChildProcessHost implementation. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; + typedef base::Callback<void(const IPC::ChannelHandle&, base::ProcessHandle, const content::GPUInfo&)> @@ -83,8 +86,6 @@ class GpuProcessHost : public content::BrowserChildProcessHostDelegate, void ForceShutdown(); private: - static bool HostIsValid(GpuProcessHost* host); - GpuProcessHost(int host_id); virtual ~GpuProcessHost(); @@ -93,9 +94,6 @@ class GpuProcessHost : public content::BrowserChildProcessHostDelegate, // Post an IPC message to the UI shim's message handler on the UI thread. void RouteOnUIThread(const IPC::Message& message); - // BrowserChildProcessHostDelegate implementation. - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; virtual void OnProcessLaunched() OVERRIDE; virtual void OnProcessCrashed(int exit_code) OVERRIDE; @@ -157,8 +155,6 @@ class GpuProcessHost : public content::BrowserChildProcessHostDelegate, // existing tabs, just the future ones. CONTENT_EXPORT static bool gpu_enabled_; - scoped_ptr<BrowserChildProcessHost> process_; - DISALLOW_COPY_AND_ASSIGN(GpuProcessHost); }; diff --git a/content/browser/plugin_process_host.cc b/content/browser/plugin_process_host.cc index d15ffbd..cd8fb88 100644 --- a/content/browser/plugin_process_host.cc +++ b/content/browser/plugin_process_host.cc @@ -21,7 +21,6 @@ #include "base/path_service.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "content/browser/browser_child_process_host.h" #include "content/browser/plugin_service_impl.h" #include "content/common/child_process_host_impl.h" #include "content/common/plugin_messages.h" @@ -37,7 +36,6 @@ #include "ui/gfx/native_widget_types.h" using content::BrowserThread; -using content::ChildProcessData; using content::ChildProcessHost; #if defined(USE_X11) @@ -93,7 +91,7 @@ void PluginProcessHost::OnReparentPluginWindow(HWND window, HWND parent) { // Reparent only from the plugin process to our process. DWORD process_id = 0; ::GetWindowThreadProcessId(window, &process_id); - if (process_id != ::GetProcessId(process_->GetHandle())) + if (process_id != ::GetProcessId(GetChildProcessHandle())) return; ::GetWindowThreadProcessId(parent, &process_id); if (process_id != ::GetCurrentProcessId()) @@ -116,12 +114,11 @@ void PluginProcessHost::OnMapNativeViewId(gfx::NativeViewId id, #endif // defined(TOOLKIT_USES_GTK) PluginProcessHost::PluginProcessHost() + : BrowserChildProcessHost(content::PROCESS_TYPE_PLUGIN) #if defined(OS_MACOSX) - : plugin_cursor_visible_(true) + , plugin_cursor_visible_(true) #endif { - process_.reset(new BrowserChildProcessHost( - content::PROCESS_TYPE_PLUGIN, this)); } PluginProcessHost::~PluginProcessHost() { @@ -167,15 +164,11 @@ PluginProcessHost::~PluginProcessHost() { CancelRequests(); } -bool PluginProcessHost::Send(IPC::Message* message) { - return process_->Send(message); -} - bool PluginProcessHost::Init(const webkit::WebPluginInfo& info) { info_ = info; - process_->SetName(info_.name); + SetName(info_.name); - std::string channel_id = process_->GetHost()->CreateChannel(); + std::string channel_id = child_process_host()->CreateChannel(); if (channel_id.empty()) return false; @@ -265,7 +258,7 @@ bool PluginProcessHost::Init(const webkit::WebPluginInfo& info) { #endif #endif - process_->Launch( + Launch( #if defined(OS_WIN) FilePath(), #elif defined(OS_POSIX) @@ -278,7 +271,7 @@ bool PluginProcessHost::Init(const webkit::WebPluginInfo& info) { // called on the plugin. The plugin process exits when it receives the // OnChannelError notification indicating that the browser plugin channel has // been destroyed. - process_->SetTerminateChildOnShutdown(false); + SetTerminateChildOnShutdown(false); content::GetContentClient()->browser()->PluginProcessHostCreated(this); @@ -288,11 +281,11 @@ bool PluginProcessHost::Init(const webkit::WebPluginInfo& info) { void PluginProcessHost::ForceShutdown() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); Send(new PluginProcessMsg_NotifyRenderersOfPendingShutdown()); - process_->ForceShutdown(); + BrowserChildProcessHost::ForceShutdown(); } void PluginProcessHost::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { - process_->GetHost()->AddFilter(filter); + child_process_host()->AddFilter(filter); } bool PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { @@ -327,6 +320,7 @@ bool PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { } void PluginProcessHost::OnChannelConnected(int32 peer_pid) { + BrowserChildProcessHost::OnChannelConnected(peer_pid); for (size_t i = 0; i < pending_requests_.size(); ++i) { RequestPluginChannel(pending_requests_[i]); } @@ -358,8 +352,9 @@ void PluginProcessHost::CancelRequests() { // static void PluginProcessHost::CancelPendingRequestsForResourceContext( const content::ResourceContext* context) { - for (PluginProcessHostIterator host_it; !host_it.Done(); ++host_it) { - PluginProcessHost* host = *host_it; + for (BrowserChildProcessHost::Iterator host_it(content::PROCESS_TYPE_PLUGIN); + !host_it.Done(); ++host_it) { + PluginProcessHost* host = static_cast<PluginProcessHost*>(*host_it); for (size_t i = 0; i < host->pending_requests_.size(); ++i) { if (&host->pending_requests_[i]->GetResourceContext() == context) { host->pending_requests_[i]->OnError(); @@ -371,9 +366,9 @@ void PluginProcessHost::CancelPendingRequestsForResourceContext( } void PluginProcessHost::OpenChannelToPlugin(Client* client) { - process_->Notify(content::NOTIFICATION_CHILD_INSTANCE_CREATED); + Notify(content::NOTIFICATION_CHILD_INSTANCE_CREATED); client->SetPluginInfo(info_); - if (process_->GetHost()->IsChannelOpening()) { + if (child_process_host()->IsChannelOpening()) { // The channel is already in the process of being opened. Put // this "open channel" request into a queue of requests that will // be run once the channel is open. diff --git a/content/browser/plugin_process_host.h b/content/browser/plugin_process_host.h index cc24e5f..2fabe64 100644 --- a/content/browser/plugin_process_host.h +++ b/content/browser/plugin_process_host.h @@ -14,17 +14,13 @@ #include <vector> #include "base/basictypes.h" -#include "base/compiler_specific.h" #include "base/memory/ref_counted.h" +#include "content/browser/browser_child_process_host.h" #include "content/common/content_export.h" -#include "content/public/browser/browser_child_process_host_delegate.h" -#include "content/public/browser/browser_child_process_host_iterator.h" #include "ipc/ipc_channel_proxy.h" #include "webkit/plugins/webplugininfo.h" #include "ui/gfx/native_widget_types.h" -class BrowserChildProcessHost; - namespace content { class ResourceContext; } @@ -45,9 +41,7 @@ struct ChannelHandle; // starting the plugin process when a plugin is created that doesn't already // have a process. After that, most of the communication is directly between // the renderer and plugin processes. -class CONTENT_EXPORT PluginProcessHost - : public content::BrowserChildProcessHostDelegate, - public IPC::Message::Sender { +class CONTENT_EXPORT PluginProcessHost : public BrowserChildProcessHost { public: class Client { public: @@ -71,9 +65,6 @@ class CONTENT_EXPORT PluginProcessHost PluginProcessHost(); virtual ~PluginProcessHost(); - // IPC::Message::Sender implementation: - virtual bool Send(IPC::Message* message) OVERRIDE; - // Initialize the new plugin process, returning true on success. This must // be called before the object can be used. bool Init(const webkit::WebPluginInfo& info); @@ -178,17 +169,7 @@ class CONTENT_EXPORT PluginProcessHost bool plugin_cursor_visible_; #endif - scoped_ptr<BrowserChildProcessHost> process_; - DISALLOW_COPY_AND_ASSIGN(PluginProcessHost); }; -class PluginProcessHostIterator - : public content::BrowserChildProcessHostTypeIterator<PluginProcessHost> { - public: - PluginProcessHostIterator() - : content::BrowserChildProcessHostTypeIterator<PluginProcessHost>( - content::PROCESS_TYPE_PLUGIN) {} -}; - #endif // CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_ diff --git a/content/browser/plugin_process_host_mac.cc b/content/browser/plugin_process_host_mac.cc index 883d301..91314b1 100644 --- a/content/browser/plugin_process_host_mac.cc +++ b/content/browser/plugin_process_host_mac.cc @@ -11,12 +11,9 @@ #include "base/bind.h" #include "base/logging.h" #include "base/mac/mac_util.h" -#include "base/process_util.h" -#include "content/browser/browser_child_process_host.h" #include "content/browser/plugin_process_host.h" #include "content/common/plugin_messages.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/child_process_data.h" #include "ui/gfx/rect.h" using content::BrowserThread; @@ -78,8 +75,7 @@ void PluginProcessHost::OnPluginHideWindow(uint32 window_id, if (plugin_fullscreen_windows_set_.find(window_id) != plugin_fullscreen_windows_set_.end()) { plugin_fullscreen_windows_set_.erase(window_id); - pid_t plugin_pid = - browser_needs_activation ? -1 : process_->GetData().handle; + pid_t plugin_pid = browser_needs_activation ? -1 : data().handle; browser_needs_activation = false; BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(ReleasePluginFullScreen, plugin_pid)); @@ -100,7 +96,7 @@ void PluginProcessHost::OnAppActivation() { if (!plugin_modal_windows_set_.empty()) { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - base::Bind(base::mac::ActivateProcess, process_->GetData().handle)); + base::Bind(base::mac::ActivateProcess, data().handle)); } } diff --git a/content/browser/plugin_service_impl.cc b/content/browser/plugin_service_impl.cc index cdb4db9..84734d5f 100644 --- a/content/browser/plugin_service_impl.cc +++ b/content/browser/plugin_service_impl.cc @@ -82,8 +82,12 @@ void WillLoadPluginsCallback() { static void NotifyPluginsOfActivation() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - for (PluginProcessHostIterator iter; !iter.Done(); ++iter) - iter->OnAppActivation(); + for (BrowserChildProcessHost::Iterator iter( + content::PROCESS_TYPE_PLUGIN); + !iter.Done(); ++iter) { + PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); + plugin->OnAppActivation(); + } } #endif #if defined(OS_POSIX) && !defined(OS_OPENBSD) @@ -227,9 +231,13 @@ void PluginServiceImpl::StartWatchingPlugins() { PluginProcessHost* PluginServiceImpl::FindNpapiPluginProcess( const FilePath& plugin_path) { - for (PluginProcessHostIterator iter; !iter.Done(); ++iter) { - if (iter->info().path == plugin_path) - return *iter; + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_PLUGIN); + !iter.Done(); ++iter) { + PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); + if (plugin->info().path == plugin_path) + return plugin; } return NULL; @@ -237,9 +245,15 @@ PluginProcessHost* PluginServiceImpl::FindNpapiPluginProcess( PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess( const FilePath& plugin_path) { - for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) { - if (iter->plugin_path() == plugin_path) - return *iter; + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + for (BrowserChildProcessHost::Iterator iter( + content::PROCESS_TYPE_PPAPI_PLUGIN); + !iter.Done(); ++iter) { + PpapiPluginProcessHost* plugin = + static_cast<PpapiPluginProcessHost*>(*iter); + if (plugin->plugin_path() == plugin_path) + return plugin; } return NULL; @@ -247,9 +261,15 @@ PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess( PpapiPluginProcessHost* PluginServiceImpl::FindPpapiBrokerProcess( const FilePath& broker_path) { - for (PpapiBrokerProcessHostIterator iter; !iter.Done(); ++iter) { - if (iter->plugin_path() == broker_path) - return *iter; + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + for (BrowserChildProcessHost::Iterator iter( + content::PROCESS_TYPE_PPAPI_BROKER); + !iter.Done(); ++iter) { + PpapiPluginProcessHost* broker = + static_cast<PpapiPluginProcessHost*>(*iter); + if (broker->plugin_path() == broker_path) + return broker; } return NULL; diff --git a/content/browser/ppapi_plugin_process_host.cc b/content/browser/ppapi_plugin_process_host.cc index 9ca0019..96b5029 100644 --- a/content/browser/ppapi_plugin_process_host.cc +++ b/content/browser/ppapi_plugin_process_host.cc @@ -9,7 +9,6 @@ #include "base/file_path.h" #include "base/process_util.h" #include "base/utf_string_conversions.h" -#include "content/browser/browser_child_process_host.h" #include "content/browser/plugin_service_impl.h" #include "content/browser/renderer_host/render_message_filter.h" #include "content/common/child_process_host_impl.h" @@ -88,12 +87,8 @@ PpapiPluginProcessHost* PpapiPluginProcessHost::CreateBrokerHost( return NULL; } -bool PpapiPluginProcessHost::Send(IPC::Message* message) { - return process_->Send(message); -} - void PpapiPluginProcessHost::OpenChannelToPlugin(Client* client) { - if (process_->GetHost()->IsChannelOpening()) { + if (child_process_host()->IsChannelOpening()) { // The channel is already in the process of being opened. Put // this "open channel" request into a queue of requests that will // be run once the channel is open. @@ -106,31 +101,29 @@ void PpapiPluginProcessHost::OpenChannelToPlugin(Client* client) { } PpapiPluginProcessHost::PpapiPluginProcessHost(net::HostResolver* host_resolver) - : filter_(new PepperMessageFilter(host_resolver)), + : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_PLUGIN), + filter_(new PepperMessageFilter(host_resolver)), network_observer_(new PluginNetworkObserver(this)), is_broker_(false), process_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()) { - process_.reset(new BrowserChildProcessHost( - content::PROCESS_TYPE_PPAPI_PLUGIN, this)); - process_->GetHost()->AddFilter(filter_.get()); + child_process_host()->AddFilter(filter_.get()); } PpapiPluginProcessHost::PpapiPluginProcessHost() - : is_broker_(true), + : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_BROKER), + is_broker_(true), process_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()) { - process_.reset(new BrowserChildProcessHost( - content::PROCESS_TYPE_PPAPI_BROKER, this)); } bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) { plugin_path_ = info.path; if (info.name.empty()) { - process_->SetName(plugin_path_.BaseName().LossyDisplayName()); + SetName(plugin_path_.BaseName().LossyDisplayName()); } else { - process_->SetName(UTF8ToUTF16(info.name)); + SetName(UTF8ToUTF16(info.name)); } - std::string channel_id = process_->GetHost()->CreateChannel(); + std::string channel_id = child_process_host()->CreateChannel(); if (channel_id.empty()) return false; @@ -183,7 +176,7 @@ bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) { #if defined(OS_POSIX) bool use_zygote = !is_broker_ && plugin_launcher.empty() && info.is_sandboxed; #endif // OS_POSIX - process_->Launch( + Launch( #if defined(OS_WIN) FilePath(), #elif defined(OS_POSIX) @@ -226,6 +219,7 @@ bool PpapiPluginProcessHost::OnMessageReceived(const IPC::Message& msg) { // Called when the browser <--> plugin channel has been established. void PpapiPluginProcessHost::OnChannelConnected(int32 peer_pid) { + BrowserChildProcessHost::OnChannelConnected(peer_pid); // This will actually load the plugin. Errors will actually not be reported // back at this point. Instead, the plugin will fail to establish the // connections when we request them on behalf of the renderer(s). @@ -277,7 +271,7 @@ void PpapiPluginProcessHost::OnRendererPluginChannelCreated( sent_requests_.pop(); // Prepare the handle to send to the renderer. - base::ProcessHandle plugin_process = process_->GetHandle(); + base::ProcessHandle plugin_process = GetChildProcessHandle(); #if defined(OS_WIN) base::ProcessHandle renderer_process; int renderer_id; diff --git a/content/browser/ppapi_plugin_process_host.h b/content/browser/ppapi_plugin_process_host.h index 0a37360..f92aa1d 100644 --- a/content/browser/ppapi_plugin_process_host.h +++ b/content/browser/ppapi_plugin_process_host.h @@ -12,12 +12,8 @@ #include "base/file_path.h" #include "base/memory/scoped_ptr.h" #include "base/memory/ref_counted.h" +#include "content/browser/browser_child_process_host.h" #include "content/browser/renderer_host/pepper_message_filter.h" -#include "content/public/browser/browser_child_process_host_delegate.h" -#include "content/public/browser/browser_child_process_host_iterator.h" -#include "ipc/ipc_message.h" - -class BrowserChildProcessHost; namespace content { struct PepperPluginInfo; @@ -30,8 +26,8 @@ class HostResolver; // Process host for PPAPI plugin and broker processes. // When used for the broker, interpret all references to "plugin" with "broker". -class PpapiPluginProcessHost : public content::BrowserChildProcessHostDelegate, - public IPC::Message::Sender { +class PpapiPluginProcessHost + : public BrowserChildProcessHost { public: class Client { public: @@ -64,9 +60,6 @@ class PpapiPluginProcessHost : public content::BrowserChildProcessHostDelegate, static PpapiPluginProcessHost* CreateBrokerHost( const content::PepperPluginInfo& info); - // IPC::Message::Sender implementation: - virtual bool Send(IPC::Message* message) OVERRIDE; - // Opens a new channel to the plugin. The client will be notified when the // channel is ready or if there's an error. void OpenChannelToPlugin(Client* client); @@ -122,28 +115,8 @@ class PpapiPluginProcessHost : public content::BrowserChildProcessHostDelegate, // The unique id created for the process. int process_id_; - scoped_ptr<BrowserChildProcessHost> process_; - DISALLOW_COPY_AND_ASSIGN(PpapiPluginProcessHost); }; -class PpapiPluginProcessHostIterator - : public content::BrowserChildProcessHostTypeIterator< - PpapiPluginProcessHost> { - public: - PpapiPluginProcessHostIterator() - : content::BrowserChildProcessHostTypeIterator< - PpapiPluginProcessHost>(content::PROCESS_TYPE_PPAPI_PLUGIN) {} -}; - -class PpapiBrokerProcessHostIterator - : public content::BrowserChildProcessHostTypeIterator< - PpapiPluginProcessHost> { - public: - PpapiBrokerProcessHostIterator() - : content::BrowserChildProcessHostTypeIterator< - PpapiPluginProcessHost>(content::PROCESS_TYPE_PPAPI_BROKER) {} -}; - #endif // CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_ diff --git a/content/browser/profiler_controller_impl.cc b/content/browser/profiler_controller_impl.cc index 1954da8..4b55357 100644 --- a/content/browser/profiler_controller_impl.cc +++ b/content/browser/profiler_controller_impl.cc @@ -6,15 +6,13 @@ #include "base/bind.h" #include "base/values.h" +#include "content/browser/browser_child_process_host.h" #include "content/common/child_process_messages.h" -#include "content/public/browser/browser_child_process_host_iterator.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/child_process_data.h" #include "content/public/browser/profiler_subscriber.h" #include "content/public/browser/render_process_host.h" #include "content/public/common/process_type.h" -using content::BrowserChildProcessHostIterator; using content::BrowserThread; namespace content { @@ -75,12 +73,13 @@ void ProfilerControllerImpl::GetProfilerDataFromChildProcesses( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); int pending_processes = 0; - for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { + for (BrowserChildProcessHost::Iterator child_process_host; + !child_process_host.Done(); ++child_process_host) { const std::string process_type = - content::GetProcessTypeNameInEnglish(iter.GetData().type); + content::GetProcessTypeNameInEnglish(child_process_host->data().type); ++pending_processes; - if (!iter.Send(new ChildProcessMsg_GetChildProfilerData( - sequence_number, process_type))) { + if (!child_process_host->Send(new ChildProcessMsg_GetChildProfilerData( + sequence_number, process_type))) { --pending_processes; } } @@ -124,8 +123,10 @@ void ProfilerControllerImpl::GetProfilerData(int sequence_number) { void ProfilerControllerImpl::SetProfilerStatusInChildProcesses(bool enable) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) - iter.Send(new ChildProcessMsg_SetProfilerStatus(enable)); + for (BrowserChildProcessHost::Iterator child_process_host; + !child_process_host.Done(); ++child_process_host) { + child_process_host->Send(new ChildProcessMsg_SetProfilerStatus(enable)); + } } void ProfilerControllerImpl::SetProfilerStatus(bool enable) { diff --git a/content/browser/renderer_host/gpu_message_filter.cc b/content/browser/renderer_host/gpu_message_filter.cc index efb5374..14b3b50 100644 --- a/content/browser/renderer_host/gpu_message_filter.cc +++ b/content/browser/renderer_host/gpu_message_filter.cc @@ -9,7 +9,6 @@ #include "content/browser/renderer_host/gpu_message_filter.h" #include "base/bind.h" -#include "base/process_util.h" #include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_surface_tracker.h" #include "content/browser/renderer_host/render_widget_helper.h" diff --git a/content/browser/renderer_host/render_widget_host_view_win.cc b/content/browser/renderer_host/render_widget_host_view_win.cc index 706211e..87866b2 100644 --- a/content/browser/renderer_host/render_widget_host_view_win.cc +++ b/content/browser/renderer_host/render_widget_host_view_win.cc @@ -32,7 +32,6 @@ #include "content/common/plugin_messages.h" #include "content/common/view_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/native_web_keyboard_event.h" #include "content/public/browser/notification_service.h" @@ -129,13 +128,15 @@ void NotifyPluginProcessHostHelper(HWND window, HWND parent, int tries) { DWORD plugin_process_id; bool found_starting_plugin_process = false; GetWindowThreadProcessId(window, &plugin_process_id); - for (PluginProcessHostIterator iter; !iter.Done(); ++iter) { - if (!iter.GetData().handle) { + for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_PLUGIN); + !iter.Done(); ++iter) { + PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); + if (!plugin->data().handle) { found_starting_plugin_process = true; continue; } - if (base::GetProcId(iter.GetData().handle) == plugin_process_id) { - iter->AddWindow(parent); + if (base::GetProcId(plugin->data().handle) == plugin_process_id) { + plugin->AddWindow(parent); return; } } diff --git a/content/browser/utility_process_host.cc b/content/browser/utility_process_host.cc index 2c225af..68db20a 100644 --- a/content/browser/utility_process_host.cc +++ b/content/browser/utility_process_host.cc @@ -9,7 +9,6 @@ #include "base/command_line.h" #include "base/message_loop.h" #include "base/utf_string_conversions.h" -#include "content/browser/browser_child_process_host.h" #include "content/common/child_process_host_impl.h" #include "content/common/utility_messages.h" #include "content/public/browser/content_browser_client.h" @@ -37,7 +36,8 @@ bool UtilityProcessHost::Client::OnMessageReceived( UtilityProcessHost::UtilityProcessHost(Client* client, BrowserThread::ID client_thread_id) - : client_(client), + : BrowserChildProcessHost(content::PROCESS_TYPE_UTILITY), + client_(client), client_thread_id_(client_thread_id), is_batch_mode_(false), no_sandbox_(false), @@ -48,8 +48,6 @@ UtilityProcessHost::UtilityProcessHost(Client* client, #endif use_linux_zygote_(false), started_(false) { - process_.reset(new BrowserChildProcessHost( - content::PROCESS_TYPE_UTILITY, this)); } UtilityProcessHost::~UtilityProcessHost() { @@ -60,7 +58,7 @@ bool UtilityProcessHost::Send(IPC::Message* message) { if (!StartProcess()) return false; - return process_->Send(message); + return BrowserChildProcessHost::Send(message); } bool UtilityProcessHost::StartBatchMode() { @@ -89,9 +87,9 @@ bool UtilityProcessHost::StartProcess() { return true; // Name must be set or metrics_service will crash in any test which // launches a UtilityProcessHost. - process_->SetName(ASCIIToUTF16("utility process")); + SetName(ASCIIToUTF16("utility process")); - std::string channel_id = process_->GetHost()->CreateChannel(); + std::string channel_id = child_process_host()->CreateChannel(); if (channel_id.empty()) return false; @@ -138,7 +136,7 @@ bool UtilityProcessHost::StartProcess() { use_zygote = !no_sandbox_ && use_linux_zygote_; #endif - process_->Launch( + Launch( #if defined(OS_WIN) exposed_dir_, #elif defined(OS_POSIX) diff --git a/content/browser/utility_process_host.h b/content/browser/utility_process_host.h index cad678e..1481d44 100644 --- a/content/browser/utility_process_host.h +++ b/content/browser/utility_process_host.h @@ -12,12 +12,9 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" #include "base/process_util.h" +#include "content/browser/browser_child_process_host.h" #include "content/common/content_export.h" -#include "content/public/browser/browser_child_process_host_delegate.h" #include "content/public/browser/browser_thread.h" -#include "ipc/ipc_message.h" - -class BrowserChildProcessHost; // This class acts as the browser-side host to a utility child process. A // utility process is a short-lived sandboxed process that is created to run @@ -26,9 +23,7 @@ class BrowserChildProcessHost; // If you need multiple batches of work to be done in the sandboxed process, // use StartBatchMode(), then multiple calls to StartFooBar(p), // then finish with EndBatchMode(). -class CONTENT_EXPORT UtilityProcessHost - : public content::BrowserChildProcessHostDelegate, - public IPC::Message::Sender { +class CONTENT_EXPORT UtilityProcessHost : public BrowserChildProcessHost { public: // An interface to be implemented by consumers of the utility process to // get results back. All functions are called on the thread passed along @@ -58,7 +53,7 @@ class CONTENT_EXPORT UtilityProcessHost content::BrowserThread::ID client_thread_id); virtual ~UtilityProcessHost(); - // IPC::Message::Sender implementation: + // BrowserChildProcessHost override virtual bool Send(IPC::Message* message) OVERRIDE; // Starts utility process in batch mode. Caller must call EndBatchMode() @@ -85,8 +80,10 @@ class CONTENT_EXPORT UtilityProcessHost // has already been started via StartBatchMode(). bool StartProcess(); - // BrowserChildProcessHost: + // IPC messages: virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + // BrowserChildProcessHost: virtual void OnProcessCrashed(int exit_code) OVERRIDE; // A pointer to our client interface, who will be informed of progress. @@ -115,8 +112,6 @@ class CONTENT_EXPORT UtilityProcessHost bool started_; - scoped_ptr<BrowserChildProcessHost> process_; - DISALLOW_COPY_AND_ASSIGN(UtilityProcessHost); }; diff --git a/content/browser/worker_host/worker_process_host.cc b/content/browser/worker_host/worker_process_host.cc index 11b3464..875511d 100644 --- a/content/browser/worker_host/worker_process_host.cc +++ b/content/browser/worker_host/worker_process_host.cc @@ -16,7 +16,6 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "content/browser/appcache/appcache_dispatcher_host.h" -#include "content/browser/browser_child_process_host.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/debugger/worker_devtools_message_filter.h" #include "content/browser/file_system/file_system_dispatcher_host.h" @@ -49,7 +48,6 @@ #include "webkit/glue/resource_type.h" using content::BrowserThread; -using content::ChildProcessData; using content::ChildProcessHost; using content::UserMetricsAction; using content::WorkerServiceImpl; @@ -88,11 +86,10 @@ void WorkerCrashCallback(int render_process_unique_id, int render_view_id) { WorkerProcessHost::WorkerProcessHost( const content::ResourceContext* resource_context) - : resource_context_(resource_context) { + : BrowserChildProcessHost(content::PROCESS_TYPE_WORKER), + resource_context_(resource_context) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(resource_context); - process_.reset(new BrowserChildProcessHost( - content::PROCESS_TYPE_WORKER, this)); } WorkerProcessHost::~WorkerProcessHost() { @@ -111,15 +108,11 @@ WorkerProcessHost::~WorkerProcessHost() { this, i->worker_route_id()); } - ChildProcessSecurityPolicy::GetInstance()->Remove(process_->GetData().id); -} - -bool WorkerProcessHost::Send(IPC::Message* message) { - return process_->Send(message); + ChildProcessSecurityPolicy::GetInstance()->Remove(data().id); } bool WorkerProcessHost::Init(int render_process_id) { - std::string channel_id = process_->GetHost()->CreateChannel(); + std::string channel_id = child_process_host()->CreateChannel(); if (channel_id.empty()) return false; @@ -182,7 +175,7 @@ bool WorkerProcessHost::Init(int render_process_id) { } #endif - process_->Launch( + Launch( #if defined(OS_WIN) FilePath(), #elif defined(OS_POSIX) @@ -192,7 +185,7 @@ bool WorkerProcessHost::Init(int render_process_id) { cmd_line); ChildProcessSecurityPolicy::GetInstance()->AddWorker( - process_->GetData().id, render_process_id); + data().id, render_process_id); if (!CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisableFileSystem)) { // Grant most file permissions to this worker. @@ -201,7 +194,7 @@ bool WorkerProcessHost::Init(int render_process_id) { // requests them. // This is for the filesystem sandbox. ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( - process_->GetData().id, resource_context_->file_system_context()-> + data().id, resource_context_->file_system_context()-> sandbox_provider()->new_base_path(), base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_CREATE | @@ -218,7 +211,7 @@ bool WorkerProcessHost::Init(int render_process_id) { // This is so that we can read and move stuff out of the old filesystem // sandbox. ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( - process_->GetData().id, resource_context_->file_system_context()-> + data().id, resource_context_->file_system_context()-> sandbox_provider()->old_base_path(), base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_WRITE_ATTRIBUTES | @@ -226,7 +219,7 @@ bool WorkerProcessHost::Init(int render_process_id) { // This is so that we can rename the old sandbox out of the way so that // we know we've taken care of it. ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( - process_->GetData().id, resource_context_->file_system_context()-> + data().id, resource_context_->file_system_context()-> sandbox_provider()->renamed_old_base_path(), base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE); @@ -243,38 +236,37 @@ void WorkerProcessHost::CreateMessageFilters(int render_process_id) { resource_context_->request_context(); ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( - process_->GetData().id, content::PROCESS_TYPE_WORKER, resource_context_, + data().id, content::PROCESS_TYPE_WORKER, resource_context_, new URLRequestContextSelector(request_context)); - process_->GetHost()->AddFilter(resource_message_filter); + child_process_host()->AddFilter(resource_message_filter); worker_message_filter_ = new WorkerMessageFilter( render_process_id, resource_context_, base::Bind(&WorkerServiceImpl::next_worker_route_id, base::Unretained(WorkerServiceImpl::GetInstance()))); - process_->GetHost()->AddFilter(worker_message_filter_); - process_->GetHost()->AddFilter(new AppCacheDispatcherHost( - resource_context_->appcache_service(), process_->GetData().id)); - process_->GetHost()->AddFilter(new FileSystemDispatcherHost( + child_process_host()->AddFilter(worker_message_filter_); + child_process_host()->AddFilter(new AppCacheDispatcherHost( + resource_context_->appcache_service(), data().id)); + child_process_host()->AddFilter(new FileSystemDispatcherHost( request_context, resource_context_->file_system_context())); - process_->GetHost()->AddFilter(new FileUtilitiesMessageFilter( - process_->GetData().id)); - process_->GetHost()->AddFilter(new BlobMessageFilter( - process_->GetData().id, resource_context_->blob_storage_context())); - process_->GetHost()->AddFilter(new MimeRegistryMessageFilter()); - process_->GetHost()->AddFilter(new DatabaseMessageFilter( + child_process_host()->AddFilter(new FileUtilitiesMessageFilter(data().id)); + child_process_host()->AddFilter(new BlobMessageFilter( + data().id, resource_context_->blob_storage_context())); + child_process_host()->AddFilter(new MimeRegistryMessageFilter()); + child_process_host()->AddFilter(new DatabaseMessageFilter( resource_context_->database_tracker())); SocketStreamDispatcherHost* socket_stream_dispatcher_host = new SocketStreamDispatcherHost( new URLRequestContextSelector(request_context), resource_context_); - process_->GetHost()->AddFilter(socket_stream_dispatcher_host); - process_->GetHost()->AddFilter( - new content::WorkerDevToolsMessageFilter(process_->GetData().id)); + child_process_host()->AddFilter(socket_stream_dispatcher_host); + child_process_host()->AddFilter( + new content::WorkerDevToolsMessageFilter(data().id)); } void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { ChildProcessSecurityPolicy::GetInstance()->GrantRequestURL( - process_->GetData().id, instance.url()); + data().id, instance.url()); instances_.push_back(instance); @@ -328,8 +320,7 @@ bool WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { NOTREACHED(); content::RecordAction(UserMetricsAction("BadMessageTerminate_WPH")); base::KillProcess( - process_->GetData().handle, content::RESULT_CODE_KILLED_BAD_MESSAGE, - false); + data().handle, content::RESULT_CODE_KILLED_BAD_MESSAGE, false); } if (handled) @@ -499,7 +490,7 @@ void WorkerProcessHost::UpdateTitle() { display_title += *i; } - process_->SetName(ASCIIToUTF16(display_title)); + SetName(ASCIIToUTF16(display_title)); } void WorkerProcessHost::DocumentDetached(WorkerMessageFilter* filter, @@ -521,10 +512,6 @@ void WorkerProcessHost::TerminateWorker(int worker_route_id) { Send(new WorkerMsg_TerminateWorkerContext(worker_route_id)); } -const ChildProcessData& WorkerProcessHost::GetData() { - return process_->GetData(); -} - WorkerProcessHost::WorkerInstance::WorkerInstance( const GURL& url, const string16& name, diff --git a/content/browser/worker_host/worker_process_host.h b/content/browser/worker_host/worker_process_host.h index 57806c8..6ccc137 100644 --- a/content/browser/worker_host/worker_process_host.h +++ b/content/browser/worker_host/worker_process_host.h @@ -11,15 +11,10 @@ #include "base/basictypes.h" #include "base/file_path.h" -#include "base/memory/scoped_ptr.h" +#include "content/browser/browser_child_process_host.h" #include "content/common/content_export.h" #include "content/browser/worker_host/worker_document_set.h" -#include "content/public/browser/browser_child_process_host_delegate.h" -#include "content/public/browser/browser_child_process_host_iterator.h" #include "googleurl/src/gurl.h" -#include "ipc/ipc_message.h" - -class BrowserChildProcessHost; namespace content { class ResourceContext; @@ -32,8 +27,7 @@ class WorkerServiceImpl; // process, but that may change. However, we do assume (by storing a // net::URLRequestContext) that a WorkerProcessHost serves a single // BrowserContext. -class WorkerProcessHost : public content::BrowserChildProcessHostDelegate, - public IPC::Message::Sender { +class WorkerProcessHost : public BrowserChildProcessHost { public: // Contains information about each worker instance, needed to forward messages // between the renderer and worker processes. @@ -116,9 +110,6 @@ class WorkerProcessHost : public content::BrowserChildProcessHostDelegate, explicit WorkerProcessHost(const content::ResourceContext* resource_context); virtual ~WorkerProcessHost(); - // IPC::Message::Sender implementation: - virtual bool Send(IPC::Message* message) OVERRIDE; - // Starts the process. Returns true iff it succeeded. // |render_process_id| is the renderer process responsible for starting this // worker. @@ -141,8 +132,6 @@ class WorkerProcessHost : public content::BrowserChildProcessHostDelegate, // Terminates the given worker, i.e. based on a UI action. CONTENT_EXPORT void TerminateWorker(int worker_route_id); - CONTENT_EXPORT const content::ChildProcessData& GetData(); - typedef std::list<WorkerInstance> Instances; const Instances& instances() const { return instances_; } @@ -156,13 +145,16 @@ class WorkerProcessHost : public content::BrowserChildProcessHostDelegate, Instances& mutable_instances() { return instances_; } private: - // BrowserChildProcessHostDelegate implementation: + // Called when the process has been launched successfully. virtual void OnProcessLaunched() OVERRIDE; - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; // Creates and adds the message filters. void CreateMessageFilters(int render_process_id); + // IPC::Channel::Listener implementation: + // Called when a message arrives from the worker process. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + void OnWorkerContextClosed(int worker_route_id); void OnAllowDatabase(int worker_route_id, const GURL& url, @@ -194,18 +186,7 @@ class WorkerProcessHost : public content::BrowserChildProcessHostDelegate, // process. scoped_refptr<WorkerMessageFilter> worker_message_filter_; - scoped_ptr<BrowserChildProcessHost> process_; - DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost); }; -class WorkerProcessHostIterator - : public content::BrowserChildProcessHostTypeIterator<WorkerProcessHost> { - public: - WorkerProcessHostIterator() - : content::BrowserChildProcessHostTypeIterator<WorkerProcessHost>( - content::PROCESS_TYPE_WORKER) { - } -}; - #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ diff --git a/content/browser/worker_host/worker_service_impl.cc b/content/browser/worker_host/worker_service_impl.cc index bddd74e..9686152 100644 --- a/content/browser/worker_host/worker_service_impl.cc +++ b/content/browser/worker_host/worker_service_impl.cc @@ -15,7 +15,6 @@ #include "content/browser/worker_host/worker_process_host.h" #include "content/common/view_messages.h" #include "content/common/worker_messages.h" -#include "content/public/browser/child_process_data.h" #include "content/public/browser/worker_service_observer.h" #include "content/public/common/content_switches.h" #include "content/public/common/process_type.h" @@ -46,8 +45,10 @@ WorkerServiceImpl::~WorkerServiceImpl() { void WorkerServiceImpl::OnWorkerMessageFilterClosing( WorkerMessageFilter* filter) { - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { - iter->FilterShutdown(filter); + for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); + !iter.Done(); ++iter) { + WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); + worker->FilterShutdown(filter); } // See if that process had any queued workers. @@ -155,8 +156,10 @@ void WorkerServiceImpl::CancelCreateDedicatedWorker( void WorkerServiceImpl::ForwardToWorker(const IPC::Message& message, WorkerMessageFilter* filter) { - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { - if (iter->FilterMessage(message, filter)) + for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); + !iter.Done(); ++iter) { + WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); + if (worker->FilterMessage(message, filter)) return; } @@ -166,8 +169,11 @@ void WorkerServiceImpl::ForwardToWorker(const IPC::Message& message, void WorkerServiceImpl::DocumentDetached(unsigned long long document_id, WorkerMessageFilter* filter) { // Any associated shared workers can be shut down. - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) - iter->DocumentDetached(filter, document_id); + for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); + !iter.Done(); ++iter) { + WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); + worker->DocumentDetached(filter, document_id); + } // Remove any queued shared workers for this document. for (WorkerProcessHost::Instances::iterator iter = queued_workers_.begin(); @@ -303,14 +309,16 @@ WorkerProcessHost* WorkerServiceImpl::GetProcessForDomain(const GURL& url) { int num_processes = 0; std::string domain = net::RegistryControlledDomainService::GetDomainAndRegistry(url); - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { + for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); + !iter.Done(); ++iter) { num_processes++; + WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); for (WorkerProcessHost::Instances::const_iterator instance = - iter->instances().begin(); - instance != iter->instances().end(); ++instance) { + worker->instances().begin(); + instance != worker->instances().end(); ++instance) { if (net::RegistryControlledDomainService::GetDomainAndRegistry( instance->url()) == domain) { - return *iter; + return worker; } } } @@ -323,7 +331,8 @@ WorkerProcessHost* WorkerServiceImpl::GetProcessForDomain(const GURL& url) { WorkerProcessHost* WorkerServiceImpl::GetProcessToFillUpCores() { int num_processes = 0; - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) + BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); + for (; !iter.Done(); ++iter) num_processes++; if (num_processes >= base::SysInfo::NumberOfProcessors()) @@ -334,9 +343,11 @@ WorkerProcessHost* WorkerServiceImpl::GetProcessToFillUpCores() { WorkerProcessHost* WorkerServiceImpl::GetLeastLoadedWorker() { WorkerProcessHost* smallest = NULL; - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { - if (!smallest || iter->instances().size() < smallest->instances().size()) - smallest = *iter; + for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); + !iter.Done(); ++iter) { + WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); + if (!smallest || worker->instances().size() < smallest->instances().size()) + smallest = worker; } return smallest; @@ -374,10 +385,12 @@ bool WorkerServiceImpl::TabCanCreateWorkerProcess( int total_workers = 0; int workers_per_tab = 0; *hit_total_worker_limit = false; - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { + for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); + !iter.Done(); ++iter) { + WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); for (WorkerProcessHost::Instances::const_iterator cur_instance = - iter->instances().begin(); - cur_instance != iter->instances().end(); ++cur_instance) { + worker->instances().begin(); + cur_instance != worker->instances().end(); ++cur_instance) { total_workers++; if (total_workers >= kMaxWorkersWhenSeparate) { *hit_total_worker_limit = true; @@ -420,14 +433,16 @@ void WorkerServiceImpl::TryStartingQueuedWorker() { bool WorkerServiceImpl::GetRendererForWorker(int worker_process_id, int* render_process_id, int* render_view_id) const { - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { - if (iter.GetData().id != worker_process_id) + for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); + !iter.Done(); ++iter) { + if (iter->data().id != worker_process_id) continue; // This code assumes one worker per process, see function comment in header! + WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); WorkerProcessHost::Instances::const_iterator first_instance = - iter->instances().begin(); - if (first_instance == iter->instances().end()) + worker->instances().begin(); + if (first_instance == worker->instances().end()) return false; WorkerDocumentSet::DocumentInfoSet::const_iterator info = @@ -441,13 +456,15 @@ bool WorkerServiceImpl::GetRendererForWorker(int worker_process_id, const WorkerProcessHost::WorkerInstance* WorkerServiceImpl::FindWorkerInstance( int worker_process_id) { - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { - if (iter.GetData().id != worker_process_id) + for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); + !iter.Done(); ++iter) { + if (iter->data().id != worker_process_id) continue; + WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); WorkerProcessHost::Instances::const_iterator instance = - iter->instances().begin(); - return instance == iter->instances().end() ? NULL : &*instance; + worker->instances().begin(); + return instance == worker->instances().end() ? NULL : &*instance; } return NULL; } @@ -479,10 +496,12 @@ WorkerProcessHost::WorkerInstance* WorkerServiceImpl::FindSharedWorkerInstance( const GURL& url, const string16& name, const content::ResourceContext* resource_context) { - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { + for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); + !iter.Done(); ++iter) { + WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); for (WorkerProcessHost::Instances::iterator instance_iter = - iter->mutable_instances().begin(); - instance_iter != iter->mutable_instances().end(); + worker->mutable_instances().begin(); + instance_iter != worker->mutable_instances().end(); ++instance_iter) { if (instance_iter->Matches(url, name, resource_context)) return &(*instance_iter); diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 2503c7b..f60b942 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -27,11 +27,6 @@ 'sources': [ 'public/browser/access_token_store.cc', 'public/browser/access_token_store.h', - 'public/browser/browser_child_process_host.h', - 'public/browser/browser_child_process_host_delegate.cc', - 'public/browser/browser_child_process_host_delegate.h', - 'public/browser/browser_child_process_host_iterator.cc', - 'public/browser/browser_child_process_host_iterator.h', 'public/browser/browser_context.h', 'public/browser/browser_main_parts.h', 'public/browser/browser_message_filter.cc', diff --git a/content/content_common.gypi b/content/content_common.gypi index 4be564af5..8f791b0 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -30,7 +30,6 @@ 'sources': [ 'public/common/bindings_policy.h', 'public/common/child_process_host.h', - 'public/common/child_process_host_delegate.cc', 'public/common/child_process_host_delegate.h', 'public/common/child_process_sandbox_support_linux.h', 'public/common/content_constants.cc', diff --git a/content/public/browser/DEPS b/content/public/browser/DEPS index ca317ea..85dabc6 100644 --- a/content/public/browser/DEPS +++ b/content/public/browser/DEPS @@ -1,5 +1,4 @@ include_rules = [ - "+content/browser/browser_child_process_host.h", "+content/browser/notification_service_impl.h", "+content/browser/renderer_host/render_view_host.h", diff --git a/content/public/browser/browser_child_process_host.h b/content/public/browser/browser_child_process_host.h deleted file mode 100644 index e4b6da3..0000000 --- a/content/public/browser/browser_child_process_host.h +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2012 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_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ -#define CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ -#pragma once - -#include "base/process_util.h" -#include "base/string16.h" -#include "build/build_config.h" -#include "content/common/content_export.h" -#include "content/public/common/process_type.h" -#include "ipc/ipc_message.h" - -class CommandLine; -class FilePath; - -namespace content { - -class BrowserChildProcessHostDelegate; -class ChildProcessHost; -struct ChildProcessData; - -// This represents child processes of the browser process, i.e. plugins. They -// will get terminated at browser shutdown. -class CONTENT_EXPORT BrowserChildProcessHost : public IPC::Message::Sender { - public: - // Used to create a child process host. The delegate must outlive this object. - static BrowserChildProcessHost* Create( - ProcessType type, - BrowserChildProcessHostDelegate* delegate); - - virtual ~BrowserChildProcessHost() {} - - // Derived classes call this to launch the child process asynchronously. - virtual void Launch( -#if defined(OS_WIN) - const FilePath& exposed_dir, -#elif defined(OS_POSIX) - bool use_zygote, - const base::environment_vector& environ, -#endif - CommandLine* cmd_line) = 0; - - virtual const ChildProcessData& GetData() const = 0; - - // Returns the ChildProcessHost object used by this object. - virtual ChildProcessHost* GetHost() const = 0; - - // Returns the termination status of a child. |exit_code| is the - // status returned when the process exited (for posix, as returned - // from waitpid(), for Windows, as returned from - // GetExitCodeProcess()). |exit_code| may be NULL. - virtual base::TerminationStatus GetTerminationStatus(int* exit_code) = 0; - - // Sets the user-visible name of the process. - virtual void SetName(const string16& name) = 0; - - // Set the handle of the process. BrowserChildProcessHost will do this when - // the Launch method is used to start the process. However if the owner - // of this object doesn't call Launch and starts the process in another way, - // they need to call this method so that the process handle is associated with - // this object. - virtual void SetHandle(base::ProcessHandle handle) = 0; -}; - -}; // namespace content - -#endif // CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ diff --git a/content/public/browser/browser_child_process_host_delegate.cc b/content/public/browser/browser_child_process_host_delegate.cc deleted file mode 100644 index 06a7c6d..0000000 --- a/content/public/browser/browser_child_process_host_delegate.cc +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2012 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/public/browser/browser_child_process_host_delegate.h" - -namespace content { - -bool BrowserChildProcessHostDelegate::CanShutdown() { - return true; -} - -} // namespace content diff --git a/content/public/browser/browser_child_process_host_delegate.h b/content/public/browser/browser_child_process_host_delegate.h deleted file mode 100644 index e028c9a..0000000 --- a/content/public/browser/browser_child_process_host_delegate.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2012 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_BROWSER_BROWSER_CHILD_PROCESS_HOST_DELEGATE_H_ -#define CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_DELEGATE_H_ -#pragma once - -#include "content/common/content_export.h" -#include "ipc/ipc_channel.h" - -namespace content { - -// Interface that all users of BrowserChildProcessHost need to provide. -class CONTENT_EXPORT BrowserChildProcessHostDelegate - : public IPC::Channel::Listener { - public: - virtual ~BrowserChildProcessHostDelegate() {} - - // Delegates return true if it's ok to shut down the child process (which is - // the default return value). The exception is if the host is in the middle of - // sending a request to the process, in which case the other side might think - // it's ok to shutdown, when really it's not. - virtual bool CanShutdown(); - - // Called when the process has been started. - virtual void OnProcessLaunched() {} - - // Called if the process crashed. |exit_code| is the status returned when the - // process crashed (for posix, as returned from waitpid(), for Windows, as - // returned from GetExitCodeProcess()). - virtual void OnProcessCrashed(int exit_code) {} -}; - -}; // namespace content - -#endif // CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_DELEGATE_H_ diff --git a/content/public/browser/browser_child_process_host_iterator.cc b/content/public/browser/browser_child_process_host_iterator.cc deleted file mode 100644 index 534a431..0000000 --- a/content/public/browser/browser_child_process_host_iterator.cc +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) 2012 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/public/browser/browser_child_process_host_iterator.h" - -#include "base/logging.h" -#include "content/browser/browser_child_process_host.h" -#include "content/public/browser/browser_thread.h" - -namespace content { - -BrowserChildProcessHostIterator::BrowserChildProcessHostIterator() - : all_(true), type_(content::PROCESS_TYPE_UNKNOWN) { - CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << - "BrowserChildProcessHostIterator must be used on the IO thread."; - iterator_ = ::BrowserChildProcessHost::GetIterator()->begin(); -} - -BrowserChildProcessHostIterator::BrowserChildProcessHostIterator( - content::ProcessType type) - : all_(false), type_(type) { - CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << - "BrowserChildProcessHostIterator must be used on the IO thread."; - iterator_ = ::BrowserChildProcessHost::GetIterator()->begin(); - if (!Done() && (*iterator_)->GetData().type != type_) - ++(*this); -} - -bool BrowserChildProcessHostIterator::operator++() { - CHECK(!Done()); - do { - ++iterator_; - if (Done()) - break; - - if (!all_ && (*iterator_)->GetData().type != type_) - continue; - - return true; - } while (true); - - return false; -} - -bool BrowserChildProcessHostIterator::Done() { - return iterator_ == ::BrowserChildProcessHost::GetIterator()->end(); -} - -const ChildProcessData& BrowserChildProcessHostIterator::GetData() { - CHECK(!Done()); - return (*iterator_)->GetData(); -} - -bool BrowserChildProcessHostIterator::Send(IPC::Message* message) { - CHECK(!Done()); - return (*iterator_)->Send(message); -} - -BrowserChildProcessHostDelegate* - BrowserChildProcessHostIterator::GetDelegate() { - return (*iterator_)->delegate(); -} - -} // namespace content diff --git a/content/public/browser/browser_child_process_host_iterator.h b/content/public/browser/browser_child_process_host_iterator.h deleted file mode 100644 index 357d708..0000000 --- a/content/public/browser/browser_child_process_host_iterator.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2012 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_BROWSER_BROWSER_CHILD_PROCESS_HOST_ITERATOR_H_ -#define CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_ITERATOR_H_ -#pragma once - -#include <list> - -#include "content/common/content_export.h" -#include "content/public/common/process_type.h" - -class BrowserChildProcessHost; - -namespace IPC { -class Message; -} - -namespace content { - -class BrowserChildProcessHostDelegate; -struct ChildProcessData; - -// This class allows iteration through either all child processes, or ones of a -// specific type, depending on which constructor is used. Note that this should -// be done from the IO thread and that the iterator should not be kept around as -// it may be invalidated on subsequent event processing in the event loop. -class CONTENT_EXPORT BrowserChildProcessHostIterator { - public: - BrowserChildProcessHostIterator(); - explicit BrowserChildProcessHostIterator(content::ProcessType type); - - // These methods work on the current iterator object. Only call them if - // Done() returns false. - bool operator++(); - bool Done(); - const ChildProcessData& GetData(); - bool Send(IPC::Message* message); - BrowserChildProcessHostDelegate* GetDelegate(); - - private: - bool all_; - content::ProcessType type_; - std::list<BrowserChildProcessHost*>::iterator iterator_; -}; - -// Helper class so that subclasses of BrowserChildProcessHostDelegate can be -// iterated with no casting needing. Note that because of the components build, -// this class can only be used by BCPHD implementations that live in content, -// otherwise link errors will result. -template <class T> -class CONTENT_EXPORT BrowserChildProcessHostTypeIterator - : public BrowserChildProcessHostIterator { - public: - explicit BrowserChildProcessHostTypeIterator(content::ProcessType type) - : BrowserChildProcessHostIterator(type) {} - T* operator->() { - return static_cast<T*>(GetDelegate()); - } - T* operator*() { - return static_cast<T*>(GetDelegate()); - } -}; - -}; // namespace content - -#endif // CONTENT_PUBLIC_BROWSER_BROWSER_CHILD_PROCESS_HOST_ITERATOR_H_ diff --git a/content/public/common/child_process_host.h b/content/public/common/child_process_host.h index 499ac2e..8c85091 100644 --- a/content/public/common/child_process_host.h +++ b/content/public/common/child_process_host.h @@ -16,9 +16,7 @@ namespace content { class ChildProcessHostDelegate; -// This represents a non-browser process. This can include traditional child -// processes like plugins, or an embedder could even use this for long lived -// processes that run independent of the browser process. +// Interface that all users of ChildProcessHost need to provide. class CONTENT_EXPORT ChildProcessHost : public IPC::Message::Sender { public: virtual ~ChildProcessHost() {} diff --git a/content/public/common/child_process_host_delegate.cc b/content/public/common/child_process_host_delegate.cc deleted file mode 100644 index 85b0398..0000000 --- a/content/public/common/child_process_host_delegate.cc +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2012 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/public/common/child_process_host_delegate.h" - -namespace content { - -bool ChildProcessHostDelegate::CanShutdown() { - return true; -} - -} // namespace content diff --git a/content/public/common/child_process_host_delegate.h b/content/public/common/child_process_host_delegate.h index 4418e611..7b9cbd1 100644 --- a/content/public/common/child_process_host_delegate.h +++ b/content/public/common/child_process_host_delegate.h @@ -2,13 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_PUBLIC_COMMON_CHILD_PROCESS_HOST_DELEGATE_H_ -#define CONTENT_PUBLIC_COMMON_CHILD_PROCESS_HOST_DELEGATE_H_ +#ifndef CONTENT_PULIC_COMMON_CHILD_PROCESS_HOST_DELEGATE_H_ +#define CONTENT_PULIC_COMMON_CHILD_PROCESS_HOST_DELEGATE_H_ #pragma once #include <string> -#include "content/common/content_export.h" #include "ipc/ipc_channel.h" namespace content { @@ -18,20 +17,20 @@ class ChildProcessHostDelegate : public IPC::Channel::Listener { public: virtual ~ChildProcessHostDelegate() {} - // Delegates return true if it's ok to shut down the child process (which is - // the default return value). The exception is if the host is in the middle of - // sending a request to the process, in which case the other side might think - // it's ok to shutdown, when really it's not. - CONTENT_EXPORT virtual bool CanShutdown(); + // Derived classes return true if it's ok to shut down the child process. + // Normally they would return true. The exception is if the host is in the + // middle of sending a request to the process, in which case the other side + // might think it's ok to shutdown, when really it's not. + virtual bool CanShutdown() = 0; // Notifies the derived class that we told the child process to kill itself. - virtual void ShutdownStarted() {} + virtual void ShutdownStarted() = 0; // Called when the child process unexpected closes the IPC channel. Delegates // would normally delete the object in this case. - virtual void OnChildDisconnected() {} + virtual void OnChildDisconnected() = 0; }; }; // namespace content -#endif // CONTENT_PUBLIC_COMMON_CHILD_PROCESS_HOST_DELEGATE_H_ +#endif // CONTENT_PULIC_COMMON_CHILD_PROCESS_HOST_DELEGATE_H_ |