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