| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_H_ | 5 #ifndef MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_H_ |
| 6 #define MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_H_ | 6 #define MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "mojo/edk/system/system_impl_export.h" | 9 #include "mojo/edk/system/system_impl_export.h" |
| 10 | 10 |
| 11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 12 #include <windows.h> | 12 #include <windows.h> |
| 13 | 13 |
| 14 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
| 15 #elif defined(OS_MACOSX) && !defined(OS_IOS) | 15 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
| 16 #include <mach/mach.h> | 16 #include <mach/mach.h> |
| 17 #elif defined(OS_ANDROID) |
| 18 #include <jni.h> |
| 19 #include "base/android/scoped_java_ref.h" |
| 17 #endif | 20 #endif |
| 18 | 21 |
| 19 namespace mojo { | 22 namespace mojo { |
| 20 namespace edk { | 23 namespace edk { |
| 21 | 24 |
| 22 #if defined(OS_POSIX) | 25 #if defined(OS_POSIX) |
| 23 struct MOJO_SYSTEM_IMPL_EXPORT PlatformHandle { | 26 struct MOJO_SYSTEM_IMPL_EXPORT PlatformHandle { |
| 24 PlatformHandle() {} | 27 PlatformHandle() {} |
| 25 explicit PlatformHandle(int handle) : handle(handle) {} | 28 explicit PlatformHandle(int handle) : handle(handle) {} |
| 26 #if defined(OS_MACOSX) && !defined(OS_IOS) | 29 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 27 explicit PlatformHandle(mach_port_t port) | 30 explicit PlatformHandle(mach_port_t port) |
| 28 : type(Type::MACH), port(port) {} | 31 : type(Type::MACH), port(port) {} |
| 29 #endif | 32 #endif |
| 33 #if defined(OS_ANDROID) |
| 34 explicit PlatformHandle( |
| 35 const base::android::ScopedJavaLocalRef<jobject>& parcelable_param) |
| 36 : type(Type::PARCELABLE), parcelable(parcelable_param) {} |
| 37 #endif |
| 30 | 38 |
| 31 void CloseIfNecessary(); | 39 void CloseIfNecessary(); |
| 32 | 40 |
| 33 bool is_valid() const { | 41 bool is_valid() const { |
| 34 #if defined(OS_MACOSX) && !defined(OS_IOS) | 42 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 35 if (type == Type::MACH || type == Type::MACH_NAME) | 43 if (type == Type::MACH || type == Type::MACH_NAME) |
| 36 return port != MACH_PORT_NULL; | 44 return port != MACH_PORT_NULL; |
| 37 #endif | 45 #endif |
| 46 #if defined(OS_ANDROID) |
| 47 if (type == Type::PARCELABLE) // || type == Type::PARCELABLE_ID) |
| 48 return !parcelable.is_null(); |
| 49 #endif |
| 38 return handle != -1; | 50 return handle != -1; |
| 39 } | 51 } |
| 40 | 52 |
| 41 enum class Type { | 53 enum class Type { |
| 42 POSIX, | 54 POSIX, |
| 43 #if defined(OS_MACOSX) && !defined(OS_IOS) | 55 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 44 MACH, | 56 MACH, |
| 45 // MACH_NAME isn't a real Mach port. But rather the "name" of one that can | 57 // MACH_NAME isn't a real Mach port. But rather the "name" of one that can |
| 46 // be resolved to a real port later. This distinction is needed so that the | 58 // be resolved to a real port later. This distinction is needed so that the |
| 47 // "port" doesn't try to be closed if CloseIfNecessary() is called. Having | 59 // "port" doesn't try to be closed if CloseIfNecessary() is called. Having |
| 48 // this also allows us to do checks in other places. | 60 // this also allows us to do checks in other places. |
| 49 MACH_NAME, | 61 MACH_NAME, |
| 50 #endif | 62 #endif |
| 63 #if defined(OS_ANDROID) |
| 64 PARCELABLE, |
| 65 // PARCELABLE_ID, |
| 66 #endif |
| 51 }; | 67 }; |
| 52 Type type = Type::POSIX; | 68 Type type = Type::POSIX; |
| 53 | 69 |
| 54 int handle = -1; | 70 int handle = -1; |
| 55 | 71 |
| 56 // A POSIX handle may be a listen handle that can accept a connection. | 72 // A POSIX handle may be a listen handle that can accept a connection. |
| 57 bool needs_connection = false; | 73 bool needs_connection = false; |
| 58 | 74 |
| 59 #if defined(OS_MACOSX) && !defined(OS_IOS) | 75 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 60 mach_port_t port = MACH_PORT_NULL; | 76 mach_port_t port = MACH_PORT_NULL; |
| 61 #endif | 77 #endif |
| 78 #if defined(OS_ANDROID) |
| 79 base::android::ScopedJavaGlobalRef<jobject> parcelable; |
| 80 #endif |
| 62 }; | 81 }; |
| 63 #elif defined(OS_WIN) | 82 #elif defined(OS_WIN) |
| 64 struct MOJO_SYSTEM_IMPL_EXPORT PlatformHandle { | 83 struct MOJO_SYSTEM_IMPL_EXPORT PlatformHandle { |
| 65 PlatformHandle() : PlatformHandle(INVALID_HANDLE_VALUE) {} | 84 PlatformHandle() : PlatformHandle(INVALID_HANDLE_VALUE) {} |
| 66 explicit PlatformHandle(HANDLE handle) | 85 explicit PlatformHandle(HANDLE handle) |
| 67 : handle(handle), owning_process(base::GetCurrentProcessHandle()) {} | 86 : handle(handle), owning_process(base::GetCurrentProcessHandle()) {} |
| 68 | 87 |
| 69 void CloseIfNecessary(); | 88 void CloseIfNecessary(); |
| 70 | 89 |
| 71 bool is_valid() const { return handle != INVALID_HANDLE_VALUE; } | 90 bool is_valid() const { return handle != INVALID_HANDLE_VALUE; } |
| 72 | 91 |
| 73 HANDLE handle; | 92 HANDLE handle; |
| 74 | 93 |
| 75 // A Windows HANDLE may be duplicated to another process but not yet sent to | 94 // A Windows HANDLE may be duplicated to another process but not yet sent to |
| 76 // that process. This tracks the handle's owning process. | 95 // that process. This tracks the handle's owning process. |
| 77 base::ProcessHandle owning_process; | 96 base::ProcessHandle owning_process; |
| 78 | 97 |
| 79 // A Windows HANDLE may be an unconnected named pipe. In this case, we need to | 98 // A Windows HANDLE may be an unconnected named pipe. In this case, we need to |
| 80 // wait for a connection before communicating on the pipe. | 99 // wait for a connection before communicating on the pipe. |
| 81 bool needs_connection = false; | 100 bool needs_connection = false; |
| 82 }; | 101 }; |
| 83 #else | 102 #else |
| 84 #error "Platform not yet supported." | 103 #error "Platform not yet supported." |
| 85 #endif | 104 #endif |
| 86 | 105 |
| 87 } // namespace edk | 106 } // namespace edk |
| 88 } // namespace mojo | 107 } // namespace mojo |
| 89 | 108 |
| 90 #endif // MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_H_ | 109 #endif // MOJO_EDK_EMBEDDER_PLATFORM_HANDLE_H_ |
| OLD | NEW |