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> |
(...skipping 151 matching lines...) Loading... |
162 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>; | 162 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>; |
163 | 163 |
164 // Adds a generic associated interface factory to bind incoming interface | 164 // Adds a generic associated interface factory to bind incoming interface |
165 // requests directly on the IO thread. MUST be called either before Init() or | 165 // requests directly on the IO thread. MUST be called either before Init() or |
166 // before the remote end of the Channel is able to send messages (e.g. before | 166 // before the remote end of the Channel is able to send messages (e.g. before |
167 // its process is launched.) | 167 // its process is launched.) |
168 void AddGenericAssociatedInterfaceForIOThread( | 168 void AddGenericAssociatedInterfaceForIOThread( |
169 const std::string& name, | 169 const std::string& name, |
170 const GenericAssociatedInterfaceFactory& factory); | 170 const GenericAssociatedInterfaceFactory& factory); |
171 | 171 |
172 // Adds a generic associated interface factory to bind incoming interface | |
173 // requests on the ChannelProxy's thread. MUST be called before Init() or | |
174 // before the remote end of the Channel is able to send messages (e.g. before | |
175 // its process is launched.) | |
176 void AddGenericAssociatedInterface( | |
177 const std::string& name, | |
178 const GenericAssociatedInterfaceFactory& factory); | |
179 | |
180 template <typename Interface> | 172 template <typename Interface> |
181 using AssociatedInterfaceFactory = | 173 using AssociatedInterfaceFactory = |
182 base::Callback<void(mojo::AssociatedInterfaceRequest<Interface>)>; | 174 base::Callback<void(mojo::AssociatedInterfaceRequest<Interface>)>; |
183 | 175 |
184 // Helper to bind an IO-thread associated interface factory, inferring the | 176 // Helper to bind an IO-thread associated interface factory, inferring the |
185 // interface name from the callback argument's type. MUST be called before | 177 // interface name from the callback argument's type. MUST be called before |
186 // Init(). | 178 // Init(). |
187 template <typename Interface> | 179 template <typename Interface> |
188 void AddAssociatedInterfaceForIOThread( | 180 void AddAssociatedInterfaceForIOThread( |
189 const AssociatedInterfaceFactory<Interface>& factory) { | 181 const AssociatedInterfaceFactory<Interface>& factory) { |
190 AddGenericAssociatedInterfaceForIOThread( | 182 AddGenericAssociatedInterfaceForIOThread( |
191 Interface::Name_, | 183 Interface::Name_, |
192 base::Bind(&ChannelProxy::BindAssociatedInterfaceRequest<Interface>, | 184 base::Bind(&ChannelProxy::BindAssociatedInterfaceRequest<Interface>, |
193 factory)); | 185 factory)); |
194 } | 186 } |
195 | 187 |
196 // Helper to bind a ChannelProxy-thread associated interface factory, | |
197 // inferring the interface name from the callback argument's type. MUST be | |
198 // called before Init(). | |
199 template <typename Interface> | |
200 void AddAssociatedInterface( | |
201 const AssociatedInterfaceFactory<Interface>& factory) { | |
202 AddGenericAssociatedInterface( | |
203 Interface::Name_, | |
204 base::Bind(&ChannelProxy::BindAssociatedInterfaceRequest<Interface>, | |
205 factory)); | |
206 } | |
207 | |
208 // Gets the AssociatedGroup used to create new associated endpoints on this | 188 // Gets the AssociatedGroup used to create new associated endpoints on this |
209 // ChannelProxy. | 189 // ChannelProxy. |
210 mojo::AssociatedGroup* GetAssociatedGroup(); | 190 mojo::AssociatedGroup* GetAssociatedGroup(); |
211 | 191 |
212 // Requests an associated interface from the remote endpoint. | 192 // Requests an associated interface from the remote endpoint. |
213 void GetGenericRemoteAssociatedInterface( | 193 void GetGenericRemoteAssociatedInterface( |
214 const std::string& name, | 194 const std::string& name, |
215 mojo::ScopedInterfaceEndpointHandle handle); | 195 mojo::ScopedInterfaceEndpointHandle handle); |
216 | 196 |
217 // Template helper to request associated interfaces from the remote endpoint. | 197 // Template helper to request associated interfaces from the remote endpoint. |
(...skipping 116 matching lines...) Loading... |
334 void OnDispatchError(); | 314 void OnDispatchError(); |
335 void OnDispatchBadMessage(const Message& message); | 315 void OnDispatchBadMessage(const Message& message); |
336 void OnDispatchAssociatedInterfaceRequest( | 316 void OnDispatchAssociatedInterfaceRequest( |
337 const std::string& interface_name, | 317 const std::string& interface_name, |
338 mojo::ScopedInterfaceEndpointHandle handle); | 318 mojo::ScopedInterfaceEndpointHandle handle); |
339 | 319 |
340 void ClearChannel(); | 320 void ClearChannel(); |
341 | 321 |
342 mojo::AssociatedGroup* associated_group() { return &associated_group_; } | 322 mojo::AssociatedGroup* associated_group() { return &associated_group_; } |
343 | 323 |
344 void AddGenericAssociatedInterface( | |
345 const std::string& name, | |
346 const GenericAssociatedInterfaceFactory& factory); | |
347 void AddGenericAssociatedInterfaceForIOThread( | 324 void AddGenericAssociatedInterfaceForIOThread( |
348 const std::string& name, | 325 const std::string& name, |
349 const GenericAssociatedInterfaceFactory& factory); | 326 const GenericAssociatedInterfaceFactory& factory); |
350 | 327 |
351 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; | 328 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; |
352 Listener* listener_; | 329 Listener* listener_; |
353 | 330 |
354 // List of filters. This is only accessed on the IPC thread. | 331 // List of filters. This is only accessed on the IPC thread. |
355 std::vector<scoped_refptr<MessageFilter> > filters_; | 332 std::vector<scoped_refptr<MessageFilter> > filters_; |
356 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; | 333 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; |
(...skipping 19 matching lines...) Loading... |
376 // Lock for pending_filters_. | 353 // Lock for pending_filters_. |
377 base::Lock pending_filters_lock_; | 354 base::Lock pending_filters_lock_; |
378 | 355 |
379 // Cached copy of the peer process ID. Set on IPC but read on both IPC and | 356 // Cached copy of the peer process ID. Set on IPC but read on both IPC and |
380 // listener threads. | 357 // listener threads. |
381 base::ProcessId peer_pid_; | 358 base::ProcessId peer_pid_; |
382 base::Lock peer_pid_lock_; | 359 base::Lock peer_pid_lock_; |
383 | 360 |
384 mojo::AssociatedGroup associated_group_; | 361 mojo::AssociatedGroup associated_group_; |
385 | 362 |
386 // Holds associated interface binders added by AddGenericAssociatedInterface | 363 // Holds associated interface binders added by |
387 // or AddGenericAssociatedInterfaceForIOThread until the underlying channel | 364 // AddGenericAssociatedInterfaceForIOThread until the underlying channel has |
388 // has been initialized. | 365 // been initialized. |
389 base::Lock pending_interfaces_lock_; | 366 base::Lock pending_io_thread_interfaces_lock_; |
390 std::vector<std::pair<std::string, GenericAssociatedInterfaceFactory>> | 367 std::vector<std::pair<std::string, GenericAssociatedInterfaceFactory>> |
391 pending_interfaces_; | 368 pending_io_thread_interfaces_; |
392 }; | 369 }; |
393 | 370 |
394 Context* context() { return context_.get(); } | 371 Context* context() { return context_.get(); } |
395 | 372 |
396 #if defined(ENABLE_IPC_FUZZER) | 373 #if defined(ENABLE_IPC_FUZZER) |
397 OutgoingMessageFilter* outgoing_message_filter() const { | 374 OutgoingMessageFilter* outgoing_message_filter() const { |
398 return outgoing_message_filter_; | 375 return outgoing_message_filter_; |
399 } | 376 } |
400 #endif | 377 #endif |
401 | 378 |
(...skipping 24 matching lines...) Loading... |
426 bool did_init_; | 403 bool did_init_; |
427 | 404 |
428 #if defined(ENABLE_IPC_FUZZER) | 405 #if defined(ENABLE_IPC_FUZZER) |
429 OutgoingMessageFilter* outgoing_message_filter_; | 406 OutgoingMessageFilter* outgoing_message_filter_; |
430 #endif | 407 #endif |
431 }; | 408 }; |
432 | 409 |
433 } // namespace IPC | 410 } // namespace IPC |
434 | 411 |
435 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 412 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
OLD | NEW |