[email protected] | e7f009d | 2011-06-14 19:35:10 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [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 | |||||
[email protected] | 141bcc5 | 2014-01-27 21:36:00 | [diff] [blame] | 8 | #include "base/files/file.h" |
[email protected] | e66ef60 | 2013-07-24 05:15:24 | [diff] [blame] | 9 | #include "base/process/process.h" |
[email protected] | 7c85437 | 2011-08-15 20:41:46 | [diff] [blame] | 10 | #include "ipc/ipc_export.h" |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 11 | |
12 | #if defined(OS_POSIX) | ||||
13 | #include "base/file_descriptor_posix.h" | ||||
14 | #endif | ||||
15 | |||||
16 | namespace IPC { | ||||
17 | |||||
18 | #if defined(OS_WIN) | ||||
19 | typedef base::PlatformFile PlatformFileForTransit; | ||||
20 | #elif defined(OS_POSIX) | ||||
21 | typedef base::FileDescriptor PlatformFileForTransit; | ||||
22 | #endif | ||||
23 | |||||
[email protected] | a784b84 | 2009-12-18 00:23:05 | [diff] [blame] | 24 | inline PlatformFileForTransit InvalidPlatformFileForTransit() { |
25 | #if defined(OS_WIN) | ||||
[email protected] | dd7a8a4 | 2014-06-10 12:58:29 | [diff] [blame] | 26 | return INVALID_HANDLE_VALUE; |
[email protected] | a784b84 | 2009-12-18 00:23:05 | [diff] [blame] | 27 | #elif defined(OS_POSIX) |
28 | return base::FileDescriptor(); | ||||
29 | #endif | ||||
30 | } | ||||
31 | |||||
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 32 | inline base::PlatformFile PlatformFileForTransitToPlatformFile( |
33 | const PlatformFileForTransit& transit) { | ||||
34 | #if defined(OS_WIN) | ||||
35 | return transit; | ||||
36 | #elif defined(OS_POSIX) | ||||
37 | return transit.fd; | ||||
38 | #endif | ||||
39 | } | ||||
40 | |||||
[email protected] | 008e3b3 | 2014-03-25 06:01:48 | [diff] [blame] | 41 | inline base::File PlatformFileForTransitToFile( |
42 | const PlatformFileForTransit& transit) { | ||||
43 | #if defined(OS_WIN) | ||||
44 | return base::File(transit); | ||||
45 | #elif defined(OS_POSIX) | ||||
46 | return base::File(transit.fd); | ||||
47 | #endif | ||||
48 | } | ||||
49 | |||||
[email protected] | e7f009d | 2011-06-14 19:35:10 | [diff] [blame] | 50 | // Returns a file handle equivalent to |file| that can be used in |process|. |
[email protected] | 7c85437 | 2011-08-15 20:41:46 | [diff] [blame] | 51 | IPC_EXPORT PlatformFileForTransit GetFileHandleForProcess( |
52 | base::PlatformFile file, | ||||
53 | base::ProcessHandle process, | ||||
54 | bool close_source_handle); | ||||
[email protected] | e7f009d | 2011-06-14 19:35:10 | [diff] [blame] | 55 | |
[email protected] | 8880e70 | 2014-03-05 20:13:49 | [diff] [blame] | 56 | // Returns a file handle equivalent to |file| that can be used in |process|. |
57 | // Note that this function takes ownership of |file|. | ||||
58 | IPC_EXPORT PlatformFileForTransit TakeFileHandleForProcess( | ||||
59 | base::File file, | ||||
60 | base::ProcessHandle process); | ||||
61 | |||||
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 62 | } // namespace IPC |
63 | |||||
64 | #endif // IPC_IPC_PLATFORM_FILE_H_ |