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" |
estade@chromium.org | 3ac3206 | 2009-11-17 07:55:17 +0900 | [diff] [blame] | 10 | #include "base/platform_file.h" |
rsesek@chromium.org | 1931971 | 2013-07-24 14:15:24 +0900 | [diff] [blame] | 11 | #include "base/process/process.h" |
darin@chromium.org | 80e4c5e | 2011-08-16 05:41:46 +0900 | [diff] [blame] | 12 | #include "ipc/ipc_export.h" |
estade@chromium.org | 3ac3206 | 2009-11-17 07:55:17 +0900 | [diff] [blame] | 13 | |
| 14 | #if defined(OS_POSIX) |
| 15 | #include "base/file_descriptor_posix.h" |
| 16 | #endif |
| 17 | |
| 18 | namespace IPC { |
| 19 | |
| 20 | #if defined(OS_WIN) |
| 21 | typedef base::PlatformFile PlatformFileForTransit; |
| 22 | #elif defined(OS_POSIX) |
| 23 | typedef base::FileDescriptor PlatformFileForTransit; |
| 24 | #endif |
| 25 | |
estade@chromium.org | d996345 | 2009-12-18 09:23:05 +0900 | [diff] [blame] | 26 | inline PlatformFileForTransit InvalidPlatformFileForTransit() { |
| 27 | #if defined(OS_WIN) |
| 28 | return base::kInvalidPlatformFileValue; |
| 29 | #elif defined(OS_POSIX) |
| 30 | return base::FileDescriptor(); |
| 31 | #endif |
| 32 | } |
| 33 | |
estade@chromium.org | 3ac3206 | 2009-11-17 07:55:17 +0900 | [diff] [blame] | 34 | inline base::PlatformFile PlatformFileForTransitToPlatformFile( |
| 35 | const PlatformFileForTransit& transit) { |
| 36 | #if defined(OS_WIN) |
| 37 | return transit; |
| 38 | #elif defined(OS_POSIX) |
| 39 | return transit.fd; |
| 40 | #endif |
| 41 | } |
| 42 | |
rvargas@chromium.org | 5e1b33d | 2014-03-25 15:01:48 +0900 | [diff] [blame^] | 43 | inline base::File PlatformFileForTransitToFile( |
| 44 | const PlatformFileForTransit& transit) { |
| 45 | #if defined(OS_WIN) |
| 46 | return base::File(transit); |
| 47 | #elif defined(OS_POSIX) |
| 48 | return base::File(transit.fd); |
| 49 | #endif |
| 50 | } |
| 51 | |
jcivelli@chromium.org | 3bab103 | 2011-06-15 04:35:10 +0900 | [diff] [blame] | 52 | // 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] | 53 | IPC_EXPORT PlatformFileForTransit GetFileHandleForProcess( |
| 54 | base::PlatformFile file, |
| 55 | base::ProcessHandle process, |
| 56 | bool close_source_handle); |
jcivelli@chromium.org | 3bab103 | 2011-06-15 04:35:10 +0900 | [diff] [blame] | 57 | |
rvargas@chromium.org | f40fe38 | 2014-03-06 05:13:49 +0900 | [diff] [blame] | 58 | // Returns a file handle equivalent to |file| that can be used in |process|. |
| 59 | // Note that this function takes ownership of |file|. |
| 60 | IPC_EXPORT PlatformFileForTransit TakeFileHandleForProcess( |
| 61 | base::File file, |
| 62 | base::ProcessHandle process); |
| 63 | |
estade@chromium.org | 3ac3206 | 2009-11-17 07:55:17 +0900 | [diff] [blame] | 64 | } // namespace IPC |
| 65 | |
| 66 | #endif // IPC_IPC_PLATFORM_FILE_H_ |