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

Unified Diff: mojo/public/cpp/system/platform_handle.cc

Issue 2735113003: Changing SpawnChild to return a struct.
Patch Set: Created 3 years, 9 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/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
« no previous file with comments | « mojo/public/cpp/system/platform_handle.h ('k') | services/service_manager/runner/host/service_process_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698