| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ipc/mach_port_attachment_mac.h" | 5 #include "ipc/mach_port_attachment_mac.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/mac/mach_logging.h" | 9 #include "base/mac/mach_logging.h" |
| 10 | 10 |
| 11 namespace IPC { | 11 namespace IPC { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 MachPortAttachmentMac::MachPortAttachmentMac(mach_port_t mach_port) | 14 MachPortAttachmentMac::MachPortAttachmentMac(mach_port_t mach_port) |
| 15 : mach_port_(mach_port), owns_mach_port_(true) { | 15 : mach_port_(mach_port), owns_mach_port_(true) { |
| 16 if (mach_port != MACH_PORT_NULL) { | 16 if (mach_port != MACH_PORT_NULL) { |
| 17 kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port, | 17 kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port, |
| 18 MACH_PORT_RIGHT_SEND, 1); | 18 MACH_PORT_RIGHT_SEND, 1); |
| 19 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) | 19 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) |
| 20 << "MachPortAttachmentMac mach_port_mod_refs"; | 20 << "MachPortAttachmentMac mach_port_mod_refs"; |
| 21 } | 21 } |
| 22 } | 22 } |
| 23 MachPortAttachmentMac::MachPortAttachmentMac(mach_port_t mach_port, | 23 MachPortAttachmentMac::MachPortAttachmentMac(mach_port_t mach_port, |
| 24 FromWire from_wire) | 24 FromWire from_wire) |
| 25 : mach_port_(mach_port), owns_mach_port_(true) {} | 25 : mach_port_(mach_port), owns_mach_port_(true) {} |
| 26 | 26 |
| 27 MachPortAttachmentMac::MachPortAttachmentMac(const WireFormat& wire_format) | |
| 28 : mach_port_(static_cast<mach_port_t>(wire_format.mach_port)), | |
| 29 owns_mach_port_(true) {} | |
| 30 | |
| 31 MachPortAttachmentMac::~MachPortAttachmentMac() { | 27 MachPortAttachmentMac::~MachPortAttachmentMac() { |
| 32 if (mach_port_ != MACH_PORT_NULL && owns_mach_port_) { | 28 if (mach_port_ != MACH_PORT_NULL && owns_mach_port_) { |
| 33 kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port_, | 29 kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port_, |
| 34 MACH_PORT_RIGHT_SEND, -1); | 30 MACH_PORT_RIGHT_SEND, -1); |
| 35 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) | 31 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) |
| 36 << "~MachPortAttachmentMac mach_port_mod_refs"; | 32 << "~MachPortAttachmentMac mach_port_mod_refs"; |
| 37 } | 33 } |
| 38 } | 34 } |
| 39 | 35 |
| 40 MachPortAttachmentMac::BrokerableType MachPortAttachmentMac::GetBrokerableType() | 36 MessageAttachment::Type MachPortAttachmentMac::GetType() const { |
| 41 const { | 37 return Type::MACH_PORT; |
| 42 return MACH_PORT; | |
| 43 } | |
| 44 | |
| 45 MachPortAttachmentMac::WireFormat MachPortAttachmentMac::GetWireFormat( | |
| 46 const base::ProcessId& destination) const { | |
| 47 return WireFormat(static_cast<uint32_t>(mach_port_), destination); | |
| 48 } | 38 } |
| 49 | 39 |
| 50 } // namespace internal | 40 } // namespace internal |
| 51 } // namespace IPC | 41 } // namespace IPC |
| OLD | NEW |