1 // Copyright 2015 The Chromium Authors 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_ATTACHMENT_POSIX_H_ 6 #define IPC_IPC_PLATFORM_FILE_ATTACHMENT_POSIX_H_ 7 8 #include "base/files/platform_file.h" 9 #include "base/files/scoped_file.h" 10 #include "ipc/ipc_message_attachment.h" 11 #include "ipc/ipc_message_support_export.h" 12 13 namespace IPC { 14 namespace internal { 15 16 // A platform file that is sent over |Channel| as a part of |Message|. 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. 20 class IPC_MESSAGE_SUPPORT_EXPORT PlatformFileAttachment 21 : public MessageAttachment { 22 public: 23 // Non-owning constructor 24 explicit PlatformFileAttachment(base::PlatformFile file); 25 // Owning constructor 26 explicit PlatformFileAttachment(base::ScopedFD file); 27 28 Type GetType() const override; 29 base::PlatformFile TakePlatformFile(); 30 file()31 base::PlatformFile file() const { return file_; } Owns()32 bool Owns() const { return owning_.is_valid(); } 33 34 private: 35 ~PlatformFileAttachment() override; 36 37 base::PlatformFile file_; 38 base::ScopedFD owning_; 39 }; 40 41 base::PlatformFile GetPlatformFile(scoped_refptr<MessageAttachment> attachment); 42 43 } // namespace internal 44 } // namespace IPC 45 46 #endif // IPC_IPC_PLATFORM_FILE_ATTACHMENT_POSIX_H_ 47