diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-17 00:52:35 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-17 00:52:35 +0000 |
commit | dabe607133c5b62e6b0134017f35cb87d0d4f3b6 (patch) | |
tree | db5d35947dcfa2810c7e7e19364ecaae37aa0912 /chrome/common | |
parent | a91baaa1bab5fe3de395aad464015a098290a46b (diff) | |
download | chromium_src-dabe607133c5b62e6b0134017f35cb87d0d4f3b6.zip chromium_src-dabe607133c5b62e6b0134017f35cb87d0d4f3b6.tar.gz chromium_src-dabe607133c5b62e6b0134017f35cb87d0d4f3b6.tar.bz2 |
Hide the details about ResourceDispatcherHost messages from child processes. The usage of RDH is now like RD, the client sends the message to RDH to see if it should handle it. I added methods to the Receiver interface so that RDH can get to the process id/handle/type when starting requests.
Review URL: http://codereview.chromium.org/42202
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11816 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/child_process_host.cc | 19 | ||||
-rw-r--r-- | chrome/common/child_process_host.h | 14 | ||||
-rw-r--r-- | chrome/common/child_process_info.cc | 1 | ||||
-rw-r--r-- | chrome/common/child_process_info.h | 22 | ||||
-rw-r--r-- | chrome/common/resource_dispatcher.cc | 6 | ||||
-rw-r--r-- | chrome/common/resource_dispatcher.h | 7 |
6 files changed, 43 insertions, 26 deletions
diff --git a/chrome/common/child_process_host.cc b/chrome/common/child_process_host.cc index cb37d30..4269678 100644 --- a/chrome/common/child_process_host.cc +++ b/chrome/common/child_process_host.cc @@ -7,6 +7,7 @@ #include "base/compiler_specific.h" #include "base/logging.h" #include "base/message_loop.h" +#include "base/process_util.h" #include "base/singleton.h" #include "base/waitable_event.h" #include "chrome/browser/chrome_thread.h" @@ -14,6 +15,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" #include "chrome/common/process_watcher.h" +#include "chrome/common/result_codes.h" typedef std::list<ChildProcessInfo*> ChildProcessList; @@ -39,10 +41,10 @@ class ChildNotificationTask : public Task { ChildProcessHost::ChildProcessHost( - ProcessType type, MessageLoop* main_message_loop) - : ChildProcessInfo(type), + ProcessType type, ResourceDispatcherHost* resource_dispatcher_host) + : Receiver(type), ALLOW_THIS_IN_INITIALIZER_LIST(listener_(this)), - main_message_loop_(main_message_loop), + resource_dispatcher_host_(resource_dispatcher_host), opening_channel_(false), process_event_(NULL) { Singleton<ChildProcessList>::get()->push_back(this); @@ -99,7 +101,7 @@ bool ChildProcessHost::Send(IPC::Message* msg) { } void ChildProcessHost::Notify(NotificationType type) { - main_message_loop_->PostTask( + resource_dispatcher_host_->ui_loop()->PostTask( FROM_HERE, new ChildNotificationTask(type, this)); } @@ -138,7 +140,14 @@ void ChildProcessHost::ListenerHook::OnMessageReceived( logger->OnPreDispatchMessage(msg); #endif - host_->OnMessageReceived(msg); + bool msg_is_ok = true; + bool handled = host_->resource_dispatcher_host_->OnMessageReceived( + msg, host_, &msg_is_ok); + if (!handled) + host_->OnMessageReceived(msg); + + if (!msg_is_ok) + base::KillProcess(host_->handle(), ResultCodes::KILLED_BAD_MESSAGE, false); #ifdef IPC_MESSAGE_LOG_ENABLED if (logger->Enabled()) diff --git a/chrome/common/child_process_host.h b/chrome/common/child_process_host.h index 4f173fc..cef940c 100644 --- a/chrome/common/child_process_host.h +++ b/chrome/common/child_process_host.h @@ -12,22 +12,21 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "base/waitable_event_watcher.h" +#include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/common/child_process_info.h" #include "chrome/common/ipc_channel.h" -class MessageLoop; class NotificationType; // Plugins/workers and other child processes that live on the IO thread should // derive from this class. -class ChildProcessHost : public ChildProcessInfo, +class ChildProcessHost : public ResourceDispatcherHost::Receiver, public base::WaitableEventWatcher::Delegate, - public IPC::Channel::Listener, - public IPC::Message::Sender { + public IPC::Channel::Listener { public: virtual ~ChildProcessHost(); - // IPC::Message::Sender implementation: + // ResourceDispatcherHost::Receiver implementation: virtual bool Send(IPC::Message* msg); // The Iterator class allows iteration through either all child processes, or @@ -51,7 +50,8 @@ class ChildProcessHost : public ChildProcessInfo, }; protected: - ChildProcessHost(ProcessType type, MessageLoop* main_message_loop); + ChildProcessHost(ProcessType type, + ResourceDispatcherHost* resource_dispatcher_host); // Creates the IPC channel. Returns true iff it succeeded. bool CreateChannel(); @@ -93,7 +93,7 @@ class ChildProcessHost : public ChildProcessInfo, ListenerHook listener_; - MessageLoop* main_message_loop_; + ResourceDispatcherHost* resource_dispatcher_host_; // True while we're waiting the channel to be opened. bool opening_channel_; diff --git a/chrome/common/child_process_info.cc b/chrome/common/child_process_info.cc index 1521dab..5ef4469 100644 --- a/chrome/common/child_process_info.cc +++ b/chrome/common/child_process_info.cc @@ -60,6 +60,7 @@ ChildProcessInfo::ChildProcessInfo(ProcessType type) { // just a simple object that contains information about it. So add it to our // list of running processes. type_ = type; + pid_ = -1; } diff --git a/chrome/common/child_process_info.h b/chrome/common/child_process_info.h index eee468d..2af3e10 100644 --- a/chrome/common/child_process_info.h +++ b/chrome/common/child_process_info.h @@ -30,7 +30,13 @@ class ChildProcessInfo { // Getter to the process handle. base::ProcessHandle handle() const { return process_.handle(); } - int pid() const { return process_.pid(); } + int pid() const { + if (pid_ != -1) + return pid_; + + pid_ = process_.pid(); + return pid_; + } void SetProcessBackgrounded() const { process_.SetProcessBackgrounded(true); } void ReduceWorkingSet() const { process_.ReduceWorkingSet(); } @@ -46,6 +52,7 @@ class ChildProcessInfo { type_ = original.type_; name_ = original.name_; process_ = original.process_; + pid_ = original.pid_; } ChildProcessInfo& operator=(const ChildProcessInfo& original) { @@ -53,6 +60,7 @@ class ChildProcessInfo { type_ = original.type_; name_ = original.name_; process_ = original.process_; + pid_ = original.pid_; } return *this; } @@ -78,20 +86,20 @@ class ChildProcessInfo { protected: void set_type(ProcessType type) { type_ = type; } void set_name(const std::wstring& name) { name_ = name; } - void set_handle(base::ProcessHandle handle) { process_.set_handle(handle); } + void set_handle(base::ProcessHandle handle) { + process_.set_handle(handle); + pid_ = -1; + } // Derived objects need to use this constructor so we know what type we are. ChildProcessInfo(ProcessType type); private: - // By making the constructor private, we can ensure that ChildProcessInfo - // objects can only be created by creating objects derived from them (i.e. - // PluginProcessHost) or by using the copy constructor or assignment operator - // to create an object from the former. - ChildProcessInfo() { } + friend class ResourceDispatcherHostTest; ProcessType type_; std::wstring name_; + mutable int pid_; // Cache of the process id. // The handle to the process. mutable base::Process process_; diff --git a/chrome/common/resource_dispatcher.cc b/chrome/common/resource_dispatcher.cc index be45a38..f29fa24 100644 --- a/chrome/common/resource_dispatcher.cc +++ b/chrome/common/resource_dispatcher.cc @@ -242,7 +242,7 @@ ResourceDispatcher::~ResourceDispatcher() { // ResourceDispatcher implementation ------------------------------------------ bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) { - if (!IsResourceMessage(message)) { + if (!IsResourceDispatcherMessage(message)) { return false; } @@ -523,8 +523,8 @@ webkit_glue::ResourceLoaderBridge* ResourceDispatcher::CreateBridge( route_id); } - -bool ResourceDispatcher::IsResourceMessage(const IPC::Message& message) const { +bool ResourceDispatcher::IsResourceDispatcherMessage( + const IPC::Message& message) { switch (message.type()) { case ViewMsg_Resource_DownloadProgress::ID: case ViewMsg_Resource_UploadProgress::ID: diff --git a/chrome/common/resource_dispatcher.h b/chrome/common/resource_dispatcher.h index 5ea97e4..53fc665 100644 --- a/chrome/common/resource_dispatcher.h +++ b/chrome/common/resource_dispatcher.h @@ -64,10 +64,6 @@ class ResourceDispatcher { // Toggles the is_deferred attribute for the specified request. void SetDefersLoading(int request_id, bool value); - // Returns true if the message passed in is a resource related - // message. - bool IsResourceMessage(const IPC::Message& message) const; - private: friend class ResourceDispatcherTest; @@ -117,6 +113,9 @@ class ResourceDispatcher { // again in the deferred state. void FlushDeferredMessages(int request_id); + // Returns true if the message passed in is a resource related message. + static bool IsResourceDispatcherMessage(const IPC::Message& message); + IPC::Message::Sender* message_sender_; // All pending requests issued to the host |