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