| 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 #include "mojo/edk/embedder/platform_handle.h" | 5 #include "mojo/edk/embedder/platform_handle.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #if defined(OS_POSIX) | 8 #if defined(OS_POSIX) |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 #elif defined(OS_WIN) | 10 #elif defined(OS_WIN) |
| 11 #include <windows.h> | 11 #include <windows.h> |
| 12 #else | 12 #else |
| 13 #error "Platform not yet supported." | 13 #error "Platform not yet supported." |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 #if defined(OS_ANDROID) |
| 17 #include "base/android/jni_android.h" |
| 18 #endif |
| 19 |
| 16 #include "base/logging.h" | 20 #include "base/logging.h" |
| 17 | 21 |
| 18 namespace mojo { | 22 namespace mojo { |
| 19 namespace edk { | 23 namespace edk { |
| 20 | 24 |
| 21 void PlatformHandle::CloseIfNecessary() { | 25 void PlatformHandle::CloseIfNecessary() { |
| 22 if (!is_valid()) | 26 if (!is_valid()) |
| 23 return; | 27 return; |
| 24 | 28 |
| 25 #if defined(OS_POSIX) | 29 #if defined(OS_POSIX) |
| 26 if (type == Type::POSIX) { | 30 if (type == Type::POSIX) { |
| 27 bool success = (close(handle) == 0); | 31 bool success = (close(handle) == 0); |
| 28 DPCHECK(success); | 32 DPCHECK(success); |
| 29 handle = -1; | 33 handle = -1; |
| 30 } | 34 } |
| 31 #if defined(OS_MACOSX) && !defined(OS_IOS) | 35 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 32 else if (type == Type::MACH) { | 36 else if (type == Type::MACH) { |
| 33 kern_return_t rv = mach_port_deallocate(mach_task_self(), port); | 37 kern_return_t rv = mach_port_deallocate(mach_task_self(), port); |
| 34 DPCHECK(rv == KERN_SUCCESS); | 38 DPCHECK(rv == KERN_SUCCESS); |
| 35 port = MACH_PORT_NULL; | 39 port = MACH_PORT_NULL; |
| 36 } | 40 } |
| 37 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 41 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 42 #if defined(OS_ANDROID) |
| 43 else if (type == Type::PARCELABLE) |
| 44 parcelable.Reset(); |
| 45 #endif // defined(OS_ANDROID) |
| 38 #elif defined(OS_WIN) | 46 #elif defined(OS_WIN) |
| 39 if (owning_process != base::GetCurrentProcessHandle()) { | 47 if (owning_process != base::GetCurrentProcessHandle()) { |
| 40 // This handle may have been duplicated to a new target process but not yet | 48 // This handle may have been duplicated to a new target process but not yet |
| 41 // sent there. In this case CloseHandle should NOT be called. From MSDN | 49 // sent there. In this case CloseHandle should NOT be called. From MSDN |
| 42 // documentation for DuplicateHandle[1]: | 50 // documentation for DuplicateHandle[1]: |
| 43 // | 51 // |
| 44 // Normally the target process closes a duplicated handle when that | 52 // Normally the target process closes a duplicated handle when that |
| 45 // process is finished using the handle. To close a duplicated handle | 53 // process is finished using the handle. To close a duplicated handle |
| 46 // from the source process, call DuplicateHandle with the following | 54 // from the source process, call DuplicateHandle with the following |
| 47 // parameters: | 55 // parameters: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 65 bool success = !!CloseHandle(handle); | 73 bool success = !!CloseHandle(handle); |
| 66 DPCHECK(success); | 74 DPCHECK(success); |
| 67 handle = INVALID_HANDLE_VALUE; | 75 handle = INVALID_HANDLE_VALUE; |
| 68 #else | 76 #else |
| 69 #error "Platform not yet supported." | 77 #error "Platform not yet supported." |
| 70 #endif | 78 #endif |
| 71 } | 79 } |
| 72 | 80 |
| 73 } // namespace edk | 81 } // namespace edk |
| 74 } // namespace mojo | 82 } // namespace mojo |
| OLD | NEW |