blob: 9b0790093b0608adc83fff9dce981e94955af572 [file] [log] [blame]
morrita98b7aaa2015-01-26 22:42:541// 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#ifndef IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_
6#define IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_
7
morrita1aa788c2015-01-31 05:45:428#include "ipc/ipc_export.h"
morrita98b7aaa2015-01-26 22:42:549#include "ipc/ipc_message_attachment.h"
10
11namespace IPC {
12namespace internal {
13
14// A platform file that is sent over |Channel| as a part of |Message|.
morrita1aa788c2015-01-31 05:45:4215// PlatformFileAttachment optionally owns the file and |owning_| is set in that
16// case. Also, |file_| is not cleared even after the ownership is taken.
17// Some old clients require this strange behavior.
18class IPC_EXPORT PlatformFileAttachment : public MessageAttachment {
morrita98b7aaa2015-01-26 22:42:5419 public:
morrita1aa788c2015-01-31 05:45:4220 // Non-owning constructor
morrita98b7aaa2015-01-26 22:42:5421 explicit PlatformFileAttachment(base::PlatformFile file);
morrita1aa788c2015-01-31 05:45:4222 // Owning constructor
23 explicit PlatformFileAttachment(base::ScopedFD file);
morrita98b7aaa2015-01-26 22:42:5424
25 Type GetType() const override;
sammc6ed3efb2016-11-23 03:17:3526 base::PlatformFile TakePlatformFile();
morrita1aa788c2015-01-31 05:45:4227
morrita98b7aaa2015-01-26 22:42:5428 base::PlatformFile file() const { return file_; }
morrita1aa788c2015-01-31 05:45:4229 bool Owns() const { return owning_.is_valid(); }
morrita98b7aaa2015-01-26 22:42:5430
31 private:
32 ~PlatformFileAttachment() override;
33
34 base::PlatformFile file_;
morrita1aa788c2015-01-31 05:45:4235 base::ScopedFD owning_;
morrita98b7aaa2015-01-26 22:42:5436};
37
38base::PlatformFile GetPlatformFile(scoped_refptr<MessageAttachment> attachment);
39
40} // namespace internal
41} // namespace IPC
42
43#endif // IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_