OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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_ATTACHMENT_H_ | 5 #ifndef IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_ |
6 #define IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_ | 6 #define IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_ |
7 | 7 |
8 #include "base/files/file.h" | 8 #include "ipc/ipc_export.h" |
9 #include "ipc/ipc_message_attachment.h" | 9 #include "ipc/ipc_message_attachment.h" |
10 | 10 |
11 namespace IPC { | 11 namespace IPC { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 // A platform file that is sent over |Channel| as a part of |Message|. | 14 // A platform file that is sent over |Channel| as a part of |Message|. |
15 // |PlatformFileAttachment| doesn't own |file_|. The lifecycle of |file_| is | 15 // PlatformFileAttachment optionally owns the file and |owning_| is set in that |
16 // managed by |MessageAttachmentSet|. | 16 // case. Also, |file_| is not cleared even after the ownership is taken. |
17 class PlatformFileAttachment : public MessageAttachment { | 17 // Some old clients require this strange behavior. |
| 18 class IPC_EXPORT PlatformFileAttachment : public MessageAttachment { |
18 public: | 19 public: |
| 20 // Non-owning constructor |
19 explicit PlatformFileAttachment(base::PlatformFile file); | 21 explicit PlatformFileAttachment(base::PlatformFile file); |
| 22 // Owning constructor |
| 23 explicit PlatformFileAttachment(base::ScopedFD file); |
20 | 24 |
21 Type GetType() const override; | 25 Type GetType() const override; |
| 26 base::PlatformFile TakePlatformFile() override; |
| 27 |
22 base::PlatformFile file() const { return file_; } | 28 base::PlatformFile file() const { return file_; } |
| 29 bool Owns() const { return owning_.is_valid(); } |
23 | 30 |
24 private: | 31 private: |
25 ~PlatformFileAttachment() override; | 32 ~PlatformFileAttachment() override; |
26 | 33 |
27 base::PlatformFile file_; | 34 base::PlatformFile file_; |
| 35 base::ScopedFD owning_; |
28 }; | 36 }; |
29 | 37 |
30 base::PlatformFile GetPlatformFile(scoped_refptr<MessageAttachment> attachment); | 38 base::PlatformFile GetPlatformFile(scoped_refptr<MessageAttachment> attachment); |
31 | 39 |
32 } // namespace internal | 40 } // namespace internal |
33 } // namespace IPC | 41 } // namespace IPC |
34 | 42 |
35 #endif // IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_ | 43 #endif // IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_ |
OLD | NEW |