Chromium Code Reviews| Index: chrome/browser/browser_message_filter.h |
| =================================================================== |
| --- chrome/browser/browser_message_filter.h (revision 68139) |
| +++ chrome/browser/browser_message_filter.h (working copy) |
| @@ -2,39 +2,62 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef CHROME_BROWSER_BROWSER_IO_MESSAGE_FILTER_H_ |
| -#define CHROME_BROWSER_BROWSER_IO_MESSAGE_FILTER_H_ |
| +#ifndef CHROME_BROWSER_BROWSER_MESSAGE_FILTER_H_ |
| +#define CHROME_BROWSER_BROWSER_MESSAGE_FILTER_H_ |
| #pragma once |
| #include "base/process.h" |
| +#include "chrome/browser/browser_thread.h" |
| #include "ipc/ipc_channel_proxy.h" |
| -// Base class for message filters in the browser process that reside on the IO |
| -// thread. |
| -class BrowserIOMessageFilter : public IPC::ChannelProxy::MessageFilter, |
| - public IPC::Message::Sender { |
| +// Base class for message filters in the browser process. You can receive and |
| +// send messages on any thread. |
| +class BrowserMessageFilter : public IPC::ChannelProxy::MessageFilter, |
| + public IPC::Message::Sender { |
| public: |
| - BrowserIOMessageFilter(); |
| - virtual ~BrowserIOMessageFilter(); |
| + BrowserMessageFilter(); |
| + virtual ~BrowserMessageFilter(); |
| // IPC::ChannelProxy::MessageFilter methods. If you override them, make sure |
| - // to call them as well. |
| + // to call them as well. These are always called on the IO thread. |
| virtual void OnFilterAdded(IPC::Channel* channel); |
| virtual void OnChannelClosing(); |
| virtual void OnChannelConnected(int32 peer_pid); |
| + // DON'T OVERRIDE THIS! Override the other version below. |
| + virtual bool OnMessageReceived(const IPC::Message& message); |
| - // IPC::Message::Sender implementation: |
| - virtual bool Send(IPC::Message* msg); |
| + // IPC::Message::Sender implementation. Can be called on any thread. Can't |
| + // send sync messages (since we don't want to block the browser on any other |
| + // process). |
| + virtual bool Send(IPC::Message* message); |
| + // This allows the message handler to be called on a different thread for the |
| + // given message. If you want to handle the message on a different thread, |
| + // change |thread| to the thread id. Otherwise leave it alone. |
|
brettw
2010/12/09 23:44:12
Can you give a little more detail here? I think wh
jam
2010/12/10 01:03:53
Thanks, OverrideThreadForMessage is clearer. swit
|
| + virtual void HandleMessageOnThread(const IPC::Message& message, |
| + BrowserThread::ID* thread); |
| + |
| + // Override this to receive messages. |
| + // Your function will normally be called on the IO thread. However, if your |
| + // HandleMessageOnThread modifies the thread used to dispatch the message, |
| + // your function will be called on the requested thread. |
| + virtual bool OnMessageReceived(const IPC::Message& message, |
| + bool* message_was_ok) = 0; |
| + |
| protected: |
| + // Can be called on any thread, after OnChannelConnected is called. |
| base::ProcessHandle peer_handle() { return peer_handle_; } |
| // Call this if a message couldn't be deserialized. This kills the renderer. |
| + // Can be called on any thread. |
| void BadMessageReceived(uint32 msg_type); |
| private: |
| + // Used for dispatching a message to the derived class. |
|
brettw
2010/12/09 23:44:12
Google comment style: "Dispatches a message to the
|
| + bool DispatchMessage(const IPC::Message& message); |
| + |
| IPC::Channel* channel_; |
| base::ProcessHandle peer_handle_; |
| }; |
| -#endif // CHROME_BROWSER_BROWSER_IO_MESSAGE_FILTER_H_ |
| +#endif // CHROME_BROWSER_BROWSER_MESSAGE_FILTER_H_ |