summaryrefslogtreecommitdiffstats
path: root/mojo/android/system
diff options
context:
space:
mode:
authorqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-28 14:02:38 +0000
committerqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-28 14:02:38 +0000
commit54cb593812104e6cfd93dbbd47fd2037fd46f67b (patch)
tree992fd348f6f6cb73ea1c856c5be85efbbe0c3894 /mojo/android/system
parent155c4cef9cfa1a830034d4edd87339238ce5d73f (diff)
downloadchromium_src-54cb593812104e6cfd93dbbd47fd2037fd46f67b.zip
chromium_src-54cb593812104e6cfd93dbbd47fd2037fd46f67b.tar.gz
chromium_src-54cb593812104e6cfd93dbbd47fd2037fd46f67b.tar.bz2
Updates mojo java core API
- Refactor test case to be re-usable - Refactor writeMessage signature to be able to take List of typed handles. - Refactor flags to enable access to constant flags for usual values. - Refactor ReadMessageResult to return the MojoResult value, as we need to differenciate OK, RESOURCE_EXHAUSTED and SHOULD_WAIT Review URL: https://codereview.chromium.org/297833005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273215 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/android/system')
-rw-r--r--mojo/android/system/core_impl.cc2
-rw-r--r--mojo/android/system/src/org/chromium/mojo/system/CoreImpl.java69
-rw-r--r--mojo/android/system/src/org/chromium/mojo/system/MessagePipeHandleImpl.java2
3 files changed, 20 insertions, 53 deletions
diff --git a/mojo/android/system/core_impl.cc b/mojo/android/system/core_impl.cc
index 34d009c..473bf32 100644
--- a/mojo/android/system/core_impl.cc
+++ b/mojo/android/system/core_impl.cc
@@ -183,7 +183,7 @@ static jobject ReadMessage(JNIEnv* env,
MojoResult result = MojoReadMessage(
mojo_handle, buffer_start, &buffer_size, handles, &num_handles, flags);
// Jave code will handle taking ownership of any received handle.
- return Java_CoreImpl_newNativeReadMessageResult(
+ return Java_CoreImpl_newReadMessageResult(
env, result, buffer_size, num_handles).Release();
}
diff --git a/mojo/android/system/src/org/chromium/mojo/system/CoreImpl.java b/mojo/android/system/src/org/chromium/mojo/system/CoreImpl.java
index be3c706..af94b44 100644
--- a/mojo/android/system/src/org/chromium/mojo/system/CoreImpl.java
+++ b/mojo/android/system/src/org/chromium/mojo/system/CoreImpl.java
@@ -20,7 +20,9 @@ import java.util.List;
/**
* Implementation of {@link Core}.
*/
-@JNIAdditionalImport(AsyncWaiter.class)
+@JNIAdditionalImport({
+ AsyncWaiter.class,
+ MessagePipeHandle.class })
@JNINamespace("mojo::android")
public class CoreImpl implements Core, AsyncWaiter {
@@ -189,7 +191,7 @@ public class CoreImpl implements Core, AsyncWaiter {
* @see MessagePipeHandle#writeMessage(ByteBuffer, List, MessagePipeHandle.WriteFlags)
*/
void writeMessage(MessagePipeHandleImpl pipeHandle, ByteBuffer bytes,
- List<Handle> handles, MessagePipeHandle.WriteFlags flags) {
+ List<? extends Handle> handles, MessagePipeHandle.WriteFlags flags) {
ByteBuffer handlesBuffer = null;
if (handles != null && !handles.isEmpty()) {
handlesBuffer = allocateDirectBuffer(handles.size() * HANDLE_SIZE);
@@ -224,28 +226,29 @@ public class CoreImpl implements Core, AsyncWaiter {
if (maxNumberOfHandles > 0) {
handlesBuffer = allocateDirectBuffer(maxNumberOfHandles * HANDLE_SIZE);
}
- NativeReadMessageResult result = nativeReadMessage(
+ MessagePipeHandle.ReadMessageResult result = nativeReadMessage(
handle.getMojoHandle(), bytes, handlesBuffer, flags.getFlags());
if (result.getMojoResult() != MojoResult.OK &&
- result.getMojoResult() != MojoResult.RESOURCE_EXHAUSTED) {
+ result.getMojoResult() != MojoResult.RESOURCE_EXHAUSTED &&
+ result.getMojoResult() != MojoResult.SHOULD_WAIT) {
throw new MojoException(result.getMojoResult());
}
if (result.getMojoResult() == MojoResult.OK) {
if (bytes != null) {
bytes.position(0);
- bytes.limit(result.getReadMessageResult().getMessageSize());
+ bytes.limit(result.getMessageSize());
}
List<UntypedHandle> handles = new ArrayList<UntypedHandle>(
- result.getReadMessageResult().getHandlesCount());
- for (int i = 0; i < result.getReadMessageResult().getHandlesCount(); ++i) {
+ result.getHandlesCount());
+ for (int i = 0; i < result.getHandlesCount(); ++i) {
int mojoHandle = handlesBuffer.getInt(HANDLE_SIZE * i);
handles.add(new UntypedHandleImpl(this, mojoHandle));
}
- result.getReadMessageResult().setHandles(handles);
+ result.setHandles(handles);
}
- return result.getReadMessageResult();
+ return result;
}
/**
@@ -524,55 +527,18 @@ public class CoreImpl implements Core, AsyncWaiter {
return result;
}
- private static class NativeReadMessageResult {
- public int mMojoResult;
- public MessagePipeHandle.ReadMessageResult mReadMessageResult;
-
- /**
- * @return the mojoResult
- */
- public int getMojoResult() {
- return mMojoResult;
- }
-
- /**
- * @param mojoResult the mojoResult to set
- */
- public void setMojoResult(int mojoResult) {
- this.mMojoResult = mojoResult;
- }
-
- /**
- * @return the readMessageResult
- */
- public MessagePipeHandle.ReadMessageResult getReadMessageResult() {
- return mReadMessageResult;
- }
-
- /**
- * @param readMessageResult the readMessageResult to set
- */
- public void setReadMessageResult(MessagePipeHandle.ReadMessageResult readMessageResult) {
- this.mReadMessageResult = readMessageResult;
- }
- }
-
@CalledByNative
- private static NativeReadMessageResult newNativeReadMessageResult(int mojoResult,
+ private static MessagePipeHandle.ReadMessageResult newReadMessageResult(int mojoResult,
int messageSize,
int handlesCount) {
- NativeReadMessageResult result = new NativeReadMessageResult();
+ MessagePipeHandle.ReadMessageResult result = new MessagePipeHandle.ReadMessageResult();
if (mojoResult >= 0) {
result.setMojoResult(MojoResult.OK);
} else {
result.setMojoResult(mojoResult);
}
- MessagePipeHandle.ReadMessageResult readMessageResult =
- new MessagePipeHandle.ReadMessageResult();
- readMessageResult.setWasMessageRead(result.getMojoResult() == MojoResult.OK);
- readMessageResult.setMessageSize(messageSize);
- readMessageResult.setHandlesCount(handlesCount);
- result.setReadMessageResult(readMessageResult);
+ result.setMessageSize(messageSize);
+ result.setHandlesCount(handlesCount);
return result;
}
@@ -654,7 +620,8 @@ public class CoreImpl implements Core, AsyncWaiter {
private native int nativeWriteMessage(int mojoHandle, ByteBuffer bytes, int numBytes,
ByteBuffer handlesBuffer, int flags);
- private native NativeReadMessageResult nativeReadMessage(int mojoHandle, ByteBuffer bytes,
+ private native MessagePipeHandle.ReadMessageResult nativeReadMessage(int mojoHandle,
+ ByteBuffer bytes,
ByteBuffer handlesBuffer,
int flags);
diff --git a/mojo/android/system/src/org/chromium/mojo/system/MessagePipeHandleImpl.java b/mojo/android/system/src/org/chromium/mojo/system/MessagePipeHandleImpl.java
index cbe42af8..54985b1 100644
--- a/mojo/android/system/src/org/chromium/mojo/system/MessagePipeHandleImpl.java
+++ b/mojo/android/system/src/org/chromium/mojo/system/MessagePipeHandleImpl.java
@@ -30,7 +30,7 @@ class MessagePipeHandleImpl extends HandleBase implements MessagePipeHandle {
* @see MessagePipeHandle#writeMessage(ByteBuffer, List, WriteFlags)
*/
@Override
- public void writeMessage(ByteBuffer bytes, List<Handle> handles, WriteFlags flags) {
+ public void writeMessage(ByteBuffer bytes, List<? extends Handle> handles, WriteFlags flags) {
mCore.writeMessage(this, bytes, handles, flags);
}