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" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 virtual void OnChannelError(); | 81 virtual void OnChannelError(); |
82 | 82 |
83 // Called to inform the filter that the IPC channel will be destroyed. | 83 // Called to inform the filter that the IPC channel will be destroyed. |
84 // OnFilterRemoved is called immediately after this. | 84 // OnFilterRemoved is called immediately after this. |
85 virtual void OnChannelClosing(); | 85 virtual void OnChannelClosing(); |
86 | 86 |
87 // Return true to indicate that the message was handled, or false to let | 87 // Return true to indicate that the message was handled, or false to let |
88 // the message be handled in the default way. | 88 // the message be handled in the default way. |
89 virtual bool OnMessageReceived(const Message& message); | 89 virtual bool OnMessageReceived(const Message& message); |
90 | 90 |
| 91 // Called to query the Message classes supported by the filter. Return |
| 92 // false to indicate that all message types should reach the filter, or true |
| 93 // if the resulting contents of |supported_message_classes| may be used to |
| 94 // selectively offer messages of a particular class to the filter. |
| 95 virtual bool GetSupportedMessageClasses( |
| 96 std::vector<uint32>* supported_message_classes) const; |
| 97 |
91 protected: | 98 protected: |
92 virtual ~MessageFilter(); | 99 virtual ~MessageFilter(); |
93 | 100 |
94 private: | 101 private: |
95 friend class base::RefCountedThreadSafe<MessageFilter>; | 102 friend class base::RefCountedThreadSafe<MessageFilter>; |
96 }; | 103 }; |
97 | 104 |
98 // Initializes a channel proxy. The channel_handle and mode parameters are | 105 // Initializes a channel proxy. The channel_handle and mode parameters are |
99 // passed directly to the underlying IPC::Channel. The listener is called on | 106 // passed directly to the underlying IPC::Channel. The listener is called on |
100 // the thread that creates the ChannelProxy. The filter's OnMessageReceived | 107 // the thread that creates the ChannelProxy. The filter's OnMessageReceived |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; | 230 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; |
224 Listener* listener_; | 231 Listener* listener_; |
225 | 232 |
226 // List of filters. This is only accessed on the IPC thread. | 233 // List of filters. This is only accessed on the IPC thread. |
227 std::vector<scoped_refptr<MessageFilter> > filters_; | 234 std::vector<scoped_refptr<MessageFilter> > filters_; |
228 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; | 235 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; |
229 scoped_ptr<Channel> channel_; | 236 scoped_ptr<Channel> channel_; |
230 std::string channel_id_; | 237 std::string channel_id_; |
231 bool channel_connected_called_; | 238 bool channel_connected_called_; |
232 | 239 |
| 240 // Routes a given message to a proper subset of |filters_|, depending |
| 241 // on which message classes a filter might support. |
| 242 class MessageFilterRouter; |
| 243 scoped_ptr<MessageFilterRouter> message_filter_router_; |
| 244 |
233 // Holds filters between the AddFilter call on the listerner thread and the | 245 // Holds filters between the AddFilter call on the listerner thread and the |
234 // IPC thread when they're added to filters_. | 246 // IPC thread when they're added to filters_. |
235 std::vector<scoped_refptr<MessageFilter> > pending_filters_; | 247 std::vector<scoped_refptr<MessageFilter> > pending_filters_; |
236 // Lock for pending_filters_. | 248 // Lock for pending_filters_. |
237 base::Lock pending_filters_lock_; | 249 base::Lock pending_filters_lock_; |
238 | 250 |
239 // Cached copy of the peer process ID. Set on IPC but read on both IPC and | 251 // Cached copy of the peer process ID. Set on IPC but read on both IPC and |
240 // listener threads. | 252 // listener threads. |
241 base::ProcessId peer_pid_; | 253 base::ProcessId peer_pid_; |
242 }; | 254 }; |
243 | 255 |
244 Context* context() { return context_.get(); } | 256 Context* context() { return context_.get(); } |
245 | 257 |
246 private: | 258 private: |
247 friend class SendCallbackHelper; | 259 friend class SendCallbackHelper; |
248 | 260 |
249 // By maintaining this indirection (ref-counted) to our internal state, we | 261 // By maintaining this indirection (ref-counted) to our internal state, we |
250 // can safely be destroyed while the background thread continues to do stuff | 262 // can safely be destroyed while the background thread continues to do stuff |
251 // that involves this data. | 263 // that involves this data. |
252 scoped_refptr<Context> context_; | 264 scoped_refptr<Context> context_; |
253 | 265 |
254 // Whether the channel has been initialized. | 266 // Whether the channel has been initialized. |
255 bool did_init_; | 267 bool did_init_; |
256 }; | 268 }; |
257 | 269 |
258 } // namespace IPC | 270 } // namespace IPC |
259 | 271 |
260 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 272 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
OLD | NEW |