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_H_ | 5 #ifndef IPC_IPC_CHANNEL_H_ |
6 #define IPC_IPC_CHANNEL_H_ | 6 #define IPC_IPC_CHANNEL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/process/process.h" | 17 #include "base/process/process.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "ipc/ipc.mojom.h" | 21 #include "ipc/ipc.mojom.h" |
22 #include "ipc/ipc_channel_handle.h" | 22 #include "ipc/ipc_channel_handle.h" |
23 #include "ipc/ipc_message.h" | 23 #include "ipc/ipc_message.h" |
24 #include "ipc/ipc_sender.h" | 24 #include "ipc/ipc_sender.h" |
25 #include "mojo/public/cpp/bindings/associated_group.h" | |
26 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" | 25 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
27 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 26 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
28 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 27 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
29 #include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h" | 28 #include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h" |
30 | 29 |
31 #if defined(OS_POSIX) | 30 #if defined(OS_POSIX) |
32 #include <sys/types.h> | 31 #include <sys/types.h> |
33 #endif | 32 #endif |
34 | 33 |
35 namespace IPC { | 34 namespace IPC { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 84 |
86 // Helper interface a Channel may implement to expose support for associated | 85 // Helper interface a Channel may implement to expose support for associated |
87 // Mojo interfaces. | 86 // Mojo interfaces. |
88 class IPC_EXPORT AssociatedInterfaceSupport { | 87 class IPC_EXPORT AssociatedInterfaceSupport { |
89 public: | 88 public: |
90 using GenericAssociatedInterfaceFactory = | 89 using GenericAssociatedInterfaceFactory = |
91 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>; | 90 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>; |
92 | 91 |
93 virtual ~AssociatedInterfaceSupport() {} | 92 virtual ~AssociatedInterfaceSupport() {} |
94 | 93 |
95 // Accesses the AssociatedGroup used to associate new interface endpoints | |
96 // with this Channel. Must be safe to call from any thread. | |
97 virtual mojo::AssociatedGroup* GetAssociatedGroup() = 0; | |
98 | |
99 // Returns a ThreadSafeForwarded for this channel which can be used to | 94 // Returns a ThreadSafeForwarded for this channel which can be used to |
100 // safely send mojom::Channel requests from arbitrary threads. | 95 // safely send mojom::Channel requests from arbitrary threads. |
101 virtual std::unique_ptr<mojo::ThreadSafeForwarder<mojom::Channel>> | 96 virtual std::unique_ptr<mojo::ThreadSafeForwarder<mojom::Channel>> |
102 CreateThreadSafeChannel() = 0; | 97 CreateThreadSafeChannel() = 0; |
103 | 98 |
104 // Adds an interface factory to this channel for interface |name|. Must be | 99 // Adds an interface factory to this channel for interface |name|. Must be |
105 // safe to call from any thread. | 100 // safe to call from any thread. |
106 virtual void AddGenericAssociatedInterface( | 101 virtual void AddGenericAssociatedInterface( |
107 const std::string& name, | 102 const std::string& name, |
108 const GenericAssociatedInterfaceFactory& factory) = 0; | 103 const GenericAssociatedInterfaceFactory& factory) = 0; |
(...skipping 12 matching lines...) Expand all Loading... |
121 const AssociatedInterfaceFactory<Interface>& factory) { | 116 const AssociatedInterfaceFactory<Interface>& factory) { |
122 AddGenericAssociatedInterface( | 117 AddGenericAssociatedInterface( |
123 Interface::Name_, | 118 Interface::Name_, |
124 base::Bind(&BindAssociatedInterfaceRequest<Interface>, factory)); | 119 base::Bind(&BindAssociatedInterfaceRequest<Interface>, factory)); |
125 } | 120 } |
126 | 121 |
127 // Template helper to request a remote associated interface. | 122 // Template helper to request a remote associated interface. |
128 template <typename Interface> | 123 template <typename Interface> |
129 void GetRemoteAssociatedInterface( | 124 void GetRemoteAssociatedInterface( |
130 mojo::AssociatedInterfacePtr<Interface>* proxy) { | 125 mojo::AssociatedInterfacePtr<Interface>* proxy) { |
131 mojo::AssociatedInterfaceRequest<Interface> request = | 126 auto request = mojo::MakeRequest(proxy); |
132 mojo::MakeRequest(proxy, GetAssociatedGroup()); | |
133 GetGenericRemoteAssociatedInterface( | 127 GetGenericRemoteAssociatedInterface( |
134 Interface::Name_, request.PassHandle()); | 128 Interface::Name_, request.PassHandle()); |
135 } | 129 } |
136 | 130 |
137 private: | 131 private: |
138 template <typename Interface> | 132 template <typename Interface> |
139 static void BindAssociatedInterfaceRequest( | 133 static void BindAssociatedInterfaceRequest( |
140 const AssociatedInterfaceFactory<Interface>& factory, | 134 const AssociatedInterfaceFactory<Interface>& factory, |
141 mojo::ScopedInterfaceEndpointHandle handle) { | 135 mojo::ScopedInterfaceEndpointHandle handle) { |
142 mojo::AssociatedInterfaceRequest<Interface> request; | 136 mojo::AssociatedInterfaceRequest<Interface> request; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // of Connect(). | 279 // of Connect(). |
286 void WillConnect(); | 280 void WillConnect(); |
287 | 281 |
288 private: | 282 private: |
289 bool did_start_connect_ = false; | 283 bool did_start_connect_ = false; |
290 }; | 284 }; |
291 | 285 |
292 } // namespace IPC | 286 } // namespace IPC |
293 | 287 |
294 #endif // IPC_IPC_CHANNEL_H_ | 288 #endif // IPC_IPC_CHANNEL_H_ |
OLD | NEW |