// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef IPC_IPC_CHANNEL_PROXY_H_ #define IPC_IPC_CHANNEL_PROXY_H_ #include <stdint.h> #include <map> #include <memory> #include <string> #include <vector> #include "base/component_export.h" #include "base/functional/bind.h" #include "base/functional/callback.h" #include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/sequence_checker.h" #include "base/synchronization/lock.h" #include "build/build_config.h" #include "ipc/ipc.mojom.h" #include "ipc/ipc_channel.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_listener.h" #include "ipc/ipc_sender.h" #include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/generic_pending_associated_receiver.h" #include "mojo/public/cpp/bindings/pending_associated_receiver.h" #include "mojo/public/cpp/bindings/pending_associated_remote.h" #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" #include "mojo/public/cpp/bindings/shared_associated_remote.h" namespace base { class SingleThreadTaskRunner; } namespace IPC { class ChannelFactory; class MessageFilter; class MessageFilterRouter; class UrgentMessageObserver; //----------------------------------------------------------------------------- // IPC::ChannelProxy // // This class is a helper class that is useful when you wish to run an IPC // channel on a background thread. It provides you with the option of either // handling IPC messages on that background thread or having them dispatched to // your main thread (the thread on which the IPC::ChannelProxy is created). // // The API for an IPC::ChannelProxy is very similar to that of an IPC::Channel. // When you send a message to an IPC::ChannelProxy, the message is routed to // the background thread, where it is then passed to the IPC::Channel's Send // method. This means that you can send a message from your thread and your // message will be sent over the IPC channel when possible instead of being // delayed until your thread returns to its message loop. (Often IPC messages // will queue up on the IPC::Channel when there is a lot of traffic, and the // channel will not get cycles to flush its message queue until the thread, on // which it is running, returns to its message loop.) // // An IPC::ChannelProxy can have a MessageFilter associated with it, which will // be notified of incoming messages on the IPC::Channel's thread. This gives // the consumer of IPC::ChannelProxy the ability to respond to incoming // messages on this background thread instead of on their own thread, which may // be bogged down with other processing. The result can be greatly improved // latency for messages that can be handled on a background thread. // // The consumer of IPC::ChannelProxy is responsible for allocating the Thread // instance where the IPC::Channel will be created and operated. // // Thread-safe send // // If a particular |Channel| implementation has a thread-safe |Send()| operation // then ChannelProxy skips the inter-thread hop and calls |Send()| directly. In // this case the |channel_| variable is touched by multiple threads so // |channel_lifetime_lock_| is used to protect it. The locking overhead is only // paid if the underlying channel supports thread-safe |Send|. // class COMPONENT_EXPORT(IPC) ChannelProxy : public Sender { … }; } // namespace IPC #endif // IPC_IPC_CHANNEL_PROXY_H_