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