blob: 7deea91bbc8b93c41523cb2d7a940f3ecef8815b [file] [log] [blame]
Avi Drissmanea1be232022-09-14 23:29:061// Copyright 2015 The Chromium Authors
morrita98b7aaa2015-01-26 22:42:542// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Lei Zhang9a1bc18f2019-08-30 07:18:555#ifndef IPC_IPC_PLATFORM_FILE_ATTACHMENT_POSIX_H_
6#define IPC_IPC_PLATFORM_FILE_ATTACHMENT_POSIX_H_
morrita98b7aaa2015-01-26 22:42:547
Lei Zhang9a1bc18f2019-08-30 07:18:558#include "base/files/platform_file.h"
9#include "base/files/scoped_file.h"
morrita98b7aaa2015-01-26 22:42:5410#include "ipc/ipc_message_attachment.h"
Ken Rockotfd907632017-09-14 04:23:4111#include "ipc/ipc_message_support_export.h"
morrita98b7aaa2015-01-26 22:42:5412
13namespace IPC {
14namespace internal {
15
16// A platform file that is sent over |Channel| as a part of |Message|.
morrita1aa788c2015-01-31 05:45:4217// PlatformFileAttachment optionally owns the file and |owning_| is set in that
18// case. Also, |file_| is not cleared even after the ownership is taken.
19// Some old clients require this strange behavior.
Ken Rockotfd907632017-09-14 04:23:4120class IPC_MESSAGE_SUPPORT_EXPORT PlatformFileAttachment
21 : public MessageAttachment {
morrita98b7aaa2015-01-26 22:42:5422 public:
morrita1aa788c2015-01-31 05:45:4223 // Non-owning constructor
morrita98b7aaa2015-01-26 22:42:5424 explicit PlatformFileAttachment(base::PlatformFile file);
morrita1aa788c2015-01-31 05:45:4225 // Owning constructor
26 explicit PlatformFileAttachment(base::ScopedFD file);
morrita98b7aaa2015-01-26 22:42:5427
28 Type GetType() const override;
sammc6ed3efb2016-11-23 03:17:3529 base::PlatformFile TakePlatformFile();
morrita1aa788c2015-01-31 05:45:4230
morrita98b7aaa2015-01-26 22:42:5431 base::PlatformFile file() const { return file_; }
morrita1aa788c2015-01-31 05:45:4232 bool Owns() const { return owning_.is_valid(); }
morrita98b7aaa2015-01-26 22:42:5433
34 private:
35 ~PlatformFileAttachment() override;
36
37 base::PlatformFile file_;
morrita1aa788c2015-01-31 05:45:4238 base::ScopedFD owning_;
morrita98b7aaa2015-01-26 22:42:5439};
40
41base::PlatformFile GetPlatformFile(scoped_refptr<MessageAttachment> attachment);
42
43} // namespace internal
44} // namespace IPC
45
Lei Zhang9a1bc18f2019-08-30 07:18:5546#endif // IPC_IPC_PLATFORM_FILE_ATTACHMENT_POSIX_H_