| 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_endpoint.h" | 22 #include "ipc/ipc_endpoint.h" |
| 23 #include "ipc/ipc_listener.h" | 23 #include "ipc/ipc_listener.h" |
| 24 #include "ipc/ipc_sender.h" | 24 #include "ipc/ipc_sender.h" |
| 25 #include "mojo/common/event.mojom.h" |
| 25 #include "mojo/public/cpp/bindings/associated_group.h" | 26 #include "mojo/public/cpp/bindings/associated_group.h" |
| 26 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 27 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
| 27 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 28 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| 28 | 29 |
| 29 namespace base { | 30 namespace base { |
| 30 class SingleThreadTaskRunner; | 31 class SingleThreadTaskRunner; |
| 31 } | 32 } |
| 32 | 33 |
| 33 namespace IPC { | 34 namespace IPC { |
| 34 | 35 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 // Ordinarily, messages sent to the ChannelProxy are routed to the matching | 154 // Ordinarily, messages sent to the ChannelProxy are routed to the matching |
| 154 // listener on the worker thread. This API allows code to intercept messages | 155 // listener on the worker thread. This API allows code to intercept messages |
| 155 // before they are sent to the worker thread. | 156 // before they are sent to the worker thread. |
| 156 // If you call this before the target process is launched, then you're | 157 // If you call this before the target process is launched, then you're |
| 157 // guaranteed to not miss any messages. But if you call this anytime after, | 158 // guaranteed to not miss any messages. But if you call this anytime after, |
| 158 // then some messages might be missed since the filter is added internally on | 159 // then some messages might be missed since the filter is added internally on |
| 159 // the IO thread. | 160 // the IO thread. |
| 160 void AddFilter(MessageFilter* filter); | 161 void AddFilter(MessageFilter* filter); |
| 161 void RemoveFilter(MessageFilter* filter); | 162 void RemoveFilter(MessageFilter* filter); |
| 162 | 163 |
| 164 // Sends a message to the remote endpoint and returns an Event pipe which will |
| 165 // Signal() once as soon as the remote endpoint receives the message. This |
| 166 // can be used to synchronize against the Channel's message FIFO. |
| 167 mojo::common::mojom::EventRequest CreateSynchronizationEvent(); |
| 168 |
| 163 using GenericAssociatedInterfaceFactory = | 169 using GenericAssociatedInterfaceFactory = |
| 164 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>; | 170 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>; |
| 165 | 171 |
| 166 // Adds a generic associated interface factory to bind incoming interface | 172 // Adds a generic associated interface factory to bind incoming interface |
| 167 // requests directly on the IO thread. MUST be called either before Init() or | 173 // requests directly on the IO thread. MUST be called either before Init() or |
| 168 // before the remote end of the Channel is able to send messages (e.g. before | 174 // before the remote end of the Channel is able to send messages (e.g. before |
| 169 // its process is launched.) | 175 // its process is launched.) |
| 170 void AddGenericAssociatedInterfaceForIOThread( | 176 void AddGenericAssociatedInterfaceForIOThread( |
| 171 const std::string& name, | 177 const std::string& name, |
| 172 const GenericAssociatedInterfaceFactory& factory); | 178 const GenericAssociatedInterfaceFactory& factory); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 void OnDispatchMessage(const Message& message); | 273 void OnDispatchMessage(const Message& message); |
| 268 | 274 |
| 269 // Sends |message| from appropriate thread. | 275 // Sends |message| from appropriate thread. |
| 270 void Send(Message* message); | 276 void Send(Message* message); |
| 271 | 277 |
| 272 // Requests a remote associated interface on the IPC thread. | 278 // Requests a remote associated interface on the IPC thread. |
| 273 void GetRemoteAssociatedInterface( | 279 void GetRemoteAssociatedInterface( |
| 274 const std::string& name, | 280 const std::string& name, |
| 275 mojo::ScopedInterfaceEndpointHandle handle); | 281 mojo::ScopedInterfaceEndpointHandle handle); |
| 276 | 282 |
| 283 // Sends an Event to be signaled by the remote end. |
| 284 void SendEventToSignal(mojo::common::mojom::EventPtr event); |
| 285 |
| 277 protected: | 286 protected: |
| 278 friend class base::RefCountedThreadSafe<Context>; | 287 friend class base::RefCountedThreadSafe<Context>; |
| 279 ~Context() override; | 288 ~Context() override; |
| 280 | 289 |
| 281 // IPC::Listener methods: | 290 // IPC::Listener methods: |
| 282 bool OnMessageReceived(const Message& message) override; | 291 bool OnMessageReceived(const Message& message) override; |
| 283 void OnChannelConnected(int32_t peer_pid) override; | 292 void OnChannelConnected(int32_t peer_pid) override; |
| 284 void OnChannelError() override; | 293 void OnChannelError() override; |
| 285 void OnAssociatedInterfaceRequest( | 294 void OnAssociatedInterfaceRequest( |
| 286 const std::string& interface_name, | 295 const std::string& interface_name, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 bool did_init_; | 436 bool did_init_; |
| 428 | 437 |
| 429 #if defined(ENABLE_IPC_FUZZER) | 438 #if defined(ENABLE_IPC_FUZZER) |
| 430 OutgoingMessageFilter* outgoing_message_filter_; | 439 OutgoingMessageFilter* outgoing_message_filter_; |
| 431 #endif | 440 #endif |
| 432 }; | 441 }; |
| 433 | 442 |
| 434 } // namespace IPC | 443 } // namespace IPC |
| 435 | 444 |
| 436 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 445 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
| OLD | NEW |