mach_port_attachment_mac.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #include "ipc/mach_port_attachment_mac.h"
  5. #include <stdint.h>
  6. #include "base/mac/mach_logging.h"
  7. namespace IPC {
  8. namespace internal {
  9. MachPortAttachmentMac::MachPortAttachmentMac(mach_port_t mach_port)
  10. : mach_port_(mach_port), owns_mach_port_(true) {
  11. if (mach_port != MACH_PORT_NULL) {
  12. kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port,
  13. MACH_PORT_RIGHT_SEND, 1);
  14. MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr)
  15. << "MachPortAttachmentMac mach_port_mod_refs";
  16. }
  17. }
  18. MachPortAttachmentMac::MachPortAttachmentMac(mach_port_t mach_port,
  19. FromWire from_wire)
  20. : mach_port_(mach_port), owns_mach_port_(true) {}
  21. MachPortAttachmentMac::~MachPortAttachmentMac() {
  22. if (mach_port_ != MACH_PORT_NULL && owns_mach_port_) {
  23. kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port_,
  24. MACH_PORT_RIGHT_SEND, -1);
  25. MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr)
  26. << "~MachPortAttachmentMac mach_port_mod_refs";
  27. }
  28. }
  29. MessageAttachment::Type MachPortAttachmentMac::GetType() const {
  30. return Type::MACH_PORT;
  31. }
  32. } // namespace internal
  33. } // namespace IPC