Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(789)

Unified Diff: mojo/public/cpp/bindings/lib/multiplex_router.h

Issue 1823683006: Mojo C++ bindings: sync call support for associated interfaces and master interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/lib/multiplex_router.h
diff --git a/mojo/public/cpp/bindings/lib/multiplex_router.h b/mojo/public/cpp/bindings/lib/multiplex_router.h
index a8bf9b556b7da7704ac1d0e30148a61af7a89788..61eba8f660057bc32072996f25c75e0de1d9e311 100644
--- a/mojo/public/cpp/bindings/lib/multiplex_router.h
+++ b/mojo/public/cpp/bindings/lib/multiplex_router.h
@@ -9,6 +9,7 @@
#include <deque>
#include <map>
+#include <queue>
#include "base/logging.h"
#include "base/macros.h"
@@ -39,6 +40,30 @@ namespace internal {
class InterfaceEndpointClient;
+class InterfaceEndpointController {
+ public:
+ virtual ~InterfaceEndpointController() {}
+
+ virtual bool SendMessage(Message* message) = 0;
+
+ virtual void AllowWokenUpBySyncWatchOnSameThread() = 0;
+ /*
+ // Requests to register |message_pipe_| with SyncHandleWatcher whenever this
+ // instance is expecting incoming messages.
+ //
+ // Please note that UnregisterSyncHandleWatch() needs to be called as many
+ // times as successful RegisterSyncHandleWatch() calls in order to cancel the
+ // effect.
+ virtual bool RegisterSyncHandleWatch() = 0;
+ virtual void UnregisterSyncHandleWatch() = 0;*/
+
+ // Watches all handles registered with SyncHandleWatcher on the same thread.
+ // The method returns true when |*should_stop| is set to true; returns false
+ // when any failure occurs during the watch, including |message_pipe_| is
+ // closed.
+ virtual bool SyncWatch(const bool* should_stop) = 0;
+};
+
// MultiplexRouter supports routing messages for multiple interfaces over a
// single message pipe.
//
@@ -78,15 +103,17 @@ class MultiplexRouter
void CloseEndpointHandle(InterfaceId id, bool is_local);
// Attaches an client to the specified endpoint to send and receive messages.
- void AttachEndpointClient(const ScopedInterfaceEndpointHandle& handle,
- InterfaceEndpointClient* endpoint_client);
+ // The returned object is owned by the router. It should only be used on the
+ // same thread as this call, and only before the client is detached using
+ // DetachEndpointClient().
+ InterfaceEndpointController* AttachEndpointClient(
+ const ScopedInterfaceEndpointHandle& handle,
+ InterfaceEndpointClient* endpoint_client);
+
// Detaches the client attached to the specified endpoint. It should be called
// on the same thread as the corresponding AttachEndpointClient() call.
void DetachEndpointClient(const ScopedInterfaceEndpointHandle& handle);
- bool SendMessage(const ScopedInterfaceEndpointHandle& handle,
- Message* message);
-
// Raises an error on the underlying message pipe. It disconnects the pipe
// and notifies all interfaces running on this pipe.
void RaiseError();
@@ -104,6 +131,10 @@ class MultiplexRouter
void CloseMessagePipe() {
DCHECK(thread_checker_.CalledOnValidThread());
connector_.CloseMessagePipe();
+ // CloseMessagePipe() above won't trigger connection error handler.
+ // Explicitly call OnPipeConnectionError() so that associated endpoints will
+ // get notified.
+ OnPipeConnectionError();
}
// Extracts the underlying message pipe.
@@ -167,18 +198,34 @@ class MultiplexRouter
void OnPipeConnectionError();
+ // Specifies whether we are allowed to directly call into
+ // InterfaceEndpointClient (given that we are already on the same thread as
+ // the client).
+ enum ClientCallBehavior {
+ // Don't call any InterfaceEndpointClient methods directly.
+ NO_DIRECT_CLIENT_CALLS,
+ // Only call InterfaceEndpointClient::HandleIncomingMessage directly to
+ // handle sync messages.
+ ALLOW_DIRECT_CLIENT_CALLS_FOR_SYNC_MESSAGES,
+ // Allow to call any InterfaceEndpointClient methods directly.
+ ALLOW_DIRECT_CLIENT_CALLS
+ };
+
// Processes enqueued tasks (incoming messages and error notifications).
- // If |force_async| is true, it guarantees not to call any
- // InterfaceEndpointClient methods directly.
//
// Note: Because calling into InterfaceEndpointClient may lead to destruction
- // of this object, if |force_async| is set to false, the caller needs to hold
- // on to a ref outside of |lock_| before calling this method.
- void ProcessTasks(bool force_async);
+ // of this object, if direct calls are allowed, the caller needs to hold on to
+ // a ref outside of |lock_| before calling this method.
+ void ProcessTasks(ClientCallBehavior client_call_behavior);
+
+ // Returns whether there are more in the queue.
+ bool ProcessFirstSyncMessageForEndpoint(InterfaceId id);
// Returns true to indicate that |task|/|message| has been processed.
- bool ProcessNotifyErrorTask(Task* task, bool force_async);
- bool ProcessIncomingMessage(Message* message, bool force_async);
+ bool ProcessNotifyErrorTask(Task* task,
+ ClientCallBehavior client_call_behavior);
+ bool ProcessIncomingMessage(Message* message,
+ ClientCallBehavior client_call_behavior);
void MaybePostToProcessTasks(base::SingleThreadTaskRunner* task_runner);
void LockAndCallProcessTasks();
@@ -213,6 +260,8 @@ class MultiplexRouter
uint32_t next_interface_id_value_;
std::deque<scoped_ptr<Task>> tasks_;
+ // It refers to tasks in |tasks_| and doesn't own any of them.
+ std::map<InterfaceId, std::deque<Task*>> sync_message_tasks_;
bool posted_to_process_tasks_;
« no previous file with comments | « mojo/public/cpp/bindings/lib/interface_ptr_state.h ('k') | mojo/public/cpp/bindings/lib/multiplex_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698