ipc_platform_file_attachment_posix.h 1.4 KB

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