Avi Drissman | ea1be23 | 2022-09-14 23:29:06 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [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 | |
Lei Zhang | 9a1bc18f | 2019-08-30 07:18:55 | [diff] [blame] | 5 | #ifndef IPC_IPC_PLATFORM_FILE_ATTACHMENT_POSIX_H_ |
| 6 | #define IPC_IPC_PLATFORM_FILE_ATTACHMENT_POSIX_H_ |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 7 | |
Lei Zhang | 9a1bc18f | 2019-08-30 07:18:55 | [diff] [blame] | 8 | #include "base/files/platform_file.h" |
| 9 | #include "base/files/scoped_file.h" |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 10 | #include "ipc/ipc_message_attachment.h" |
Ken Rockot | fd90763 | 2017-09-14 04:23:41 | [diff] [blame] | 11 | #include "ipc/ipc_message_support_export.h" |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 12 | |
| 13 | namespace IPC { |
| 14 | namespace internal { |
| 15 | |
| 16 | // A platform file that is sent over |Channel| as a part of |Message|. |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 17 | // PlatformFileAttachment optionally owns the file and |owning_| is set in that |
| 18 | // case. Also, |file_| is not cleared even after the ownership is taken. |
| 19 | // Some old clients require this strange behavior. |
Ken Rockot | fd90763 | 2017-09-14 04:23:41 | [diff] [blame] | 20 | class IPC_MESSAGE_SUPPORT_EXPORT PlatformFileAttachment |
| 21 | : public MessageAttachment { |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 22 | public: |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 23 | // Non-owning constructor |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 24 | explicit PlatformFileAttachment(base::PlatformFile file); |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 25 | // Owning constructor |
| 26 | explicit PlatformFileAttachment(base::ScopedFD file); |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 27 | |
| 28 | Type GetType() const override; |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 29 | base::PlatformFile TakePlatformFile(); |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 30 | |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 31 | base::PlatformFile file() const { return file_; } |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 32 | bool Owns() const { return owning_.is_valid(); } |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 33 | |
| 34 | private: |
| 35 | ~PlatformFileAttachment() override; |
| 36 | |
| 37 | base::PlatformFile file_; |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 38 | base::ScopedFD owning_; |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | base::PlatformFile GetPlatformFile(scoped_refptr<MessageAttachment> attachment); |
| 42 | |
| 43 | } // namespace internal |
| 44 | } // namespace IPC |
| 45 | |
Lei Zhang | 9a1bc18f | 2019-08-30 07:18:55 | [diff] [blame] | 46 | #endif // IPC_IPC_PLATFORM_FILE_ATTACHMENT_POSIX_H_ |