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

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

Issue 411913002: mojo: generate Proxies and Stubs for java bindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update landmines Created 6 years, 4 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/java/bindings/src/org/chromium/mojo/bindings/Encoder.java
diff --git a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java
index 9ec2cb248e0bb8cc5e697a29cdec93f84398bbf8..52a9cbd8c5be90167d2054d42aba0827ad531a7b 100644
--- a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java
+++ b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java
@@ -7,6 +7,8 @@ package org.chromium.mojo.bindings;
import org.chromium.mojo.bindings.Struct.DataHeader;
import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.Handle;
+import org.chromium.mojo.system.MessagePipeHandle;
+import org.chromium.mojo.system.Pair;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -139,7 +141,6 @@ public class Encoder {
Encoder result = new Encoder(mEncoderState);
result.encode(dataHeader);
return result;
-
}
/**
@@ -243,25 +244,43 @@ public class Encoder {
/**
* Encode an {@link Interface}.
*/
- public <T extends Interface> void encode(T v, int offset, Object builder) {
+ public <T extends Interface> void encode(T v, int offset, Interface.Manager<T, ?> manager) {
+ if (v == null) {
+ encode(-1, offset);
+ return;
+ }
if (mEncoderState.core == null) {
throw new UnsupportedOperationException(
"The encoder has been created without a Core. It can't encode an interface.");
}
- // TODO(qsr): To be implemented when interfaces proxy and stubs are implemented.
- throw new UnsupportedOperationException("Unimplemented operation");
+ // If the instance is a proxy, pass the proxy's handle instead of creating a new stub.
+ if (v instanceof Interface.AbstractProxy) {
+ Interface.AbstractProxy proxy = (Interface.AbstractProxy) v;
+ if (proxy.getMessageReceiver() instanceof HandleOwner) {
+ encode(((HandleOwner<?>) proxy.getMessageReceiver()).passHandle(), offset);
+ return;
+ }
+ // If the proxy is not over a message pipe, the default case applies.
+ }
+ Pair<MessagePipeHandle, MessagePipeHandle> handles =
+ mEncoderState.core.createMessagePipe(null);
+ manager.bind(v, handles.first);
+ encode(handles.second, offset);
}
/**
* Encode an {@link InterfaceRequest}.
*/
- public <T extends Interface> void encode(InterfaceRequest<T> v, int offset) {
+ public <I extends Interface> void encode(InterfaceRequest<I> v, int offset) {
+ if (v == null) {
+ encode(-1, offset);
+ return;
+ }
if (mEncoderState.core == null) {
throw new UnsupportedOperationException(
"The encoder has been created without a Core. It can't encode an interface.");
}
- // TODO(qsr): To be implemented when interfaces proxy and stubs are implemented.
- throw new UnsupportedOperationException("Unimplemented operation");
+ encode(v.passHandle(), offset);
}
/**
@@ -374,7 +393,8 @@ public class Encoder {
/**
* Encodes an array of {@link Interface}.
*/
- public <T extends Interface> void encode(T[] v, int offset, Object builder) {
+ public <T extends Interface> void encode(T[] v, int offset,
+ Interface.Manager<T, ?> manager) {
if (v == null) {
encodeNullPointer(offset);
return;
@@ -382,14 +402,14 @@ public class Encoder {
Encoder e = encoderForArray(BindingsHelper.SERIALIZED_HANDLE_SIZE, v.length, offset);
for (int i = 0; i < v.length; ++i) {
e.encode(v[i], DataHeader.HEADER_SIZE + BindingsHelper.SERIALIZED_HANDLE_SIZE * i,
- builder);
+ manager);
}
}
/**
- * Encodes an array of {@link Interface}.
+ * Encodes an array of {@link InterfaceRequest}.
*/
- public <T extends Interface> void encode(InterfaceRequest<T>[] v, int offset) {
+ public <I extends Interface> void encode(InterfaceRequest<I>[] v, int offset) {
if (v == null) {
encodeNullPointer(offset);
return;

Powered by Google App Engine
This is Rietveld 408576698