summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-15 22:19:48 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-15 22:19:48 +0000
commit8e2b6472071f38c065a3d00adb136ef259ef68a1 (patch)
tree8a05864f6463e4948c6468139998a59eb6b54899 /chrome/common
parent10a4a0aa5e9a1754752454ee2d4d8aff872a61a3 (diff)
downloadchromium_src-8e2b6472071f38c065a3d00adb136ef259ef68a1.zip
chromium_src-8e2b6472071f38c065a3d00adb136ef259ef68a1.tar.gz
chromium_src-8e2b6472071f38c065a3d00adb136ef259ef68a1.tar.bz2
Create a ResourceMessageFilter to filter resource related IPCs. This gets rid of the awkward ResourceDispatcherHost::Receiver interface and allows a bunch of cleanup. I've also generalized the filtering done in WorkerProcessHost and moved it to ChildProcessHost (since it's now used to add the ResourceMessageFilter).
Review URL: http://codereview.chromium.org/5874002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69335 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/child_process_host.cc56
-rw-r--r--chrome/common/child_process_host.h29
2 files changed, 54 insertions, 31 deletions
diff --git a/chrome/common/child_process_host.cc b/chrome/common/child_process_host.cc
index dad6415..fd68895 100644
--- a/chrome/common/child_process_host.cc
+++ b/chrome/common/child_process_host.cc
@@ -13,7 +13,6 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/plugin_messages.h"
#include "ipc/ipc_logging.h"
-#include "ipc/ipc_message.h"
#if defined(OS_LINUX)
#include "base/linux_util.h"
@@ -25,6 +24,17 @@ ChildProcessHost::ChildProcessHost()
}
ChildProcessHost::~ChildProcessHost() {
+ for (size_t i = 0; i < filters_.size(); ++i) {
+ filters_[i]->OnChannelClosing();
+ filters_[i]->OnFilterRemoved();
+ }
+}
+
+void ChildProcessHost::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
+ filters_.push_back(filter);
+
+ if (channel_.get())
+ filter->OnFilterAdded(channel_.get());
}
// static
@@ -109,13 +119,16 @@ bool ChildProcessHost::CreateChannel() {
if (!channel_->Connect())
return false;
+ for (size_t i = 0; i < filters_.size(); ++i)
+ filters_[i]->OnFilterAdded(channel_.get());
+
// Make sure these messages get sent first.
#if defined(IPC_MESSAGE_LOG_ENABLED)
bool enabled = IPC::Logging::GetInstance()->Enabled();
- SendOnChannel(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
+ Send(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
#endif
- SendOnChannel(new PluginProcessMsg_AskBeforeShutdown());
+ Send(new PluginProcessMsg_AskBeforeShutdown());
opening_channel_ = true;
@@ -126,22 +139,18 @@ void ChildProcessHost::InstanceCreated() {
Notify(NotificationType::CHILD_INSTANCE_CREATED);
}
-bool ChildProcessHost::SendOnChannel(IPC::Message* msg) {
+bool ChildProcessHost::Send(IPC::Message* message) {
if (!channel_.get()) {
- delete msg;
+ delete message;
return false;
}
- return channel_->Send(msg);
+ return channel_->Send(message);
}
void ChildProcessHost::OnChildDied() {
delete this;
}
-bool ChildProcessHost::InterceptMessageFromChild(const IPC::Message& msg) {
- return false;
-}
-
ChildProcessHost::ListenerHook::ListenerHook(ChildProcessHost* host)
: host_(host) {
}
@@ -159,17 +168,22 @@ void ChildProcessHost::ListenerHook::OnMessageReceived(
logger->OnPreDispatchMessage(msg);
#endif
- bool handled = host_->InterceptMessageFromChild(msg);
+ if (msg.type() == PluginProcessHostMsg_ShutdownRequest::ID &&
+ host_->CanShutdown()) {
+ host_->Send(new PluginProcessMsg_Shutdown());
+ }
- if (!handled) {
- if (msg.type() == PluginProcessHostMsg_ShutdownRequest::ID) {
- if (host_->CanShutdown())
- host_->SendOnChannel(new PluginProcessMsg_Shutdown());
- } else {
- host_->OnMessageReceived(msg);
+ bool handled = false;
+ for (size_t i = 0; i < host_->filters_.size(); ++i) {
+ if (host_->filters_[i]->OnMessageReceived(msg)) {
+ handled = true;
+ break;
}
}
+ if (!handled)
+ host_->OnMessageReceived(msg);
+
#ifdef IPC_MESSAGE_LOG_ENABLED
if (logger->Enabled())
logger->OnPostDispatchMessage(msg, host_->channel_id_);
@@ -181,16 +195,22 @@ void ChildProcessHost::ListenerHook::OnChannelConnected(int32 peer_pid) {
host_->OnChannelConnected(peer_pid);
// Notify in the main loop of the connection.
host_->Notify(NotificationType::CHILD_PROCESS_HOST_CONNECTED);
+
+ for (size_t i = 0; i < host_->filters_.size(); ++i)
+ host_->filters_[i]->OnChannelConnected(peer_pid);
}
void ChildProcessHost::ListenerHook::OnChannelError() {
host_->opening_channel_ = false;
host_->OnChannelError();
+ for (size_t i = 0; i < host_->filters_.size(); ++i)
+ host_->filters_[i]->OnChannelError();
+
// This will delete host_, which will also destroy this!
host_->OnChildDied();
}
void ChildProcessHost::ForceShutdown() {
- SendOnChannel(new PluginProcessMsg_Shutdown());
+ Send(new PluginProcessMsg_Shutdown());
}
diff --git a/chrome/common/child_process_host.h b/chrome/common/child_process_host.h
index 72438e8..3b467ec 100644
--- a/chrome/common/child_process_host.h
+++ b/chrome/common/child_process_host.h
@@ -7,6 +7,7 @@
#pragma once
#include <string>
+#include <vector>
#include "build/build_config.h"
@@ -17,7 +18,7 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "chrome/common/notification_type.h"
-#include "ipc/ipc_channel.h"
+#include "ipc/ipc_channel_proxy.h"
class CommandLine;
class FilePath;
@@ -29,8 +30,8 @@ class Message;
// Provides common functionality for hosting a child process and processing IPC
// messages between the host and the child process. Subclasses are responsible
// for the actual launching and terminating of the child processes.
-//
-class ChildProcessHost : public IPC::Channel::Listener {
+class ChildProcessHost : public IPC::Channel::Listener,
+ public IPC::Message::Sender {
public:
virtual ~ChildProcessHost();
@@ -56,16 +57,14 @@ class ChildProcessHost : public IPC::Channel::Listener {
static void PreCacheFont(LOGFONT font);
#endif // defined(OS_WIN)
+ // IPC::Message::Sender implementation.
+ bool Send(IPC::Message* message);
+
protected:
ChildProcessHost();
- // A helper method to send an IPC message to the child on the channel.
- // It behavies just like IPC::Message::Sender::Send. The implementor takes
- // ownership of the given Message regardless of whether or not this method
- // succeeds. This class does not implement IPC::Message::Sender to prevent
- // conflicts with subclasses which indirectly could inherit from
- // IPC::Message::Sender.
- bool SendOnChannel(IPC::Message* msg);
+ // Adds an IPC message filter. A reference will be kept to the filter.
+ void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
// Derived classes return true if it's ok to shut down the child process.
virtual bool CanShutdown() = 0;
@@ -91,9 +90,8 @@ class ChildProcessHost : public IPC::Channel::Listener {
// Called when the child process goes away.
virtual void OnChildDied();
- // Allows the derived implementation to intercept a message before it is
- // handed to the IPC::Channel::Listener::OnMessageReceived implementation.
- virtual bool InterceptMessageFromChild(const IPC::Message& msg);
+ // Notifies the derived class that we told the child process to kill itself.
+ virtual void ShutdownStarted() { }
// Subclasses can implement specific notification methods.
virtual void Notify(NotificationType type) { }
@@ -117,6 +115,11 @@ class ChildProcessHost : public IPC::Channel::Listener {
scoped_ptr<IPC::Channel> channel_;
std::string channel_id_;
+ // Holds all the IPC message filters. Since this object lives on the IO
+ // thread, we don't have a IPC::ChannelProxy and so we manage filters
+ // manually.
+ std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_;
+
DISALLOW_COPY_AND_ASSIGN(ChildProcessHost);
};