ipc_platform_file_attachment_posix.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. #include "ipc/ipc_platform_file_attachment_posix.h"
  5. #include <tuple>
  6. #include <utility>
  7. namespace IPC {
  8. namespace internal {
  9. PlatformFileAttachment::PlatformFileAttachment(base::PlatformFile file)
  10. : file_(file) {
  11. }
  12. PlatformFileAttachment::PlatformFileAttachment(base::ScopedFD file)
  13. : file_(file.get()), owning_(std::move(file)) {}
  14. PlatformFileAttachment::~PlatformFileAttachment() = default;
  15. MessageAttachment::Type PlatformFileAttachment::GetType() const {
  16. return Type::PLATFORM_FILE;
  17. }
  18. base::PlatformFile PlatformFileAttachment::TakePlatformFile() {
  19. std::ignore = owning_.release();
  20. return file_;
  21. }
  22. base::PlatformFile GetPlatformFile(
  23. scoped_refptr<MessageAttachment> attachment) {
  24. DCHECK_EQ(attachment->GetType(), MessageAttachment::Type::PLATFORM_FILE);
  25. return static_cast<PlatformFileAttachment*>(attachment.get())->file();
  26. }
  27. } // namespace internal
  28. } // namespace IPC