diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-02 19:16:07 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-02 19:16:07 +0000 |
commit | 4b580bf3020b1e0eaf5b7efad50896b4c62474c5 (patch) | |
tree | 94f893bf3422dccda5e4bc05e4f8b8cca0d62638 /ipc/ipc_channel_proxy.h | |
parent | e669998f4edaa156aafbe2fb93b3e3dae1ebd06c (diff) | |
download | chromium_src-4b580bf3020b1e0eaf5b7efad50896b4c62474c5.zip chromium_src-4b580bf3020b1e0eaf5b7efad50896b4c62474c5.tar.gz chromium_src-4b580bf3020b1e0eaf5b7efad50896b4c62474c5.tar.bz2 |
Add a base class for objects that want to filter messages on the IO thread. I'll switch the filters to it in future separate changes.
I've also taken out the special case for an initial filter from the IPC classes. The reason it existed was that there was a race condition of some messages not being filtered if a filter is added after construction but before launching the peer process. Taking it out allows us to add more than one filter and makes things a little cleaner.
Review URL: http://codereview.chromium.org/5513001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68043 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_channel_proxy.h')
-rw-r--r-- | ipc/ipc_channel_proxy.h | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h index 53a39b4..a85841d 100644 --- a/ipc/ipc_channel_proxy.h +++ b/ipc/ipc_channel_proxy.h @@ -8,6 +8,7 @@ #include <vector> +#include "base/lock.h" #include "base/ref_counted.h" #include "ipc/ipc_channel.h" @@ -104,8 +105,9 @@ class ChannelProxy : public Message::Sender { // on the background thread. Any message not handled by the filter will be // dispatched to the listener. The given message loop indicates where the // IPC::Channel should be created. - ChannelProxy(const std::string& channel_id, Channel::Mode mode, - Channel::Listener* listener, MessageFilter* filter, + ChannelProxy(const std::string& channel_id, + Channel::Mode mode, + Channel::Listener* listener, MessageLoop* ipc_thread_loop); virtual ~ChannelProxy(); @@ -129,6 +131,10 @@ class ChannelProxy : public Message::Sender { // Ordinarily, messages sent to the ChannelProxy are routed to the matching // listener on the worker thread. This API allows code to intercept messages // before they are sent to the worker thread. + // If you call this before the target process is launched, then you're + // guaranteed to not miss any messages. But if you call this anytime after, + // then some messages might be missed since the filter is added internally on + // the IO thread. void AddFilter(MessageFilter* filter); void RemoveFilter(MessageFilter* filter); @@ -147,16 +153,17 @@ class ChannelProxy : public Message::Sender { // A subclass uses this constructor if it needs to add more information // to the internal state. If create_pipe_now is true, the pipe is created // immediately. Otherwise it's created on the IO thread. - ChannelProxy(const std::string& channel_id, Channel::Mode mode, - MessageLoop* ipc_thread_loop, Context* context, + ChannelProxy(const std::string& channel_id, + Channel::Mode mode, + MessageLoop* ipc_thread_loop, + Context* context, bool create_pipe_now); // Used internally to hold state that is referenced on the IPC thread. class Context : public base::RefCountedThreadSafe<Context>, public Channel::Listener { public: - Context(Channel::Listener* listener, MessageFilter* filter, - MessageLoop* ipc_thread); + Context(Channel::Listener* listener, MessageLoop* ipc_thread); void ClearIPCMessageLoop() { ipc_message_loop_ = NULL; } MessageLoop* ipc_message_loop() const { return ipc_message_loop_; } const std::string& channel_id() const { return channel_id_; } @@ -196,10 +203,13 @@ class ChannelProxy : public Message::Sender { // Create the Channel void CreateChannel(const std::string& id, const Channel::Mode& mode); - // Methods called via InvokeLater: + // Methods called on the IO thread. void OnSendMessage(Message* message_ptr); - void OnAddFilter(MessageFilter* filter); + void OnAddFilter(); void OnRemoveFilter(MessageFilter* filter); + + // Methods called on the listener thread. + void AddFilter(MessageFilter* filter); void OnDispatchConnected(); void OnDispatchError(); @@ -213,6 +223,12 @@ class ChannelProxy : public Message::Sender { std::string channel_id_; int peer_pid_; bool channel_connected_called_; + + // Holds filters between the AddFilter call on the listerner thread and the + // IPC thread when they're added to filters_. + std::vector<scoped_refptr<MessageFilter> > pending_filters_; + // Lock for pending_filters_. + Lock pending_filters_lock_; }; Context* context() { return context_; } |