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

Unified Diff: mojo/public/java/bindings/src/org/chromium/mojo/bindings/Interface.java

Issue 1450373002: Add a Binding class to manager the binding of a message pipe. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 5 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/java/bindings/src/org/chromium/mojo/bindings/Interface.java
diff --git a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Interface.java b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Interface.java
index c2bbc8ebddb4127bef1020b75395dd673b8ad691..3167e87dc2b78362757a09506376bbe2d482c85f 100644
--- a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Interface.java
+++ b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Interface.java
@@ -308,6 +308,23 @@ public interface Interface extends ConnectionErrorHandler, Closeable {
}
/**
+ * Enables managing the bindings from an implementation to a message pipe.
+ */
+ interface Binding {
+ /**
+ * Unbinds the implementation from the message pipe. Returns the handle that will be owned
+ * by the caller.
+ */
+ public MessagePipeHandle unbind();
+
+ /**
+ * Registers an error handler on the binding. It will be called if an error happens on the
+ * underlying message pipe.
+ */
+ public void registerErrorHandler(ConnectionErrorHandler errorHandler);
+ }
+
+ /**
* The |Manager| object enables building of proxies and stubs for a given interface.
*
* @param <I> the type of the interface the manager can handle.
@@ -329,20 +346,21 @@ public interface Interface extends ConnectionErrorHandler, Closeable {
/**
* Binds the given implementation to the handle.
*/
- public void bind(I impl, MessagePipeHandle handle) {
+ public Binding bind(I impl, MessagePipeHandle handle) {
// The router (and by consequence the handle) is intentionally leaked. It will close
// itself when the connected handle is closed and the proxy receives the connection
// error.
Router router = new RouterImpl(handle);
- bind(handle.getCore(), impl, router);
+ Binding result = bind(handle.getCore(), impl, router);
router.start();
+ return result;
}
/**
* Binds the given implementation to the InterfaceRequest.
*/
- public final void bind(I impl, InterfaceRequest<I> request) {
- bind(impl, request.passHandle());
+ public final Binding bind(I impl, InterfaceRequest<I> request) {
+ return bind(impl, request.passHandle());
}
/**
@@ -352,9 +370,10 @@ public interface Interface extends ConnectionErrorHandler, Closeable {
public final P attachProxy(MessagePipeHandle handle, int version) {
RouterImpl router = new RouterImpl(handle);
P proxy = attachProxy(handle.getCore(), router);
- DelegatingConnectionErrorHandler handlers = new DelegatingConnectionErrorHandler();
- handlers.addConnectionErrorHandler(proxy);
- router.setErrorHandler(handlers);
+ DelegatingConnectionErrorHandler delegatingHandler =
+ new DelegatingConnectionErrorHandler();
+ delegatingHandler.addConnectionErrorHandler(proxy);
+ router.setErrorHandler(delegatingHandler);
router.start();
((HandlerImpl) proxy.getProxyHandler()).setVersion(version);
return proxy;
@@ -378,9 +397,24 @@ public interface Interface extends ConnectionErrorHandler, Closeable {
/**
* Binds the implementation to the given |router|.
*/
- final void bind(Core core, I impl, Router router) {
- router.setErrorHandler(impl);
+ final Binding bind(Core core, I impl, final Router router) {
+ final DelegatingConnectionErrorHandler delegatingHandler =
+ new DelegatingConnectionErrorHandler();
+ delegatingHandler.addConnectionErrorHandler(impl);
+ router.setErrorHandler(delegatingHandler);
router.setIncomingMessageReceiver(buildStub(core, impl));
+ return new Binding() {
+
+ @Override
+ public MessagePipeHandle unbind() {
+ return router.passHandle();
+ }
+
+ @Override
+ public void registerErrorHandler(ConnectionErrorHandler errorHandler) {
+ delegatingHandler.addConnectionErrorHandler(errorHandler);
+ }
+ };
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698