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 "base/mac/mach_logging.h" |
| 8 |
7 namespace IPC { | 9 namespace IPC { |
8 namespace internal { | 10 namespace internal { |
9 | 11 |
10 MachPortAttachmentMac::MachPortAttachmentMac(mach_port_t mach_port) | 12 MachPortAttachmentMac::MachPortAttachmentMac(mach_port_t mach_port) |
11 : mach_port_(mach_port) {} | 13 : mach_port_(mach_port), owns_mach_port_(true) { |
| 14 if (mach_port != MACH_PORT_NULL) { |
| 15 kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port, |
| 16 MACH_PORT_RIGHT_SEND, 1); |
| 17 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) |
| 18 << "MachPortAttachmentMac mach_port_mod_refs"; |
| 19 } |
| 20 } |
12 | 21 |
13 MachPortAttachmentMac::MachPortAttachmentMac(const WireFormat& wire_format) | 22 MachPortAttachmentMac::MachPortAttachmentMac(const WireFormat& wire_format) |
14 : BrokerableAttachment(wire_format.attachment_id), | 23 : BrokerableAttachment(wire_format.attachment_id), |
15 mach_port_(static_cast<mach_port_t>(wire_format.mach_port)) {} | 24 mach_port_(static_cast<mach_port_t>(wire_format.mach_port)), |
| 25 owns_mach_port_(false) {} |
16 | 26 |
17 MachPortAttachmentMac::MachPortAttachmentMac( | 27 MachPortAttachmentMac::MachPortAttachmentMac( |
18 const BrokerableAttachment::AttachmentId& id) | 28 const BrokerableAttachment::AttachmentId& id) |
19 : BrokerableAttachment(id), mach_port_(MACH_PORT_NULL) {} | 29 : BrokerableAttachment(id), |
| 30 mach_port_(MACH_PORT_NULL), |
| 31 owns_mach_port_(false) {} |
20 | 32 |
21 MachPortAttachmentMac::~MachPortAttachmentMac() {} | 33 MachPortAttachmentMac::~MachPortAttachmentMac() { |
| 34 if (mach_port_ != MACH_PORT_NULL && owns_mach_port_) { |
| 35 kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port_, |
| 36 MACH_PORT_RIGHT_SEND, -1); |
| 37 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) |
| 38 << "~MachPortAttachmentMac mach_port_mod_refs"; |
| 39 } |
| 40 } |
22 | 41 |
23 MachPortAttachmentMac::BrokerableType MachPortAttachmentMac::GetBrokerableType() | 42 MachPortAttachmentMac::BrokerableType MachPortAttachmentMac::GetBrokerableType() |
24 const { | 43 const { |
25 return MACH_PORT; | 44 return MACH_PORT; |
26 } | 45 } |
27 | 46 |
28 MachPortAttachmentMac::WireFormat MachPortAttachmentMac::GetWireFormat( | 47 MachPortAttachmentMac::WireFormat MachPortAttachmentMac::GetWireFormat( |
29 const base::ProcessId& destination) const { | 48 const base::ProcessId& destination) const { |
30 return WireFormat(static_cast<uint32_t>(mach_port_), destination, | 49 return WireFormat(static_cast<uint32_t>(mach_port_), destination, |
31 GetIdentifier()); | 50 GetIdentifier()); |
32 } | 51 } |
33 | 52 |
34 } // namespace internal | 53 } // namespace internal |
35 } // namespace IPC | 54 } // namespace IPC |
OLD | NEW |