| 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) | 27 MachPortAttachmentMac::MachPortAttachmentMac(const WireFormat& wire_format) |
| 28 : BrokerableAttachment(wire_format.attachment_id), | 28 : mach_port_(static_cast<mach_port_t>(wire_format.mach_port)), |
| 29 mach_port_(static_cast<mach_port_t>(wire_format.mach_port)), | |
| 30 owns_mach_port_(true) {} | 29 owns_mach_port_(true) {} |
| 31 | 30 |
| 32 MachPortAttachmentMac::~MachPortAttachmentMac() { | 31 MachPortAttachmentMac::~MachPortAttachmentMac() { |
| 33 if (mach_port_ != MACH_PORT_NULL && owns_mach_port_) { | 32 if (mach_port_ != MACH_PORT_NULL && owns_mach_port_) { |
| 34 kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port_, | 33 kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port_, |
| 35 MACH_PORT_RIGHT_SEND, -1); | 34 MACH_PORT_RIGHT_SEND, -1); |
| 36 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) | 35 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) |
| 37 << "~MachPortAttachmentMac mach_port_mod_refs"; | 36 << "~MachPortAttachmentMac mach_port_mod_refs"; |
| 38 } | 37 } |
| 39 } | 38 } |
| 40 | 39 |
| 41 MachPortAttachmentMac::BrokerableType MachPortAttachmentMac::GetBrokerableType() | 40 MachPortAttachmentMac::BrokerableType MachPortAttachmentMac::GetBrokerableType() |
| 42 const { | 41 const { |
| 43 return MACH_PORT; | 42 return MACH_PORT; |
| 44 } | 43 } |
| 45 | 44 |
| 46 MachPortAttachmentMac::WireFormat MachPortAttachmentMac::GetWireFormat( | 45 MachPortAttachmentMac::WireFormat MachPortAttachmentMac::GetWireFormat( |
| 47 const base::ProcessId& destination) const { | 46 const base::ProcessId& destination) const { |
| 48 return WireFormat(static_cast<uint32_t>(mach_port_), destination, | 47 return WireFormat(static_cast<uint32_t>(mach_port_), destination); |
| 49 GetIdentifier()); | |
| 50 } | 48 } |
| 51 | 49 |
| 52 } // namespace internal | 50 } // namespace internal |
| 53 } // namespace IPC | 51 } // namespace IPC |
| OLD | NEW |