jcivelli@chromium.org | 3bab103 | 2011-06-15 04:35:10 +0900 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
estade@chromium.org | 3ac3206 | 2009-11-17 07:55:17 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef IPC_IPC_PLATFORM_FILE_H_ |
| 6 | #define IPC_IPC_PLATFORM_FILE_H_ |
| 7 | |
| 8 | #include "base/basictypes.h" |
rvargas@chromium.org | 9e469f6 | 2014-01-28 06:36:00 +0900 | [diff] [blame] | 9 | #include "base/files/file.h" |
rsesek@chromium.org | 1931971 | 2013-07-24 14:15:24 +0900 | [diff] [blame] | 10 | #include "base/process/process.h" |
darin@chromium.org | 80e4c5e | 2011-08-16 05:41:46 +0900 | [diff] [blame] | 11 | #include "ipc/ipc_export.h" |
estade@chromium.org | 3ac3206 | 2009-11-17 07:55:17 +0900 | [diff] [blame] | 12 | |
| 13 | #if defined(OS_POSIX) |
| 14 | #include "base/file_descriptor_posix.h" |
| 15 | #endif |
| 16 | |
| 17 | namespace IPC { |
| 18 | |
| 19 | #if defined(OS_WIN) |
| 20 | typedef base::PlatformFile PlatformFileForTransit; |
| 21 | #elif defined(OS_POSIX) |
| 22 | typedef base::FileDescriptor PlatformFileForTransit; |
| 23 | #endif |
| 24 | |
estade@chromium.org | d996345 | 2009-12-18 09:23:05 +0900 | [diff] [blame] | 25 | inline PlatformFileForTransit InvalidPlatformFileForTransit() { |
| 26 | #if defined(OS_WIN) |
rvargas@chromium.org | 01585f2 | 2014-06-10 21:58:29 +0900 | [diff] [blame] | 27 | return INVALID_HANDLE_VALUE; |
estade@chromium.org | d996345 | 2009-12-18 09:23:05 +0900 | [diff] [blame] | 28 | #elif defined(OS_POSIX) |
| 29 | return base::FileDescriptor(); |
| 30 | #endif |
| 31 | } |
| 32 | |
estade@chromium.org | 3ac3206 | 2009-11-17 07:55:17 +0900 | [diff] [blame] | 33 | inline base::PlatformFile PlatformFileForTransitToPlatformFile( |
| 34 | const PlatformFileForTransit& transit) { |
| 35 | #if defined(OS_WIN) |
| 36 | return transit; |
| 37 | #elif defined(OS_POSIX) |
| 38 | return transit.fd; |
| 39 | #endif |
| 40 | } |
| 41 | |
rvargas@chromium.org | 5e1b33d | 2014-03-25 15:01:48 +0900 | [diff] [blame] | 42 | inline base::File PlatformFileForTransitToFile( |
| 43 | const PlatformFileForTransit& transit) { |
| 44 | #if defined(OS_WIN) |
| 45 | return base::File(transit); |
| 46 | #elif defined(OS_POSIX) |
| 47 | return base::File(transit.fd); |
| 48 | #endif |
| 49 | } |
| 50 | |
jcivelli@chromium.org | 3bab103 | 2011-06-15 04:35:10 +0900 | [diff] [blame] | 51 | // Returns a file handle equivalent to |file| that can be used in |process|. |
darin@chromium.org | 80e4c5e | 2011-08-16 05:41:46 +0900 | [diff] [blame] | 52 | IPC_EXPORT PlatformFileForTransit GetFileHandleForProcess( |
| 53 | base::PlatformFile file, |
| 54 | base::ProcessHandle process, |
| 55 | bool close_source_handle); |
jcivelli@chromium.org | 3bab103 | 2011-06-15 04:35:10 +0900 | [diff] [blame] | 56 | |
rvargas@chromium.org | f40fe38 | 2014-03-06 05:13:49 +0900 | [diff] [blame] | 57 | // Returns a file handle equivalent to |file| that can be used in |process|. |
| 58 | // Note that this function takes ownership of |file|. |
| 59 | IPC_EXPORT PlatformFileForTransit TakeFileHandleForProcess( |
| 60 | base::File file, |
| 61 | base::ProcessHandle process); |
| 62 | |
estade@chromium.org | 3ac3206 | 2009-11-17 07:55:17 +0900 | [diff] [blame] | 63 | } // namespace IPC |
| 64 | |
| 65 | #endif // IPC_IPC_PLATFORM_FILE_H_ |