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

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

Issue 150713002: Mojo: Add ErrorHandler to RemotePtr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update per review feedback 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
« no previous file with comments | « mojo/public/bindings/lib/connector.h ('k') | mojo/public/bindings/remote_ptr.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/bindings/lib/connector.cc
diff --git a/mojo/public/bindings/lib/connector.cc b/mojo/public/bindings/lib/connector.cc
index b35812f39ead010829cf34c92d58a843e49fc5ca..7a25e93fb9757639c405480e31fb3da2ff827ac4 100644
--- a/mojo/public/bindings/lib/connector.cc
+++ b/mojo/public/bindings/lib/connector.cc
@@ -4,10 +4,9 @@
#include "mojo/public/bindings/lib/connector.h"
-#include <assert.h>
#include <stdlib.h>
-#include <algorithm>
+#include "mojo/public/bindings/error_handler.h"
namespace mojo {
namespace internal {
@@ -16,11 +15,15 @@ namespace internal {
Connector::Connector(ScopedMessagePipeHandle message_pipe,
MojoAsyncWaiter* waiter)
- : waiter_(waiter),
+ : error_handler_(NULL),
+ waiter_(waiter),
message_pipe_(message_pipe.Pass()),
incoming_receiver_(NULL),
async_wait_id_(0),
error_(false) {
+ // Even though we don't have an incoming receiver, we still want to monitor
+ // the message pipe to know if is closed or encounters an error.
+ WaitToReadMore();
}
Connector::~Connector() {
@@ -28,13 +31,6 @@ Connector::~Connector() {
waiter_->CancelWait(waiter_, async_wait_id_);
}
-void Connector::SetIncomingReceiver(MessageReceiver* receiver) {
- assert(!incoming_receiver_);
- incoming_receiver_ = receiver;
- if (incoming_receiver_)
- WaitToReadMore();
-}
-
bool Connector::Accept(Message* message) {
if (error_)
return false;
@@ -44,10 +40,22 @@ bool Connector::Accept(Message* message) {
}
// static
-void Connector::OnHandleReady(void* closure, MojoResult result) {
+void Connector::CallOnHandleReady(void* closure, MojoResult result) {
Connector* self = static_cast<Connector*>(closure);
- self->async_wait_id_ = 0;
- self->ReadMore();
+ self->OnHandleReady(result);
+}
+
+void Connector::OnHandleReady(MojoResult result) {
+ async_wait_id_ = 0;
+
+ if (result == MOJO_RESULT_OK) {
+ ReadMore();
+ } else {
+ error_ = true;
+ }
+
+ if (error_ && error_handler_)
+ error_handler_->OnError();
}
void Connector::WaitToReadMore() {
@@ -55,7 +63,7 @@ void Connector::WaitToReadMore() {
message_pipe_.get().value(),
MOJO_WAIT_FLAG_READABLE,
MOJO_DEADLINE_INDEFINITE,
- &Connector::OnHandleReady,
+ &Connector::CallOnHandleReady,
this);
}
@@ -95,7 +103,8 @@ void Connector::ReadMore() {
break;
}
- incoming_receiver_->Accept(&message);
+ if (incoming_receiver_)
+ incoming_receiver_->Accept(&message);
}
}
« no previous file with comments | « mojo/public/bindings/lib/connector.h ('k') | mojo/public/bindings/remote_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698