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

Unified Diff: mojo/bindings/java/src/org/chromium/mojo/bindings/Connector.java

Issue 392223004: Revert of Adding a router class to handle messages that expect responses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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/bindings/java/src/org/chromium/mojo/bindings/Connector.java
diff --git a/mojo/bindings/java/src/org/chromium/mojo/bindings/Connector.java b/mojo/bindings/java/src/org/chromium/mojo/bindings/Connector.java
index 17cc7ed9fe27e3d3d540a5edc792246a60f076ce..f978ba49b0b3a4f504ec1c34309d93dd9dda753f 100644
--- a/mojo/bindings/java/src/org/chromium/mojo/bindings/Connector.java
+++ b/mojo/bindings/java/src/org/chromium/mojo/bindings/Connector.java
@@ -21,6 +21,13 @@
public class Connector implements MessageReceiver, HandleOwner<MessagePipeHandle> {
/**
+ * An {@link ErrorHandler} is notified of error happening while using the message pipe.
+ */
+ interface ErrorHandler {
+ public void onError(MojoException e);
+ }
+
+ /**
* The callback that is notified when the state of the owned handle changes.
*/
private final AsyncWaiterCallback mAsyncWaiterCallback = new AsyncWaiterCallback();
@@ -48,14 +55,14 @@
/**
* The error handler to notify of errors.
*/
- private ConnectionErrorHandler mErrorHandler;
+ private ErrorHandler mErrorHandler;
/**
* Create a new connector over a |messagePipeHandle|. The created connector will use the default
* {@link AsyncWaiter} from the {@link Core} implementation of |messagePipeHandle|.
*/
public Connector(MessagePipeHandle messagePipeHandle) {
- this(messagePipeHandle, BindingsHelper.getDefaultAsyncWaiterForHandle(messagePipeHandle));
+ this(messagePipeHandle, getDefaultAsyncWaiterForMessagePipe(messagePipeHandle));
}
/**
@@ -76,10 +83,9 @@
}
/**
- * Set the {@link ConnectionErrorHandler} that will be notified of errors on the owned message
- * pipe.
- */
- public void setErrorHandler(ConnectionErrorHandler errorHandler) {
+ * Set the {@link ErrorHandler} that will be notified of errors on the owned message pipe.
+ */
+ public void setErrorHandler(ErrorHandler errorHandler) {
mErrorHandler = errorHandler;
}
@@ -92,13 +98,13 @@
}
/**
- * @see MessageReceiver#accept(MessageWithHeader)
+ * @see MessageReceiver#accept(Message)
*/
@Override
- public boolean accept(MessageWithHeader message) {
+ public boolean accept(Message message) {
try {
- mMessagePipeHandle.writeMessage(message.getMessage().buffer,
- message.getMessage().handles, MessagePipeHandle.WriteFlags.NONE);
+ mMessagePipeHandle.writeMessage(message.buffer, message.handles,
+ MessagePipeHandle.WriteFlags.NONE);
return true;
} catch (MojoException e) {
onError(e);
@@ -125,6 +131,15 @@
public void close() {
cancelIfActive();
mMessagePipeHandle.close();
+ }
+
+ private static AsyncWaiter getDefaultAsyncWaiterForMessagePipe(
+ MessagePipeHandle messagePipeHandle) {
+ if (messagePipeHandle.getCore() != null) {
+ return messagePipeHandle.getCore().getDefaultAsyncWaiter();
+ } else {
+ return null;
+ }
}
private class AsyncWaiterCallback implements AsyncWaiter.Callback {
@@ -163,7 +178,7 @@
mCancellable = null;
close();
if (mErrorHandler != null) {
- mErrorHandler.onConnectionError(exception);
+ mErrorHandler.onError(exception);
}
}
@@ -187,7 +202,7 @@
int result;
do {
try {
- result = MessageWithHeader.readAndDispatchMessage(mMessagePipeHandle,
+ result = Message.readAndDispatchMessage(mMessagePipeHandle,
mIncomingMessageReceiver);
} catch (MojoException e) {
onError(e);
@@ -207,4 +222,5 @@
mCancellable = null;
}
}
+
}

Powered by Google App Engine
This is Rietveld 408576698