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

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

Issue 1713203002: Mojo C++ bindings: support sync methods - part 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « mojo/public/cpp/bindings/lib/binding_state.h ('k') | mojo/public/cpp/bindings/lib/connector.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/connector.h
diff --git a/mojo/public/cpp/bindings/lib/connector.h b/mojo/public/cpp/bindings/lib/connector.h
index 3978171101ce0d8f7368954b37ee29171a4e3b67..8e664a196cd7811ebb1ea10bd9d931e89652dc89 100644
--- a/mojo/public/cpp/bindings/lib/connector.h
+++ b/mojo/public/cpp/bindings/lib/connector.h
@@ -6,6 +6,7 @@
#define MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "mojo/public/c/environment/async_waiter.h"
#include "mojo/public/cpp/bindings/callback.h"
@@ -121,9 +122,31 @@ class Connector : public MessageReceiver {
return message_pipe_.get();
}
+ // 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.
+ bool RegisterSyncHandleWatch();
+ void UnregisterSyncHandleWatch();
+
+ // 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.
+ bool RunSyncHandleWatch(const bool* should_stop);
+
+ // Whether currently the control flow is inside the sync handle watcher
+ // callback.
+ bool during_sync_handle_watcher_callback() const {
+ return sync_handle_watcher_callback_count_ > 0;
+ }
+
private:
static void CallOnHandleReady(void* closure, MojoResult result);
- void OnHandleReady(MojoResult result);
+ void OnSyncHandleWatcherHandleReady(MojoResult result);
+ void OnHandleReadyInternal(MojoResult result);
void WaitToReadMore();
@@ -155,17 +178,22 @@ class Connector : public MessageReceiver {
bool paused_;
- // If non-null, this will be set to true when the Connector is destroyed. We
- // use this flag to allow for the Connector to be destroyed as a side-effect
- // of dispatching an incoming message.
- bool* destroyed_flag_;
-
// If sending messages is allowed from multiple threads, |lock_| is used to
// protect modifications to |message_pipe_| and |drop_writes_|.
scoped_ptr<base::Lock> lock_;
+ // If non-zero, |message_pipe_| should be registered with SyncHandleWatcher.
+ size_t register_sync_handle_watch_count_;
+ // Whether |message_pipe_| has been registered with SyncHandleWatcher.
+ bool registered_with_sync_handle_watcher_;
+ // If non-zero, currently the control flow is inside the sync handle watcher
+ // callback.
+ size_t sync_handle_watcher_callback_count_;
+
base::ThreadChecker thread_checker_;
+ base::WeakPtrFactory<Connector> weak_factory_;
+
MOJO_DISALLOW_COPY_AND_ASSIGN(Connector);
};
« no previous file with comments | « mojo/public/cpp/bindings/lib/binding_state.h ('k') | mojo/public/cpp/bindings/lib/connector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698