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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // Close the IPC::Channel. This operation completes asynchronously, once the | 116 // Close the IPC::Channel. This operation completes asynchronously, once the |
117 // background thread processes the command to close the channel. It is ok to | 117 // background thread processes the command to close the channel. It is ok to |
118 // call this method multiple times. Redundant calls are ignored. | 118 // call this method multiple times. Redundant calls are ignored. |
119 // | 119 // |
120 // WARNING: MessageFilter objects held by the ChannelProxy is also | 120 // WARNING: MessageFilter objects held by the ChannelProxy is also |
121 // released asynchronously, and it may in fact have its final reference | 121 // released asynchronously, and it may in fact have its final reference |
122 // released on the background thread. The caller should be careful to deal | 122 // released on the background thread. The caller should be careful to deal |
123 // with / allow for this possibility. | 123 // with / allow for this possibility. |
124 void Close(); | 124 void Close(); |
125 | 125 |
126 // Send a message asynchronously. The message is routed to the background | 126 // DEPRECATED: Please use either SendNow or SendOnIPCThread to make ordering |
127 // thread where it is passed to the IPC::Channel's Send method. | 127 // expectations explicit. |
| 128 // |
| 129 // This is an alias for for SendOnIPCThread. |
128 bool Send(Message* message) override; | 130 bool Send(Message* message) override; |
129 | 131 |
| 132 // Send a message as soon as possible. This method may send the message |
| 133 // immediately, or it may defer and send on the IPC thread. Use this when you |
| 134 // you don't care about strict ordering of the send operation with respect to |
| 135 // tasks on the IPC thread. This is most commonly what you want. |
| 136 virtual bool SendNow(std::unique_ptr<Message> message); |
| 137 |
| 138 // Send a message from the IPC thread. This immediately posts a task to the |
| 139 // IPC thread task runner to send the message. Use this when you're posting |
| 140 // other related tasks to the IPC thread and you need to guarantee that the |
| 141 // send operation is ordered with respect to those tasks. |
| 142 virtual bool SendOnIPCThread(std::unique_ptr<Message> message); |
| 143 |
130 // Used to intercept messages as they are received on the background thread. | 144 // Used to intercept messages as they are received on the background thread. |
131 // | 145 // |
132 // Ordinarily, messages sent to the ChannelProxy are routed to the matching | 146 // Ordinarily, messages sent to the ChannelProxy are routed to the matching |
133 // listener on the worker thread. This API allows code to intercept messages | 147 // listener on the worker thread. This API allows code to intercept messages |
134 // before they are sent to the worker thread. | 148 // before they are sent to the worker thread. |
135 // If you call this before the target process is launched, then you're | 149 // If you call this before the target process is launched, then you're |
136 // guaranteed to not miss any messages. But if you call this anytime after, | 150 // guaranteed to not miss any messages. But if you call this anytime after, |
137 // then some messages might be missed since the filter is added internally on | 151 // then some messages might be missed since the filter is added internally on |
138 // the IO thread. | 152 // the IO thread. |
139 void AddFilter(MessageFilter* filter); | 153 void AddFilter(MessageFilter* filter); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 void ClearIPCTaskRunner(); | 188 void ClearIPCTaskRunner(); |
175 base::SingleThreadTaskRunner* ipc_task_runner() const { | 189 base::SingleThreadTaskRunner* ipc_task_runner() const { |
176 return ipc_task_runner_.get(); | 190 return ipc_task_runner_.get(); |
177 } | 191 } |
178 const std::string& channel_id() const { return channel_id_; } | 192 const std::string& channel_id() const { return channel_id_; } |
179 | 193 |
180 // Dispatches a message on the listener thread. | 194 // Dispatches a message on the listener thread. |
181 void OnDispatchMessage(const Message& message); | 195 void OnDispatchMessage(const Message& message); |
182 | 196 |
183 // Sends |message| from appropriate thread. | 197 // Sends |message| from appropriate thread. |
184 void Send(Message* message); | 198 bool Send(std::unique_ptr<Message> message, bool force_io_thread); |
185 | 199 |
186 // Indicates if the underlying channel's Send is thread-safe. | 200 // Indicates if the underlying channel's Send is thread-safe. |
187 bool IsChannelSendThreadSafe() const; | 201 bool IsChannelSendThreadSafe() const; |
188 | 202 |
189 protected: | 203 protected: |
190 friend class base::RefCountedThreadSafe<Context>; | 204 friend class base::RefCountedThreadSafe<Context>; |
191 ~Context() override; | 205 ~Context() override; |
192 | 206 |
193 // IPC::Listener methods: | 207 // IPC::Listener methods: |
194 bool OnMessageReceived(const Message& message) override; | 208 bool OnMessageReceived(const Message& message) override; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 void OnSendMessage(std::unique_ptr<Message> message_ptr); | 242 void OnSendMessage(std::unique_ptr<Message> message_ptr); |
229 void OnAddFilter(); | 243 void OnAddFilter(); |
230 void OnRemoveFilter(MessageFilter* filter); | 244 void OnRemoveFilter(MessageFilter* filter); |
231 | 245 |
232 // Methods called on the listener thread. | 246 // Methods called on the listener thread. |
233 void AddFilter(MessageFilter* filter); | 247 void AddFilter(MessageFilter* filter); |
234 void OnDispatchConnected(); | 248 void OnDispatchConnected(); |
235 void OnDispatchError(); | 249 void OnDispatchError(); |
236 void OnDispatchBadMessage(const Message& message); | 250 void OnDispatchBadMessage(const Message& message); |
237 | 251 |
238 void SendFromThisThread(Message* message); | |
239 void ClearChannel(); | 252 void ClearChannel(); |
240 | 253 |
241 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; | 254 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; |
242 Listener* listener_; | 255 Listener* listener_; |
243 | 256 |
244 // List of filters. This is only accessed on the IPC thread. | 257 // List of filters. This is only accessed on the IPC thread. |
245 std::vector<scoped_refptr<MessageFilter> > filters_; | 258 std::vector<scoped_refptr<MessageFilter> > filters_; |
246 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; | 259 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; |
247 | 260 |
248 // Note, channel_ may be set on the Listener thread or the IPC thread. | 261 // Note, channel_ may be set on the Listener thread or the IPC thread. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 302 |
290 protected: | 303 protected: |
291 bool did_init() const { return did_init_; } | 304 bool did_init() const { return did_init_; } |
292 | 305 |
293 private: | 306 private: |
294 friend class IpcSecurityTestUtil; | 307 friend class IpcSecurityTestUtil; |
295 | 308 |
296 // Always called once immediately after Init. | 309 // Always called once immediately after Init. |
297 virtual void OnChannelInit(); | 310 virtual void OnChannelInit(); |
298 | 311 |
| 312 bool SendImpl(std::unique_ptr<Message> message, bool force_io_thread); |
| 313 |
299 // By maintaining this indirection (ref-counted) to our internal state, we | 314 // By maintaining this indirection (ref-counted) to our internal state, we |
300 // can safely be destroyed while the background thread continues to do stuff | 315 // can safely be destroyed while the background thread continues to do stuff |
301 // that involves this data. | 316 // that involves this data. |
302 scoped_refptr<Context> context_; | 317 scoped_refptr<Context> context_; |
303 | 318 |
304 // Whether the channel has been initialized. | 319 // Whether the channel has been initialized. |
305 bool did_init_; | 320 bool did_init_; |
306 | 321 |
307 #if defined(ENABLE_IPC_FUZZER) | 322 #if defined(ENABLE_IPC_FUZZER) |
308 OutgoingMessageFilter* outgoing_message_filter_; | 323 OutgoingMessageFilter* outgoing_message_filter_; |
309 #endif | 324 #endif |
310 }; | 325 }; |
311 | 326 |
312 } // namespace IPC | 327 } // namespace IPC |
313 | 328 |
314 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 329 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
OLD | NEW |