1 // Copyright 2015 The Chromium Authors 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 11 #include "base/process/process_handle.h" 12 #include "ipc/ipc_message_attachment.h" 13 #include "ipc/ipc_message_support_export.h" 14 #include "ipc/mach_port_mac.h" 15 16 namespace IPC { 17 namespace internal { 18 19 // This class represents an OSX mach_port_t attached to a Chrome IPC message. 20 class IPC_MESSAGE_SUPPORT_EXPORT MachPortAttachmentMac 21 : public MessageAttachment { 22 public: 23 // This constructor increments the ref count of |mach_port_| and takes 24 // ownership of the result. Should only be called by the sender of a Chrome 25 // IPC message. 26 explicit MachPortAttachmentMac(mach_port_t mach_port); 27 28 MachPortAttachmentMac(const MachPortAttachmentMac&) = delete; 29 MachPortAttachmentMac& operator=(const MachPortAttachmentMac&) = delete; 30 31 enum FromWire { 32 FROM_WIRE, 33 }; 34 // This constructor takes ownership of |mach_port|, but does not modify its 35 // ref count. Should only be called by the receiver of a Chrome IPC message. 36 MachPortAttachmentMac(mach_port_t mach_port, FromWire from_wire); 37 38 Type GetType() const override; 39 get_mach_port()40 mach_port_t get_mach_port() const { return mach_port_; } 41 42 // The caller of this method has taken ownership of |mach_port_|. reset_mach_port_ownership()43 void reset_mach_port_ownership() { owns_mach_port_ = false; } 44 45 private: 46 ~MachPortAttachmentMac() override; 47 const mach_port_t mach_port_; 48 49 // In the sender process, the attachment owns the Mach port of a newly created 50 // message. The attachment broker will eventually take ownership of 51 // |mach_port_|. 52 // In the destination process, the attachment owns |mach_port_| until 53 // ParamTraits<MachPortMac>::Read() is called, which takes ownership. 54 bool owns_mach_port_; 55 }; 56 57 } // namespace internal 58 } // namespace IPC 59 60 #endif // IPC_MACH_PORT_ATTACHMENT_MAC_H_ 61