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 bool SendNow(Message* message); | |
piman
2016/05/20 00:35:41
drive-by: it would be nice to take this occasion t
| |
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 bool SendOnIPCThread(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(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); | 252 bool SendFromThisThread(Message* message); |
239 void ClearChannel(); | 253 void ClearChannel(); |
240 | 254 |
241 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; | 255 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; |
242 Listener* listener_; | 256 Listener* listener_; |
243 | 257 |
244 // List of filters. This is only accessed on the IPC thread. | 258 // List of filters. This is only accessed on the IPC thread. |
245 std::vector<scoped_refptr<MessageFilter> > filters_; | 259 std::vector<scoped_refptr<MessageFilter> > filters_; |
246 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; | 260 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; |
247 | 261 |
248 // Note, channel_ may be set on the Listener thread or the IPC thread. | 262 // 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 | 303 |
290 protected: | 304 protected: |
291 bool did_init() const { return did_init_; } | 305 bool did_init() const { return did_init_; } |
292 | 306 |
293 private: | 307 private: |
294 friend class IpcSecurityTestUtil; | 308 friend class IpcSecurityTestUtil; |
295 | 309 |
296 // Always called once immediately after Init. | 310 // Always called once immediately after Init. |
297 virtual void OnChannelInit(); | 311 virtual void OnChannelInit(); |
298 | 312 |
313 bool SendImpl(Message* message, bool force_io_thread); | |
314 | |
299 // By maintaining this indirection (ref-counted) to our internal state, we | 315 // By maintaining this indirection (ref-counted) to our internal state, we |
300 // can safely be destroyed while the background thread continues to do stuff | 316 // can safely be destroyed while the background thread continues to do stuff |
301 // that involves this data. | 317 // that involves this data. |
302 scoped_refptr<Context> context_; | 318 scoped_refptr<Context> context_; |
303 | 319 |
304 // Whether the channel has been initialized. | 320 // Whether the channel has been initialized. |
305 bool did_init_; | 321 bool did_init_; |
306 | 322 |
307 #if defined(ENABLE_IPC_FUZZER) | 323 #if defined(ENABLE_IPC_FUZZER) |
308 OutgoingMessageFilter* outgoing_message_filter_; | 324 OutgoingMessageFilter* outgoing_message_filter_; |
309 #endif | 325 #endif |
310 }; | 326 }; |
311 | 327 |
312 } // namespace IPC | 328 } // namespace IPC |
313 | 329 |
314 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 330 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
OLD | NEW |