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 <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "ipc/ipc_channel.h" | 20 #include "ipc/ipc_channel.h" |
21 #include "ipc/ipc_channel_handle.h" | 21 #include "ipc/ipc_channel_handle.h" |
22 #include "ipc/ipc_listener.h" | 22 #include "ipc/ipc_listener.h" |
23 #include "ipc/ipc_sender.h" | 23 #include "ipc/ipc_sender.h" |
24 #include "mojo/public/cpp/bindings/associated_group.h" | 24 #include "mojo/public/cpp/bindings/associated_group.h" |
25 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" | |
25 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 26 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
26 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 27 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
28 #include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h" | |
27 | 29 |
28 namespace base { | 30 namespace base { |
29 class SingleThreadTaskRunner; | 31 class SingleThreadTaskRunner; |
30 } | 32 } |
31 | 33 |
32 namespace IPC { | 34 namespace IPC { |
33 | 35 |
34 class ChannelFactory; | 36 class ChannelFactory; |
35 class MessageFilter; | 37 class MessageFilter; |
36 class MessageFilterRouter; | 38 class MessageFilterRouter; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 mojo::MakeRequest(proxy, GetAssociatedGroup()); | 204 mojo::MakeRequest(proxy, GetAssociatedGroup()); |
203 GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle()); | 205 GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle()); |
204 } | 206 } |
205 | 207 |
206 #if defined(ENABLE_IPC_FUZZER) | 208 #if defined(ENABLE_IPC_FUZZER) |
207 void set_outgoing_message_filter(OutgoingMessageFilter* filter) { | 209 void set_outgoing_message_filter(OutgoingMessageFilter* filter) { |
208 outgoing_message_filter_ = filter; | 210 outgoing_message_filter_ = filter; |
209 } | 211 } |
210 #endif | 212 #endif |
211 | 213 |
214 // Creates a ThreadSafeAssociatedInterfacePtr for |Interface|. This object | |
215 // may be used to send messages on the interface from any thread and those | |
216 // messages will remain ordered with respect to other messages sent on the | |
217 // same thread over other ThreadSafeAssociatedInterfacePtrs associated with | |
218 // the same Channel. | |
212 template <typename Interface> | 219 template <typename Interface> |
213 using AssociatedInterfaceRetrievedCallback = | 220 void GetThreadSafeRemoteAssociatedInterface( |
yzshen1
2017/02/01 18:57:55
I guess the change I proposed is orthogonal:
I am
| |
214 base::Callback<void(mojo::AssociatedInterfacePtr<Interface>)>; | 221 scoped_refptr<mojo::ThreadSafeAssociatedInterfacePtr<Interface>>* |
215 // Creates an AssociatedInterfacePtr to |Interface| on the IO thread and | 222 out_ptr) { |
216 // passes it to |callback|, also invoked on the IO thread. | 223 DCHECK(GetAssociatedGroup()); |
217 template <typename Interface> | 224 mojo::AssociatedInterfacePtr<Interface> ptr; |
218 void RetrieveAssociatedInterfaceOnIOThread( | 225 mojo::AssociatedInterfaceRequest<Interface> request = |
219 const AssociatedInterfaceRetrievedCallback<Interface>& callback) { | 226 mojo::MakeRequest(&ptr, GetAssociatedGroup()); |
220 context_->ipc_task_runner()->PostTask( | 227 *out_ptr = mojo::ThreadSafeAssociatedInterfacePtr<Interface>::Create( |
221 FROM_HERE, base::Bind(&Context::RetrieveAssociatedInterface<Interface>, | 228 ptr.PassInterface(), ipc_task_runner()); |
222 context_, callback)); | 229 GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle()); |
223 } | 230 } |
224 | 231 |
225 base::SingleThreadTaskRunner* ipc_task_runner() const { | 232 base::SingleThreadTaskRunner* ipc_task_runner() const { |
226 return context_->ipc_task_runner(); | 233 return context_->ipc_task_runner(); |
227 } | 234 } |
228 | 235 |
229 // Called to clear the pointer to the IPC task runner when it's going away. | 236 // Called to clear the pointer to the IPC task runner when it's going away. |
230 void ClearIPCTaskRunner(); | 237 void ClearIPCTaskRunner(); |
231 | 238 |
232 protected: | 239 protected: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 friend class ChannelProxy; | 299 friend class ChannelProxy; |
293 friend class IpcSecurityTestUtil; | 300 friend class IpcSecurityTestUtil; |
294 | 301 |
295 // Create the Channel | 302 // Create the Channel |
296 void CreateChannel(std::unique_ptr<ChannelFactory> factory); | 303 void CreateChannel(std::unique_ptr<ChannelFactory> factory); |
297 | 304 |
298 // Methods called on the IO thread. | 305 // Methods called on the IO thread. |
299 void OnSendMessage(std::unique_ptr<Message> message_ptr); | 306 void OnSendMessage(std::unique_ptr<Message> message_ptr); |
300 void OnAddFilter(); | 307 void OnAddFilter(); |
301 void OnRemoveFilter(MessageFilter* filter); | 308 void OnRemoveFilter(MessageFilter* filter); |
302 template <typename Interface> | |
303 void RetrieveAssociatedInterface( | |
304 const AssociatedInterfaceRetrievedCallback<Interface>& callback) { | |
305 mojo::AssociatedInterfacePtr<Interface> interface_ptr; | |
306 channel_->GetAssociatedInterfaceSupport()->GetRemoteAssociatedInterface( | |
307 &interface_ptr); | |
308 callback.Run(std::move(interface_ptr)); | |
309 } | |
310 | 309 |
311 // Methods called on the listener thread. | 310 // Methods called on the listener thread. |
312 void AddFilter(MessageFilter* filter); | 311 void AddFilter(MessageFilter* filter); |
313 void OnDispatchConnected(); | 312 void OnDispatchConnected(); |
314 void OnDispatchError(); | 313 void OnDispatchError(); |
315 void OnDispatchBadMessage(const Message& message); | 314 void OnDispatchBadMessage(const Message& message); |
316 void OnDispatchAssociatedInterfaceRequest( | 315 void OnDispatchAssociatedInterfaceRequest( |
317 const std::string& interface_name, | 316 const std::string& interface_name, |
318 mojo::ScopedInterfaceEndpointHandle handle); | 317 mojo::ScopedInterfaceEndpointHandle handle); |
319 | 318 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 bool did_init_; | 402 bool did_init_; |
404 | 403 |
405 #if defined(ENABLE_IPC_FUZZER) | 404 #if defined(ENABLE_IPC_FUZZER) |
406 OutgoingMessageFilter* outgoing_message_filter_; | 405 OutgoingMessageFilter* outgoing_message_filter_; |
407 #endif | 406 #endif |
408 }; | 407 }; |
409 | 408 |
410 } // namespace IPC | 409 } // namespace IPC |
411 | 410 |
412 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 411 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
OLD | NEW |