1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 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" 9#include "base/files/file.h" 10#include "base/process/process.h" 11#include "ipc/ipc_export.h" 12 13#if defined(OS_POSIX) 14#include "base/file_descriptor_posix.h" 15#endif 16 17namespace IPC { 18 19#if defined(OS_WIN) 20typedef base::PlatformFile PlatformFileForTransit; 21#elif defined(OS_POSIX) 22typedef base::FileDescriptor PlatformFileForTransit; 23#endif 24 25inline PlatformFileForTransit InvalidPlatformFileForTransit() { 26#if defined(OS_WIN) 27 return INVALID_HANDLE_VALUE; 28#elif defined(OS_POSIX) 29 return base::FileDescriptor(); 30#endif 31} 32 33inline 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 42inline 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 51// Returns a file handle equivalent to |file| that can be used in |process|. 52IPC_EXPORT PlatformFileForTransit GetFileHandleForProcess( 53 base::PlatformFile file, 54 base::ProcessHandle process, 55 bool close_source_handle); 56 57// Returns a file handle equivalent to |file| that can be used in |process|. 58// Note that this function takes ownership of |file|. 59IPC_EXPORT PlatformFileForTransit TakeFileHandleForProcess( 60 base::File file, 61 base::ProcessHandle process); 62 63} // namespace IPC 64 65#endif // IPC_IPC_PLATFORM_FILE_H_ 66