blob: 9c92f37b5ab24667de7797c3e720d2c9555bf8f4 [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_MESSAGE_ATTACHMENT_H_
6#define IPC_IPC_MESSAGE_ATTACHMENT_H_
7
morrita1aa788c2015-01-31 05:45:428#include "base/files/file.h"
9#include "base/macros.h"
morrita98b7aaa2015-01-26 22:42:5410#include "base/memory/ref_counted.h"
rockot502c94f2016-02-03 20:20:1611#include "base/pickle.h"
avi246998d82015-12-22 02:39:0412#include "build/build_config.h"
Ken Rockotfd907632017-09-14 04:23:4113#include "ipc/ipc_message_support_export.h"
14#include "mojo/public/cpp/system/handle.h"
morrita98b7aaa2015-01-26 22:42:5415
16namespace IPC {
17
18// Auxiliary data sent with |Message|. This can be a platform file descriptor
19// or a mojo |MessagePipe|. |GetType()| returns the type of the subclass.
Ken Rockotfd907632017-09-14 04:23:4120class IPC_MESSAGE_SUPPORT_EXPORT MessageAttachment
21 : public base::Pickle::Attachment {
morrita98b7aaa2015-01-26 22:42:5422 public:
Ken Rockotfd907632017-09-14 04:23:4123 enum class Type {
24 MOJO_HANDLE,
25 PLATFORM_FILE,
26 WIN_HANDLE,
27 MACH_PORT,
28 FUCHSIA_HANDLE,
29 };
30
31 static scoped_refptr<MessageAttachment> CreateFromMojoHandle(
32 mojo::ScopedHandle handle,
33 Type type);
morrita98b7aaa2015-01-26 22:42:5434
35 virtual Type GetType() const = 0;
morrita81b17e02015-02-06 00:58:3036
Ken Rockotfd907632017-09-14 04:23:4137 mojo::ScopedHandle TakeMojoHandle();
38
morrita98b7aaa2015-01-26 22:42:5439 protected:
erikchenfa705362015-10-30 23:16:2940 friend class base::RefCountedThreadSafe<MessageAttachment>;
morrita1aa788c2015-01-31 05:45:4241 MessageAttachment();
rockot502c94f2016-02-03 20:20:1642 ~MessageAttachment() override;
morrita1aa788c2015-01-31 05:45:4243
44 DISALLOW_COPY_AND_ASSIGN(MessageAttachment);
morrita98b7aaa2015-01-26 22:42:5445};
46
47} // namespace IPC
48
49#endif // IPC_IPC_MESSAGE_ATTACHMENT_H_