blob: 7111cfa0bbb4979d7ff3eb67848c94ccc925baf5 [file] [log] [blame]
Luis Hector Chavez645501c2016-12-28 10:56:26 -08001// 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
9namespace IPC {
10namespace internal {
11
12PlatformFileAttachment::PlatformFileAttachment(base::PlatformFile file)
13 : file_(file) {
14}
15
16PlatformFileAttachment::PlatformFileAttachment(base::ScopedFD file)
17 : file_(file.get()), owning_(std::move(file)) {}
18
19PlatformFileAttachment::~PlatformFileAttachment() {
20}
21
22MessageAttachment::Type PlatformFileAttachment::GetType() const {
Jay Civellicfc1eaa2017-08-21 17:18:10 -070023 return Type::PLATFORM_FILE;
Luis Hector Chavez645501c2016-12-28 10:56:26 -080024}
25
26base::PlatformFile PlatformFileAttachment::TakePlatformFile() {
27 ignore_result(owning_.release());
28 return file_;
29}
30
31base::PlatformFile GetPlatformFile(
32 scoped_refptr<MessageAttachment> attachment) {
Jay Civellicfc1eaa2017-08-21 17:18:10 -070033 DCHECK_EQ(attachment->GetType(), MessageAttachment::Type::PLATFORM_FILE);
Luis Hector Chavez645501c2016-12-28 10:56:26 -080034 return static_cast<PlatformFileAttachment*>(attachment.get())->file();
35}
36
37} // namespace internal
38} // namespace IPC