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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 template <typename Interface> | 182 template <typename Interface> |
183 void AddAssociatedInterface( | 183 void AddAssociatedInterface( |
184 const AssociatedInterfaceFactory<Interface>& factory) { | 184 const AssociatedInterfaceFactory<Interface>& factory) { |
185 AddGenericAssociatedInterface( | 185 AddGenericAssociatedInterface( |
186 Interface::Name_, | 186 Interface::Name_, |
187 base::Bind(&ChannelProxy::BindAssociatedInterfaceRequest<Interface>, | 187 base::Bind(&ChannelProxy::BindAssociatedInterfaceRequest<Interface>, |
188 factory)); | 188 factory)); |
189 } | 189 } |
190 | 190 |
191 // Gets the AssociatedGroup used to create new associated endpoints on this | 191 // Gets the AssociatedGroup used to create new associated endpoints on this |
192 // ChannelProxy. This must only be called after the listener's | 192 // ChannelProxy. |
193 // OnChannelConnected is called. | |
194 mojo::AssociatedGroup* GetAssociatedGroup(); | 193 mojo::AssociatedGroup* GetAssociatedGroup(); |
195 | 194 |
196 // Requests an associated interface from the remote endpoint. | 195 // Requests an associated interface from the remote endpoint. |
197 void GetGenericRemoteAssociatedInterface( | 196 void GetGenericRemoteAssociatedInterface( |
198 const std::string& name, | 197 const std::string& name, |
199 mojo::ScopedInterfaceEndpointHandle handle); | 198 mojo::ScopedInterfaceEndpointHandle handle); |
200 | 199 |
201 // Template helper to request associated interfaces from the remote endpoint. | 200 // Template helper to request associated interfaces from the remote endpoint. |
202 // Must only be called after the listener's OnChannelConnected is called. | |
203 template <typename Interface> | 201 template <typename Interface> |
204 void GetRemoteAssociatedInterface( | 202 void GetRemoteAssociatedInterface( |
205 mojo::AssociatedInterfacePtr<Interface>* proxy) { | 203 mojo::AssociatedInterfacePtr<Interface>* proxy) { |
206 mojo::AssociatedInterfaceRequest<Interface> request = | 204 mojo::AssociatedInterfaceRequest<Interface> request = |
207 mojo::GetProxy(proxy, GetAssociatedGroup()); | 205 mojo::GetProxy(proxy, GetAssociatedGroup()); |
208 GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle()); | 206 GetGenericRemoteAssociatedInterface(Interface::Name_, request.PassHandle()); |
209 } | 207 } |
210 | 208 |
211 #if defined(ENABLE_IPC_FUZZER) | 209 #if defined(ENABLE_IPC_FUZZER) |
212 void set_outgoing_message_filter(OutgoingMessageFilter* filter) { | 210 void set_outgoing_message_filter(OutgoingMessageFilter* filter) { |
(...skipping 11 matching lines...) Expand all Loading... |
224 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) | 222 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) |
225 // Calls through to the underlying channel's methods. | 223 // Calls through to the underlying channel's methods. |
226 int GetClientFileDescriptor(); | 224 int GetClientFileDescriptor(); |
227 base::ScopedFD TakeClientFileDescriptor(); | 225 base::ScopedFD TakeClientFileDescriptor(); |
228 #endif | 226 #endif |
229 | 227 |
230 protected: | 228 protected: |
231 class Context; | 229 class Context; |
232 // A subclass uses this constructor if it needs to add more information | 230 // A subclass uses this constructor if it needs to add more information |
233 // to the internal state. | 231 // to the internal state. |
234 ChannelProxy(Context* context); | 232 explicit ChannelProxy(Context* context); |
235 | 233 |
236 | 234 |
237 // Used internally to hold state that is referenced on the IPC thread. | 235 // Used internally to hold state that is referenced on the IPC thread. |
238 class Context : public base::RefCountedThreadSafe<Context>, | 236 class Context : public base::RefCountedThreadSafe<Context>, |
239 public Listener { | 237 public Listener { |
240 public: | 238 public: |
241 Context(Listener* listener, | 239 Context(Listener* listener, |
242 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_thread); | 240 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_thread); |
243 void ClearIPCTaskRunner(); | 241 void ClearIPCTaskRunner(); |
244 base::SingleThreadTaskRunner* ipc_task_runner() const { | 242 base::SingleThreadTaskRunner* ipc_task_runner() const { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 303 |
306 // Methods called on the listener thread. | 304 // Methods called on the listener thread. |
307 void AddFilter(MessageFilter* filter); | 305 void AddFilter(MessageFilter* filter); |
308 void OnDispatchConnected(); | 306 void OnDispatchConnected(); |
309 void OnDispatchError(); | 307 void OnDispatchError(); |
310 void OnDispatchBadMessage(const Message& message); | 308 void OnDispatchBadMessage(const Message& message); |
311 | 309 |
312 void SendFromThisThread(Message* message); | 310 void SendFromThisThread(Message* message); |
313 void ClearChannel(); | 311 void ClearChannel(); |
314 | 312 |
| 313 mojo::AssociatedGroup* associated_group() { return &associated_group_; } |
| 314 |
| 315 void AddGenericAssociatedInterface( |
| 316 const std::string& name, |
| 317 const GenericAssociatedInterfaceFactory& factory); |
| 318 void AddGenericAssociatedInterfaceForIOThread( |
| 319 const std::string& name, |
| 320 const GenericAssociatedInterfaceFactory& factory); |
| 321 |
315 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; | 322 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; |
316 Listener* listener_; | 323 Listener* listener_; |
317 | 324 |
318 // List of filters. This is only accessed on the IPC thread. | 325 // List of filters. This is only accessed on the IPC thread. |
319 std::vector<scoped_refptr<MessageFilter> > filters_; | 326 std::vector<scoped_refptr<MessageFilter> > filters_; |
320 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; | 327 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; |
321 | 328 |
322 // Note, channel_ may be set on the Listener thread or the IPC thread. | 329 // Note, channel_ may be set on the Listener thread or the IPC thread. |
323 // But once it has been set, it must only be read or cleared on the IPC | 330 // But once it has been set, it must only be read or cleared on the IPC |
324 // thread. | 331 // thread. |
(...skipping 21 matching lines...) Expand all Loading... |
346 | 353 |
347 // Cached copy of the peer process ID. Set on IPC but read on both IPC and | 354 // Cached copy of the peer process ID. Set on IPC but read on both IPC and |
348 // listener threads. | 355 // listener threads. |
349 base::ProcessId peer_pid_; | 356 base::ProcessId peer_pid_; |
350 base::Lock peer_pid_lock_; | 357 base::Lock peer_pid_lock_; |
351 | 358 |
352 // Whether this channel is used as an endpoint for sending and receiving | 359 // Whether this channel is used as an endpoint for sending and receiving |
353 // brokerable attachment messages to/from the broker process. | 360 // brokerable attachment messages to/from the broker process. |
354 bool attachment_broker_endpoint_; | 361 bool attachment_broker_endpoint_; |
355 | 362 |
356 // Modified only on the listener's thread before Init() is called. | 363 mojo::AssociatedGroup associated_group_; |
357 std::map<std::string, GenericAssociatedInterfaceFactory> | |
358 io_thread_interfaces_; | |
359 std::map<std::string, GenericAssociatedInterfaceFactory> | |
360 proxy_thread_interfaces_; | |
361 | 364 |
362 // Valid and constant any time after the ChannelProxy's Listener receives | 365 // Holds associated interface binders added by AddGenericAssociatedInterface |
363 // OnChannelConnected on its own thread. | 366 // or AddGenericAssociatedInterfaceForIOThread until the underlying channel |
364 std::unique_ptr<mojo::AssociatedGroup> channel_associated_group_; | 367 // has been initialized. |
| 368 base::Lock pending_interfaces_lock_; |
| 369 std::vector<std::pair<std::string, GenericAssociatedInterfaceFactory>> |
| 370 pending_interfaces_; |
365 }; | 371 }; |
366 | 372 |
367 Context* context() { return context_.get(); } | 373 Context* context() { return context_.get(); } |
368 | 374 |
369 #if defined(ENABLE_IPC_FUZZER) | 375 #if defined(ENABLE_IPC_FUZZER) |
370 OutgoingMessageFilter* outgoing_message_filter() const { | 376 OutgoingMessageFilter* outgoing_message_filter() const { |
371 return outgoing_message_filter_; | 377 return outgoing_message_filter_; |
372 } | 378 } |
373 #endif | 379 #endif |
374 | 380 |
(...skipping 24 matching lines...) Expand all Loading... |
399 bool did_init_; | 405 bool did_init_; |
400 | 406 |
401 #if defined(ENABLE_IPC_FUZZER) | 407 #if defined(ENABLE_IPC_FUZZER) |
402 OutgoingMessageFilter* outgoing_message_filter_; | 408 OutgoingMessageFilter* outgoing_message_filter_; |
403 #endif | 409 #endif |
404 }; | 410 }; |
405 | 411 |
406 } // namespace IPC | 412 } // namespace IPC |
407 | 413 |
408 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 414 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
OLD | NEW |