OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 IPC_IPC_CHANNEL_PROXY_H_ | 5 #ifndef IPC_IPC_CHANNEL_PROXY_H_ |
6 #define IPC_IPC_CHANNEL_PROXY_H_ | 6 #define IPC_IPC_CHANNEL_PROXY_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
14 #include "ipc/ipc_channel.h" | 14 #include "ipc/ipc_channel.h" |
15 #include "ipc/ipc_channel_handle.h" | 15 #include "ipc/ipc_channel_handle.h" |
16 #include "ipc/ipc_listener.h" | 16 #include "ipc/ipc_listener.h" |
| 17 #include "ipc/ipc_message_start.h" |
17 #include "ipc/ipc_sender.h" | 18 #include "ipc/ipc_sender.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
21 } | 22 } |
22 | 23 |
23 namespace IPC { | 24 namespace IPC { |
24 | 25 |
25 class SendCallbackHelper; | 26 class SendCallbackHelper; |
26 | 27 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 virtual void OnChannelError(); | 82 virtual void OnChannelError(); |
82 | 83 |
83 // Called to inform the filter that the IPC channel will be destroyed. | 84 // Called to inform the filter that the IPC channel will be destroyed. |
84 // OnFilterRemoved is called immediately after this. | 85 // OnFilterRemoved is called immediately after this. |
85 virtual void OnChannelClosing(); | 86 virtual void OnChannelClosing(); |
86 | 87 |
87 // Return true to indicate that the message was handled, or false to let | 88 // Return true to indicate that the message was handled, or false to let |
88 // the message be handled in the default way. | 89 // the message be handled in the default way. |
89 virtual bool OnMessageReceived(const Message& message); | 90 virtual bool OnMessageReceived(const Message& message); |
90 | 91 |
| 92 // Called to query the Message classes supported by the filter. Return |
| 93 // false to indicate that all message types should reach the filter, or true |
| 94 // if the resulting contents of |supported_message_classes| may be used to |
| 95 // selectively offer messages of a particular class to the filter. |
| 96 virtual bool GetSupportedMessageClasses( |
| 97 std::vector<uint32>* supported_message_classes) const; |
| 98 |
91 protected: | 99 protected: |
92 virtual ~MessageFilter(); | 100 virtual ~MessageFilter(); |
93 | 101 |
94 private: | 102 private: |
95 friend class base::RefCountedThreadSafe<MessageFilter>; | 103 friend class base::RefCountedThreadSafe<MessageFilter>; |
96 }; | 104 }; |
97 | 105 |
98 // Initializes a channel proxy. The channel_handle and mode parameters are | 106 // Initializes a channel proxy. The channel_handle and mode parameters are |
99 // passed directly to the underlying IPC::Channel. The listener is called on | 107 // passed directly to the underlying IPC::Channel. The listener is called on |
100 // the thread that creates the ChannelProxy. The filter's OnMessageReceived | 108 // the thread that creates the ChannelProxy. The filter's OnMessageReceived |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 225 |
218 // Methods called on the listener thread. | 226 // Methods called on the listener thread. |
219 void AddFilter(MessageFilter* filter); | 227 void AddFilter(MessageFilter* filter); |
220 void OnDispatchConnected(); | 228 void OnDispatchConnected(); |
221 void OnDispatchError(); | 229 void OnDispatchError(); |
222 | 230 |
223 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; | 231 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; |
224 Listener* listener_; | 232 Listener* listener_; |
225 | 233 |
226 // List of filters. This is only accessed on the IPC thread. | 234 // List of filters. This is only accessed on the IPC thread. |
227 std::vector<scoped_refptr<MessageFilter> > filters_; | 235 std::vector<scoped_refptr<MessageFilter> > all_filters_; |
228 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; | 236 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; |
229 scoped_ptr<Channel> channel_; | 237 scoped_ptr<Channel> channel_; |
230 std::string channel_id_; | 238 std::string channel_id_; |
231 bool channel_connected_called_; | 239 bool channel_connected_called_; |
232 | 240 |
| 241 // List of global and selective filters; a given filter from |all_filters_| |
| 242 // will exists in either |message_global_filters_| OR |
| 243 // |message_class_filters_|, but not both. |
| 244 // Note that |message_global_filters_| will be given first offering of any |
| 245 // given message. It's the filter implementer and installer's |
| 246 // responsibility to ensure that a filter is either global or selective to |
| 247 // ensure proper message filtering order. |
| 248 std::vector<MessageFilter*> message_global_filters_; |
| 249 std::vector<MessageFilter*> message_class_filters_[LastIPCMsgStart]; |
| 250 |
233 // Holds filters between the AddFilter call on the listerner thread and the | 251 // Holds filters between the AddFilter call on the listerner thread and the |
234 // IPC thread when they're added to filters_. | 252 // IPC thread when they're added to filters_. |
235 std::vector<scoped_refptr<MessageFilter> > pending_filters_; | 253 std::vector<scoped_refptr<MessageFilter> > pending_filters_; |
236 // Lock for pending_filters_. | 254 // Lock for pending_filters_. |
237 base::Lock pending_filters_lock_; | 255 base::Lock pending_filters_lock_; |
238 | 256 |
239 // Cached copy of the peer process ID. Set on IPC but read on both IPC and | 257 // Cached copy of the peer process ID. Set on IPC but read on both IPC and |
240 // listener threads. | 258 // listener threads. |
241 base::ProcessId peer_pid_; | 259 base::ProcessId peer_pid_; |
242 }; | 260 }; |
243 | 261 |
244 Context* context() { return context_.get(); } | 262 Context* context() { return context_.get(); } |
245 | 263 |
246 private: | 264 private: |
247 friend class SendCallbackHelper; | 265 friend class SendCallbackHelper; |
248 | 266 |
249 // By maintaining this indirection (ref-counted) to our internal state, we | 267 // By maintaining this indirection (ref-counted) to our internal state, we |
250 // can safely be destroyed while the background thread continues to do stuff | 268 // can safely be destroyed while the background thread continues to do stuff |
251 // that involves this data. | 269 // that involves this data. |
252 scoped_refptr<Context> context_; | 270 scoped_refptr<Context> context_; |
253 | 271 |
254 // Whether the channel has been initialized. | 272 // Whether the channel has been initialized. |
255 bool did_init_; | 273 bool did_init_; |
256 }; | 274 }; |
257 | 275 |
258 } // namespace IPC | 276 } // namespace IPC |
259 | 277 |
260 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 278 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
OLD | NEW |