| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 #include "ipc/ipc_platform_file.h" | 6 #include "ipc/ipc_platform_file.h" |
| 7 | 7 |
| 8 #if defined(OS_POSIX) | 8 #if defined(OS_POSIX) |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 namespace IPC { | 12 namespace IPC { |
| 13 | 13 |
| 14 PlatformFileForTransit GetFileHandleForProcess(base::PlatformFile handle, | 14 PlatformFileForTransit GetPlatformFileForTransit(base::PlatformFile handle, |
| 15 base::ProcessHandle process, | 15 bool close_source_handle) { |
| 16 bool close_source_handle) { | |
| 17 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
| 18 HANDLE raw_handle = INVALID_HANDLE_VALUE; | 17 HANDLE raw_handle = INVALID_HANDLE_VALUE; |
| 19 DWORD options = DUPLICATE_SAME_ACCESS; | 18 DWORD options = DUPLICATE_SAME_ACCESS; |
| 20 if (close_source_handle) | 19 if (close_source_handle) |
| 21 options |= DUPLICATE_CLOSE_SOURCE; | 20 options |= DUPLICATE_CLOSE_SOURCE; |
| 22 if (handle == INVALID_HANDLE_VALUE || | 21 if (handle == INVALID_HANDLE_VALUE || |
| 23 !::DuplicateHandle(::GetCurrentProcess(), handle, ::GetCurrentProcess(), | 22 !::DuplicateHandle(::GetCurrentProcess(), handle, ::GetCurrentProcess(), |
| 24 &raw_handle, 0, FALSE, options)) { | 23 &raw_handle, 0, FALSE, options)) { |
| 25 return IPC::InvalidPlatformFileForTransit(); | 24 return IPC::InvalidPlatformFileForTransit(); |
| 26 } | 25 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 40 // condition. | 39 // condition. |
| 41 int fd = close_source_handle ? handle : ::dup(handle); | 40 int fd = close_source_handle ? handle : ::dup(handle); |
| 42 return base::FileDescriptor(fd, true); | 41 return base::FileDescriptor(fd, true); |
| 43 #else | 42 #else |
| 44 #error Not implemented. | 43 #error Not implemented. |
| 45 #endif | 44 #endif |
| 46 } | 45 } |
| 47 | 46 |
| 48 PlatformFileForTransit TakeFileHandleForProcess(base::File file, | 47 PlatformFileForTransit TakeFileHandleForProcess(base::File file, |
| 49 base::ProcessHandle process) { | 48 base::ProcessHandle process) { |
| 50 return GetFileHandleForProcess(file.TakePlatformFile(), process, true); | 49 return GetPlatformFileForTransit(file.TakePlatformFile(), true); |
| 51 } | 50 } |
| 52 | 51 |
| 53 } // namespace IPC | 52 } // namespace IPC |
| OLD | NEW |