morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 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 | |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 5 | #include "ipc/ipc_platform_file_attachment_posix.h" |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 6 | |
danakj | e3de838f | 2015-12-03 01:49:40 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 9 | namespace IPC { |
| 10 | namespace internal { |
| 11 | |
| 12 | PlatformFileAttachment::PlatformFileAttachment(base::PlatformFile file) |
| 13 | : file_(file) { |
| 14 | } |
| 15 | |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 16 | PlatformFileAttachment::PlatformFileAttachment(base::ScopedFD file) |
danakj | e3de838f | 2015-12-03 01:49:40 | [diff] [blame] | 17 | : file_(file.get()), owning_(std::move(file)) {} |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 18 | |
Chris Watkins | 2d879af | 2017-11-30 02:11:59 | [diff] [blame] | 19 | PlatformFileAttachment::~PlatformFileAttachment() = default; |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 20 | |
| 21 | MessageAttachment::Type PlatformFileAttachment::GetType() const { |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 22 | return Type::PLATFORM_FILE; |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 23 | } |
| 24 | |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 25 | base::PlatformFile PlatformFileAttachment::TakePlatformFile() { |
| 26 | ignore_result(owning_.release()); |
| 27 | return file_; |
| 28 | } |
| 29 | |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 30 | base::PlatformFile GetPlatformFile( |
| 31 | scoped_refptr<MessageAttachment> attachment) { |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 32 | DCHECK_EQ(attachment->GetType(), MessageAttachment::Type::PLATFORM_FILE); |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 33 | return static_cast<PlatformFileAttachment*>(attachment.get())->file(); |
| 34 | } |
| 35 | |
| 36 | } // namespace internal |
| 37 | } // namespace IPC |