namespace IPC {
class SyncMessage;
+class ChannelFactory;
// This is similar to ChannelProxy, with the added feature of supporting sending
// synchronous messages.
// Overview of how the sync channel works
// --------------------------------------
// When the sending thread sends a synchronous message, we create a bunch
-// of tracking info (created in SendWithTimeout, stored in the PendingSyncMsg
+// of tracking info (created in Send, stored in the PendingSyncMsg
// structure) associated with the message that we identify by the unique
// "MessageId" on the SyncMessage. Among the things we save is the
// "Deserializer" which is provided by the sync message. This object is in
// Creates and initializes a sync channel. If create_pipe_now is specified,
// the channel will be initialized synchronously.
- SyncChannel(const IPC::ChannelHandle& channel_handle,
- Channel::Mode mode,
- Listener* listener,
- base::SingleThreadTaskRunner* ipc_task_runner,
- bool create_pipe_now,
- base::WaitableEvent* shutdown_event);
+ // The naming pattern follows IPC::Channel.
+ static scoped_ptr<SyncChannel> Create(
+ const IPC::ChannelHandle& channel_handle,
+ IPC::Channel::Mode mode,
+ Listener* listener,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner,
+ bool create_pipe_now,
+ base::WaitableEvent* shutdown_event);
+
+ static scoped_ptr<SyncChannel> Create(
+ scoped_ptr<ChannelFactory> factory,
+ Listener* listener,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner,
+ bool create_pipe_now,
+ base::WaitableEvent* shutdown_event);
// Creates an uninitialized sync channel. Call ChannelProxy::Init to
// initialize the channel. This two-step setup allows message filters to be
// added before any messages are sent or received.
- SyncChannel(Listener* listener,
- base::SingleThreadTaskRunner* ipc_task_runner,
- base::WaitableEvent* shutdown_event);
+ static scoped_ptr<SyncChannel> Create(
+ Listener* listener,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner,
+ base::WaitableEvent* shutdown_event);
- virtual ~SyncChannel();
+ ~SyncChannel() override;
- virtual bool Send(Message* message) OVERRIDE;
- virtual bool SendWithTimeout(Message* message, int timeout_ms);
-
- // Whether we allow sending messages with no time-out.
- void set_sync_messages_with_no_timeout_allowed(bool value) {
- sync_messages_with_no_timeout_allowed_ = value;
- }
+ bool Send(Message* message) override;
// Sets the dispatch group for this channel, to only allow re-entrant dispatch
// of messages to other channels in the same group.
// ChannelProxy::Context for more information.
class SyncContext : public Context {
public:
- SyncContext(Listener* listener,
- base::SingleThreadTaskRunner* ipc_task_runner,
- base::WaitableEvent* shutdown_event);
+ SyncContext(
+ Listener* listener,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner,
+ base::WaitableEvent* shutdown_event);
// Adds information about an outgoing sync message to the context so that
// we know how to deserialize the reply.
base::WaitableEventWatcher::EventCallback MakeWaitableEventCallback();
private:
- virtual ~SyncContext();
+ ~SyncContext() override;
// ChannelProxy methods that we override.
// Called on the listener thread.
- virtual void Clear() OVERRIDE;
+ void Clear() override;
// Called on the IPC thread.
- virtual bool OnMessageReceived(const Message& msg) OVERRIDE;
- virtual void OnChannelError() OVERRIDE;
- virtual void OnChannelOpened() OVERRIDE;
- virtual void OnChannelClosed() OVERRIDE;
+ bool OnMessageReceived(const Message& msg) override;
+ void OnChannelError() override;
+ void OnChannelOpened() override;
+ void OnChannelClosed() override;
// Cancels all pending Send calls.
void CancelPendingSends();
};
private:
+ SyncChannel(
+ Listener* listener,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner,
+ base::WaitableEvent* shutdown_event);
+
void OnWaitableEventSignaled(base::WaitableEvent* arg);
SyncContext* sync_context() {
// Starts the dispatch watcher.
void StartWatching();
- bool sync_messages_with_no_timeout_allowed_;
-
// Used to signal events between the IPC and listener threads.
base::WaitableEventWatcher dispatch_watcher_;
base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_;