mach_port_attachment_mac.h 2.0 KB

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