Chromium Code Reviews| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 // the consumer of IPC::ChannelProxy the ability to respond to incoming | 50 // the consumer of IPC::ChannelProxy the ability to respond to incoming |
| 51 // messages on this background thread instead of on their own thread, which may | 51 // messages on this background thread instead of on their own thread, which may |
| 52 // be bogged down with other processing. The result can be greatly improved | 52 // be bogged down with other processing. The result can be greatly improved |
| 53 // latency for messages that can be handled on a background thread. | 53 // latency for messages that can be handled on a background thread. |
| 54 // | 54 // |
| 55 // The consumer of IPC::ChannelProxy is responsible for allocating the Thread | 55 // The consumer of IPC::ChannelProxy is responsible for allocating the Thread |
| 56 // instance where the IPC::Channel will be created and operated. | 56 // instance where the IPC::Channel will be created and operated. |
| 57 // | 57 // |
| 58 class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { | 58 class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { |
| 59 public: | 59 public: |
| 60 // Interface for a filter to be imposed on outgoing messages which can | |
|
inferno
2015/03/05 18:46:48
All code ifdefed.
| |
| 61 // re-write the message. Used for testing. | |
| 62 class OutgoingMessageFilter { | |
| 63 public: | |
| 64 virtual Message* Rewrite(Message* message) = 0; | |
| 65 }; | |
| 66 | |
| 60 // Initializes a channel proxy. The channel_handle and mode parameters are | 67 // Initializes a channel proxy. The channel_handle and mode parameters are |
| 61 // passed directly to the underlying IPC::Channel. The listener is called on | 68 // passed directly to the underlying IPC::Channel. The listener is called on |
| 62 // the thread that creates the ChannelProxy. The filter's OnMessageReceived | 69 // the thread that creates the ChannelProxy. The filter's OnMessageReceived |
| 63 // method is called on the thread where the IPC::Channel is running. The | 70 // method is called on the thread where the IPC::Channel is running. The |
| 64 // filter may be null if the consumer is not interested in handling messages | 71 // filter may be null if the consumer is not interested in handling messages |
| 65 // on the background thread. Any message not handled by the filter will be | 72 // on the background thread. Any message not handled by the filter will be |
| 66 // dispatched to the listener. The given task runner correspond to a thread | 73 // dispatched to the listener. The given task runner correspond to a thread |
| 67 // on which IPC::Channel is created and used (e.g. IO thread). | 74 // on which IPC::Channel is created and used (e.g. IO thread). |
| 68 static scoped_ptr<ChannelProxy> Create( | 75 static scoped_ptr<ChannelProxy> Create( |
| 69 const IPC::ChannelHandle& channel_handle, | 76 const IPC::ChannelHandle& channel_handle, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 // Ordinarily, messages sent to the ChannelProxy are routed to the matching | 112 // Ordinarily, messages sent to the ChannelProxy are routed to the matching |
| 106 // listener on the worker thread. This API allows code to intercept messages | 113 // listener on the worker thread. This API allows code to intercept messages |
| 107 // before they are sent to the worker thread. | 114 // before they are sent to the worker thread. |
| 108 // If you call this before the target process is launched, then you're | 115 // If you call this before the target process is launched, then you're |
| 109 // guaranteed to not miss any messages. But if you call this anytime after, | 116 // guaranteed to not miss any messages. But if you call this anytime after, |
| 110 // then some messages might be missed since the filter is added internally on | 117 // then some messages might be missed since the filter is added internally on |
| 111 // the IO thread. | 118 // the IO thread. |
| 112 void AddFilter(MessageFilter* filter); | 119 void AddFilter(MessageFilter* filter); |
| 113 void RemoveFilter(MessageFilter* filter); | 120 void RemoveFilter(MessageFilter* filter); |
| 114 | 121 |
| 122 void set_outgoing_message_filter(OutgoingMessageFilter* filter) { | |
| 123 outgoing_message_filter_ = filter; | |
| 124 } | |
| 125 | |
| 115 // Set the task runner on which dispatched messages are posted. Both the new | 126 // Set the task runner on which dispatched messages are posted. Both the new |
| 116 // task runner and the existing task runner must run on the same thread, and | 127 // task runner and the existing task runner must run on the same thread, and |
| 117 // must belong to the calling thread. | 128 // must belong to the calling thread. |
| 118 void SetListenerTaskRunner( | 129 void SetListenerTaskRunner( |
| 119 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner); | 130 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner); |
| 120 | 131 |
| 121 // Called to clear the pointer to the IPC task runner when it's going away. | 132 // Called to clear the pointer to the IPC task runner when it's going away. |
| 122 void ClearIPCTaskRunner(); | 133 void ClearIPCTaskRunner(); |
| 123 | 134 |
| 124 // Get the process ID for the connected peer. | 135 // Get the process ID for the connected peer. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 // Lock for pending_filters_. | 236 // Lock for pending_filters_. |
| 226 base::Lock pending_filters_lock_; | 237 base::Lock pending_filters_lock_; |
| 227 | 238 |
| 228 // Cached copy of the peer process ID. Set on IPC but read on both IPC and | 239 // Cached copy of the peer process ID. Set on IPC but read on both IPC and |
| 229 // listener threads. | 240 // listener threads. |
| 230 base::ProcessId peer_pid_; | 241 base::ProcessId peer_pid_; |
| 231 }; | 242 }; |
| 232 | 243 |
| 233 Context* context() { return context_.get(); } | 244 Context* context() { return context_.get(); } |
| 234 | 245 |
| 246 OutgoingMessageFilter* outgoing_message_filter() { | |
|
inferno
2015/03/05 18:46:48
() const {
| |
| 247 return outgoing_message_filter_; | |
| 248 } | |
| 249 | |
| 235 private: | 250 private: |
| 236 friend class IpcSecurityTestUtil; | 251 friend class IpcSecurityTestUtil; |
| 237 | 252 |
| 238 // By maintaining this indirection (ref-counted) to our internal state, we | 253 // By maintaining this indirection (ref-counted) to our internal state, we |
| 239 // can safely be destroyed while the background thread continues to do stuff | 254 // can safely be destroyed while the background thread continues to do stuff |
| 240 // that involves this data. | 255 // that involves this data. |
| 241 scoped_refptr<Context> context_; | 256 scoped_refptr<Context> context_; |
| 242 | 257 |
| 243 // Whether the channel has been initialized. | 258 // Whether the channel has been initialized. |
| 244 bool did_init_; | 259 bool did_init_; |
| 260 | |
| 261 OutgoingMessageFilter* outgoing_message_filter_; | |
| 245 }; | 262 }; |
| 246 | 263 |
| 247 } // namespace IPC | 264 } // namespace IPC |
| 248 | 265 |
| 249 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 266 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
| OLD | NEW |