xref: /aosp_15_r20/external/cronet/ipc/ipc_platform_file_attachment_posix.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 #include "ipc/ipc_platform_file_attachment_posix.h"
6 
7 #include <tuple>
8 #include <utility>
9 
10 namespace IPC {
11 namespace internal {
12 
PlatformFileAttachment(base::PlatformFile file)13 PlatformFileAttachment::PlatformFileAttachment(base::PlatformFile file)
14     : file_(file) {
15 }
16 
PlatformFileAttachment(base::ScopedFD file)17 PlatformFileAttachment::PlatformFileAttachment(base::ScopedFD file)
18     : file_(file.get()), owning_(std::move(file)) {}
19 
20 PlatformFileAttachment::~PlatformFileAttachment() = default;
21 
GetType() const22 MessageAttachment::Type PlatformFileAttachment::GetType() const {
23   return Type::PLATFORM_FILE;
24 }
25 
TakePlatformFile()26 base::PlatformFile PlatformFileAttachment::TakePlatformFile() {
27   std::ignore = owning_.release();
28   return file_;
29 }
30 
GetPlatformFile(scoped_refptr<MessageAttachment> attachment)31 base::PlatformFile GetPlatformFile(
32     scoped_refptr<MessageAttachment> attachment) {
33   DCHECK_EQ(attachment->GetType(), MessageAttachment::Type::PLATFORM_FILE);
34   return static_cast<PlatformFileAttachment*>(attachment.get())->file();
35 }
36 
37 }  // namespace internal
38 }  // namespace IPC
39