blob: ae41cd03d34e2ecd078c43e2f042873c38219d4a [file] [log] [blame]
erikchen1c1e6652015-10-01 18:51:321// Copyright 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_MACH_PORT_ATTACHMENT_MAC_H_
6#define IPC_MACH_PORT_ATTACHMENT_MAC_H_
7
8#include <mach/mach.h>
9#include <stdint.h>
10
avi246998d82015-12-22 02:39:0411#include "base/macros.h"
erikchen1c1e6652015-10-01 18:51:3212#include "base/process/process_handle.h"
sammc6ed3efb2016-11-23 03:17:3513#include "ipc/ipc_message_attachment.h"
Ken Rockotfd907632017-09-14 04:23:4114#include "ipc/ipc_message_support_export.h"
erikchen1c1e6652015-10-01 18:51:3215#include "ipc/mach_port_mac.h"
16
17namespace IPC {
18namespace internal {
19
20// This class represents an OSX mach_port_t attached to a Chrome IPC message.
Ken Rockotfd907632017-09-14 04:23:4121class IPC_MESSAGE_SUPPORT_EXPORT MachPortAttachmentMac
22 : public MessageAttachment {
erikchen1c1e6652015-10-01 18:51:3223 public:
erikchen3722a322015-10-07 20:51:5524 // This constructor increments the ref count of |mach_port_| and takes
25 // ownership of the result. Should only be called by the sender of a Chrome
26 // IPC message.
erikchen1c1e6652015-10-01 18:51:3227 explicit MachPortAttachmentMac(mach_port_t mach_port);
erikchen3722a322015-10-07 20:51:5528
sammc57ed9f982016-03-10 06:28:3529 enum FromWire {
30 FROM_WIRE,
31 };
32 // This constructor takes ownership of |mach_port|, but does not modify its
33 // ref count. Should only be called by the receiver of a Chrome IPC message.
34 MachPortAttachmentMac(mach_port_t mach_port, FromWire from_wire);
35
sammc6ed3efb2016-11-23 03:17:3536 Type GetType() const override;
erikchen1c1e6652015-10-01 18:51:3237
38 mach_port_t get_mach_port() const { return mach_port_; }
39
erikchen3722a322015-10-07 20:51:5540 // The caller of this method has taken ownership of |mach_port_|.
41 void reset_mach_port_ownership() { owns_mach_port_ = false; }
42
erikchen1c1e6652015-10-01 18:51:3243 private:
44 ~MachPortAttachmentMac() override;
erikchenfa705362015-10-30 23:16:2945 const mach_port_t mach_port_;
erikchen3722a322015-10-07 20:51:5546
47 // In the sender process, the attachment owns the Mach port of a newly created
erikchen8a6f3f4e2016-01-06 22:04:4348 // message. The attachment broker will eventually take ownership of
49 // |mach_port_|.
50 // In the destination process, the attachment owns |mach_port_| until
51 // ParamTraits<MachPortMac>::Read() is called, which takes ownership.
erikchen3722a322015-10-07 20:51:5552 bool owns_mach_port_;
53 DISALLOW_COPY_AND_ASSIGN(MachPortAttachmentMac);
erikchen1c1e6652015-10-01 18:51:3254};
55
56} // namespace internal
57} // namespace IPC
58
59#endif // IPC_MACH_PORT_ATTACHMENT_MAC_H_