Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef IPC_IPC_PLATFORM_FILE_H_ | 5 #ifndef IPC_IPC_PLATFORM_FILE_H_ |
| 6 #define IPC_IPC_PLATFORM_FILE_H_ | 6 #define IPC_IPC_PLATFORM_FILE_H_ |
| 7 | 7 |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/process/process.h" | 9 #include "base/process/process.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "ipc/ipc_export.h" | 11 #include "ipc/ipc_export.h" |
| 12 | 12 |
| 13 #if defined(OS_POSIX) | 13 #if defined(OS_POSIX) |
| 14 #include "base/file_descriptor_posix.h" | 14 #include "base/file_descriptor_posix.h" |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #if defined(OS_WIN) | |
| 18 #include "base/memory/shared_memory_handle.h" | |
| 19 #endif | |
| 20 | |
| 21 namespace IPC { | 17 namespace IPC { |
| 22 | 18 |
| 23 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
| 24 // The semantics for IPC transfer of a SharedMemoryHandle are exactly the same | 20 // The semantics for IPC transfer of a SharedMemoryHandle are exactly the same |
|
Mark Seaborn
2017/04/28 22:45:21
I think this reference to SharedMemoryHandle needs
erikchen
2017/04/28 23:24:37
This whole comment is no longer meaningful. Remove
| |
| 25 // as for a PlatformFileForTransit. The object wraps a HANDLE, and has some | 21 // as for a PlatformFileForTransit. The object wraps a HANDLE, and has some |
| 26 // metadata that indicates the process to which the HANDLE belongs. | 22 // metadata that indicates the process to which the HANDLE belongs. |
|
Mark Seaborn
2017/04/28 22:45:21
PlatformFileForTransit no longer has this metadata
erikchen
2017/04/28 23:24:37
This whole comment is no longer meaningful. Remove
| |
| 27 using PlatformFileForTransit = base::SharedMemoryHandle; | 23 class IPC_EXPORT PlatformFileForTransit { |
| 24 public: | |
| 25 // Creates an invalid platform file. | |
| 26 PlatformFileForTransit(); | |
| 27 | |
| 28 // Creates a platform file that takes unofficial ownership of |handle|. Note | |
| 29 // that ownership is not handled by a Scoped* class due to usage patterns of | |
| 30 // this class and its POSIX counterpart [base::FileDescriptor]. When this | |
| 31 // class is used as an input to an IPC message, the IPC subsystem will close | |
| 32 // |handle|. When this class is used as the output from an IPC message, the | |
| 33 // receiver is expected to take ownership of |handle|. | |
| 34 explicit PlatformFileForTransit(HANDLE handle); | |
| 35 | |
| 36 // Comparison operators. | |
| 37 bool operator==(const PlatformFileForTransit& platform_file) const; | |
| 38 bool operator!=(const PlatformFileForTransit& platform_file) const; | |
| 39 | |
| 40 HANDLE GetHandle() const; | |
| 41 bool IsValid() const; | |
| 42 | |
| 43 private: | |
| 44 HANDLE handle_; | |
| 45 }; | |
| 28 #elif defined(OS_POSIX) | 46 #elif defined(OS_POSIX) |
| 29 typedef base::FileDescriptor PlatformFileForTransit; | 47 typedef base::FileDescriptor PlatformFileForTransit; |
| 30 #endif | 48 #endif |
| 31 | 49 |
| 32 inline PlatformFileForTransit InvalidPlatformFileForTransit() { | 50 inline PlatformFileForTransit InvalidPlatformFileForTransit() { |
| 33 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 34 return PlatformFileForTransit(); | 52 return PlatformFileForTransit(); |
| 35 #elif defined(OS_POSIX) | 53 #elif defined(OS_POSIX) |
| 36 return base::FileDescriptor(); | 54 return base::FileDescriptor(); |
| 37 #endif | 55 #endif |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 62 bool close_source_handle); | 80 bool close_source_handle); |
| 63 | 81 |
| 64 // Creates a new handle that can be passed through IPC. The result must be | 82 // Creates a new handle that can be passed through IPC. The result must be |
| 65 // passed to the IPC layer as part of a message, or else it will leak. | 83 // passed to the IPC layer as part of a message, or else it will leak. |
| 66 // Note that this function takes ownership of |file|. | 84 // Note that this function takes ownership of |file|. |
| 67 IPC_EXPORT PlatformFileForTransit TakePlatformFileForTransit(base::File file); | 85 IPC_EXPORT PlatformFileForTransit TakePlatformFileForTransit(base::File file); |
| 68 | 86 |
| 69 } // namespace IPC | 87 } // namespace IPC |
| 70 | 88 |
| 71 #endif // IPC_IPC_PLATFORM_FILE_H_ | 89 #endif // IPC_IPC_PLATFORM_FILE_H_ |
| OLD | NEW |