Index: mojo/public/cpp/system/platform_handle.cc |
diff --git a/mojo/public/cpp/system/platform_handle.cc b/mojo/public/cpp/system/platform_handle.cc |
index 42e4abac832c703db4f52a0e0fc4e13ba3256684..844f8e5519dc4c428b9bac76863f95beff13ad8a 100644 |
--- a/mojo/public/cpp/system/platform_handle.cc |
+++ b/mojo/public/cpp/system/platform_handle.cc |
@@ -9,6 +9,10 @@ |
#include "base/mac/mach_logging.h" |
#endif |
+#if defined(OS_ANDROID) |
+#include "base/android/jni_android.h" |
+#endif |
+ |
namespace mojo { |
namespace { |
@@ -175,4 +179,42 @@ MojoResult UnwrapMachPort(ScopedHandle handle, mach_port_t* port) { |
} |
#endif // defined(OS_MACOSX) && !defined(OS_IOS) |
+#if defined(OS_ANDROID) |
+ScopedHandle WrapParcelable( |
+ base::android::ScopedJavaLocalRef<jobject> parcelable) { |
+ MojoPlatformHandle platform_handle; |
+ platform_handle.struct_size = sizeof(MojoPlatformHandle); |
+ platform_handle.type = MOJO_PLATFORM_HANDLE_TYPE_PARCELABLE; |
+ platform_handle.value = reinterpret_cast<uint64_t>(parcelable.Release()); |
+ |
+ MojoHandle mojo_handle; |
+ MojoResult result = MojoWrapPlatformHandle(&platform_handle, &mojo_handle); |
+ CHECK_EQ(result, MOJO_RESULT_OK); |
+ |
+ return ScopedHandle(Handle(mojo_handle)); |
+} |
+ |
+MojoResult UnwrapParcelable( |
+ ScopedHandle handle, |
+ base::android::ScopedJavaLocalRef<jobject>* parcelable) { |
+ DCHECK(handle.is_valid()); |
+ MojoPlatformHandle platform_handle; |
+ platform_handle.struct_size = sizeof(MojoPlatformHandle); |
+ MojoResult result = |
+ MojoUnwrapPlatformHandle(handle.release().value(), &platform_handle); |
+ if (result != MOJO_RESULT_OK) |
+ return result; |
+ |
+ CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_PARCELABLE); |
+ jobject jparcelable = reinterpret_cast<jobject>(platform_handle.value); |
+ parcelable->Reset(base::android::AttachCurrentThread(), jparcelable); |
+ |
+ // ScopedHandle holds a GlobalRef that gets released in |
+ // ScopedPlatformHandleToMojoPlatformHandle and must be cleared. |
+ base::android::AttachCurrentThread()->DeleteGlobalRef(jparcelable); |
+ |
+ return MOJO_RESULT_OK; |
+} |
+#endif |
+ |
} // namespace mojo |