OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_BROWSER_IO_MESSAGE_FILTER_H_ | 5 #ifndef CHROME_BROWSER_BROWSER_MESSAGE_FILTER_H_ |
6 #define CHROME_BROWSER_BROWSER_IO_MESSAGE_FILTER_H_ | 6 #define CHROME_BROWSER_BROWSER_MESSAGE_FILTER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/process.h" | 9 #include "base/process.h" |
10 #include "chrome/browser/browser_thread.h" | |
10 #include "ipc/ipc_channel_proxy.h" | 11 #include "ipc/ipc_channel_proxy.h" |
11 | 12 |
12 // Base class for message filters in the browser process that reside on the IO | 13 // Base class for message filters in the browser process. You can receive and |
13 // thread. | 14 // send messages on any thread. |
14 class BrowserIOMessageFilter : public IPC::ChannelProxy::MessageFilter, | 15 class BrowserMessageFilter : public IPC::ChannelProxy::MessageFilter, |
15 public IPC::Message::Sender { | 16 public IPC::Message::Sender { |
16 public: | 17 public: |
17 BrowserIOMessageFilter(); | 18 BrowserMessageFilter(); |
18 virtual ~BrowserIOMessageFilter(); | 19 virtual ~BrowserMessageFilter(); |
19 | 20 |
20 // IPC::ChannelProxy::MessageFilter methods. If you override them, make sure | 21 // IPC::ChannelProxy::MessageFilter methods. If you override them, make sure |
21 // to call them as well. | 22 // to call them as well. These are always called on the IO thread. |
22 virtual void OnFilterAdded(IPC::Channel* channel); | 23 virtual void OnFilterAdded(IPC::Channel* channel); |
23 virtual void OnChannelClosing(); | 24 virtual void OnChannelClosing(); |
24 virtual void OnChannelConnected(int32 peer_pid); | 25 virtual void OnChannelConnected(int32 peer_pid); |
26 // You can't override this, override the other version below. | |
27 bool OnMessageReceived(const IPC::Message& message); | |
Matt Perry
2010/12/09 18:20:06
FYI I don't think the compiler actually prevents y
jam
2010/12/09 22:44:51
you're right. i tried it out with private and als
| |
25 | 28 |
26 // IPC::Message::Sender implementation: | 29 // IPC::Message::Sender implementation. Can be called on any thread. Can't |
27 virtual bool Send(IPC::Message* msg); | 30 // send sync messages (since we don't want to block the browser on any other |
31 // process). | |
32 virtual bool Send(IPC::Message* message); | |
33 | |
34 // This allows the message handler to be called on a different thread for the | |
35 // given message. If you want to handle the message on a different thread, | |
36 // return true and set |thread| to the thread id. Otherwise return false. | |
37 virtual bool ShouldHandleMessageOnThread(const IPC::Message& message, | |
38 BrowserThread::ID* thread); | |
39 | |
40 // Override this to receive messages. | |
41 // Your function will normally be called on the IO thread. However, if your | |
42 // HandleMessageOnThread returns a different thread for this message, your | |
43 // function will be called on the requested thread. | |
44 virtual bool OnMessageReceived(const IPC::Message& message, | |
45 bool* message_was_ok) = 0; | |
28 | 46 |
29 protected: | 47 protected: |
48 // Can be called on any thread, after OnChannelConnected is called. | |
30 base::ProcessHandle peer_handle() { return peer_handle_; } | 49 base::ProcessHandle peer_handle() { return peer_handle_; } |
31 | 50 |
32 // Call this if a message couldn't be deserialized. This kills the renderer. | 51 // Call this if a message couldn't be deserialized. This kills the renderer. |
52 // Can be called on any thread. | |
33 void BadMessageReceived(uint32 msg_type); | 53 void BadMessageReceived(uint32 msg_type); |
34 | 54 |
35 private: | 55 private: |
56 // Used for dispatching a message to the derived class. | |
57 bool DispatchMessage(const IPC::Message& message); | |
58 | |
36 IPC::Channel* channel_; | 59 IPC::Channel* channel_; |
37 base::ProcessHandle peer_handle_; | 60 base::ProcessHandle peer_handle_; |
38 }; | 61 }; |
39 | 62 |
40 #endif // CHROME_BROWSER_BROWSER_IO_MESSAGE_FILTER_H_ | 63 #endif // CHROME_BROWSER_BROWSER_MESSAGE_FILTER_H_ |
OLD | NEW |