erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 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_mac.h" |
| 6 | |
| 7 | #include "base/logging.h" |
| 8 | #include "base/memory/ref_counted.h" |
| 9 | #include "base/strings/string_number_conversions.h" |
Ken Rockot | fd90763 | 2017-09-14 04:23:41 | [diff] [blame] | 10 | #include "base/strings/stringprintf.h" |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 11 | #include "ipc/mach_port_attachment_mac.h" |
| 12 | |
| 13 | namespace IPC { |
| 14 | |
| 15 | // static |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 16 | void ParamTraits<MachPortMac>::Write(base::Pickle* m, const param_type& p) { |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 17 | if (!m->WriteAttachment( |
| 18 | new IPC::internal::MachPortAttachmentMac(p.get_mach_port()))) { |
| 19 | NOTREACHED(); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | // static |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 24 | bool ParamTraits<MachPortMac>::Read(const base::Pickle* m, |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 25 | base::PickleIterator* iter, |
| 26 | param_type* r) { |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 27 | scoped_refptr<base::Pickle::Attachment> base_attachment; |
| 28 | if (!m->ReadAttachment(iter, &base_attachment)) |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 29 | return false; |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 30 | MessageAttachment* attachment = |
| 31 | static_cast<MessageAttachment*>(base_attachment.get()); |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 32 | if (attachment->GetType() != MessageAttachment::Type::MACH_PORT) |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 33 | return false; |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 34 | IPC::internal::MachPortAttachmentMac* mach_port_attachment = |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 35 | static_cast<IPC::internal::MachPortAttachmentMac*>(attachment); |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 36 | r->set_mach_port(mach_port_attachment->get_mach_port()); |
erikchen | 8a6f3f4e | 2016-01-06 22:04:43 | [diff] [blame] | 37 | mach_port_attachment->reset_mach_port_ownership(); |
erikchen | 1c1e665 | 2015-10-01 18:51:32 | [diff] [blame] | 38 | return true; |
| 39 | } |
| 40 | |
| 41 | // static |
| 42 | void ParamTraits<MachPortMac>::Log(const param_type& p, std::string* l) { |
| 43 | l->append(base::StringPrintf("mach port: 0x%X", p.get_mach_port())); |
| 44 | } |
| 45 | |
| 46 | } // namespace IPC |