blob: d1eff609c5340b8c617dcd4a069875121eed1212 [file] [log] [blame]
morrita6308f322015-01-27 07:42:54 +09001// 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
morrita7d1bfcc2015-01-31 14:45:42 +09008#include "ipc/ipc_export.h"
morrita6308f322015-01-27 07:42:54 +09009#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|.
morrita7d1bfcc2015-01-31 14:45:42 +090015// 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 {
morrita6308f322015-01-27 07:42:54 +090019 public:
morrita7d1bfcc2015-01-31 14:45:42 +090020 // Non-owning constructor
morrita6308f322015-01-27 07:42:54 +090021 explicit PlatformFileAttachment(base::PlatformFile file);
morrita7d1bfcc2015-01-31 14:45:42 +090022 // Owning constructor
23 explicit PlatformFileAttachment(base::ScopedFD file);
morrita6308f322015-01-27 07:42:54 +090024
25 Type GetType() const override;
morrita7d1bfcc2015-01-31 14:45:42 +090026 base::PlatformFile TakePlatformFile() override;
27
morrita6308f322015-01-27 07:42:54 +090028 base::PlatformFile file() const { return file_; }
morrita7d1bfcc2015-01-31 14:45:42 +090029 bool Owns() const { return owning_.is_valid(); }
morrita6308f322015-01-27 07:42:54 +090030
31 private:
32 ~PlatformFileAttachment() override;
33
34 base::PlatformFile file_;
morrita7d1bfcc2015-01-31 14:45:42 +090035 base::ScopedFD owning_;
morrita6308f322015-01-27 07:42:54 +090036};
37
38base::PlatformFile GetPlatformFile(scoped_refptr<MessageAttachment> attachment);
39
40} // namespace internal
41} // namespace IPC
42
43#endif // IPC_IPC_PLATFORM_FILE_ATTACHMENT_H_