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

Unified Diff: mojo/public/bindings/lib/connector.cc

Issue 134253004: Mojo: AsyncWaiter and mojo/public/environment (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing files Created 6 years, 11 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/bindings/lib/connector.cc
diff --git a/mojo/public/bindings/lib/connector.cc b/mojo/public/bindings/lib/connector.cc
index 1befc2b40eeb8ef4d5317f3c57fc22f73d6153e1..e8f54aaf73d631056a5d6214e75582c3773c920f 100644
--- a/mojo/public/bindings/lib/connector.cc
+++ b/mojo/public/bindings/lib/connector.cc
@@ -14,8 +14,10 @@ namespace internal {
// ----------------------------------------------------------------------------
-Connector::Connector(ScopedMessagePipeHandle message_pipe)
- : message_pipe_(message_pipe.Pass()),
+Connector::Connector(ScopedMessagePipeHandle message_pipe,
+ MojoAsyncWaiter* waiter)
+ : waiter_(waiter),
+ message_pipe_(message_pipe.Pass()),
incoming_receiver_(NULL),
error_(false) {
}
@@ -54,19 +56,26 @@ void Connector::OnHandleReady(Callback* callback, MojoResult result) {
}
void Connector::WaitToReadMore() {
- read_callback_.SetOwnerToNotify(this);
- read_callback_.SetAsyncWaitID(
- BindingsSupport::Get()->AsyncWait(message_pipe_.get(),
- MOJO_WAIT_FLAG_READABLE,
- &read_callback_));
+ CallAsyncWait(MOJO_WAIT_FLAG_READABLE, &read_callback_);
}
void Connector::WaitToWriteMore() {
- write_callback_.SetOwnerToNotify(this);
- write_callback_.SetAsyncWaitID(
- BindingsSupport::Get()->AsyncWait(message_pipe_.get(),
- MOJO_WAIT_FLAG_WRITABLE,
- &write_callback_));
+ CallAsyncWait(MOJO_WAIT_FLAG_WRITABLE, &write_callback_);
+}
+
+void Connector::CallAsyncWait(MojoWaitFlags flags, Callback* callback) {
+ callback->SetOwnerToNotify(this);
+ callback->SetAsyncWaitID(
+ waiter_->AsyncWait(waiter_,
+ message_pipe_.get().value(),
+ MOJO_WAIT_FLAG_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ &Callback::OnHandleReady,
+ callback));
+}
+
+void Connector::CallCancelWait(MojoAsyncWaitID async_wait_id) {
+ waiter_->CancelWait(waiter_, async_wait_id);
}
void Connector::ReadMore() {
@@ -155,7 +164,7 @@ Connector::Callback::Callback()
Connector::Callback::~Callback() {
if (owner_)
- BindingsSupport::Get()->CancelWait(async_wait_id_);
+ owner_->CallCancelWait(async_wait_id_);
}
void Connector::Callback::SetOwnerToNotify(Connector* owner) {
@@ -163,15 +172,20 @@ void Connector::Callback::SetOwnerToNotify(Connector* owner) {
owner_ = owner;
}
-void Connector::Callback::SetAsyncWaitID(BindingsSupport::AsyncWaitID id) {
+void Connector::Callback::SetAsyncWaitID(MojoAsyncWaitID id) {
async_wait_id_ = id;
}
-void Connector::Callback::OnHandleReady(MojoResult result) {
- assert(owner_);
+// static
+void Connector::Callback::OnHandleReady(void* closure, MojoResult result) {
+ Callback* self = static_cast<Callback*>(closure);
+
+ // Reset |owner_| to indicate that we are no longer in the waiting state.
+
+ assert(self->owner_);
Connector* owner = NULL;
- std::swap(owner, owner_);
- owner->OnHandleReady(this, result);
+ std::swap(owner, self->owner_);
+ owner->OnHandleReady(self, result);
}
} // namespace internal

Powered by Google App Engine
This is Rietveld 408576698