Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(972)

Unified Diff: chrome/common/child_process_host.cc

Issue 5874002: Create a ResourceMessageFilter to filter resource related IPCs. This gets ri... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/child_process_host.cc
===================================================================
--- chrome/common/child_process_host.cc (revision 69229)
+++ chrome/common/child_process_host.cc (working copy)
@@ -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,8 +24,19 @@
}
ChildProcessHost::~ChildProcessHost() {
+ for (size_t i = 0; i < filters_.size(); ++i) {
+ filters_[i]->OnChannelClosing();
+ filters_[i]->OnFilterRemoved();
+ }
}
+void ChildProcessHost::AddFilter(IPC::ChannelProxy::MessageFilter* filter) {
+ filters_.push_back(filter);
+
+ if (channel_.get())
+ filter->OnFilterAdded(channel_.get());
+}
+
// static
FilePath ChildProcessHost::GetChildPath(bool allow_self) {
FilePath child_path;
@@ -109,13 +119,16 @@
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 @@
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 @@
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 @@
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());
}

Powered by Google App Engine
This is Rietveld 408576698