blob: 91663641714d7fe981fe9c494f0ce3c614a29104 [file] [log] [blame]
erikchen1c1e6652015-10-01 18:51:321// 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 Rockotfd907632017-09-14 04:23:4110#include "base/strings/stringprintf.h"
erikchen1c1e6652015-10-01 18:51:3211#include "ipc/mach_port_attachment_mac.h"
12
13namespace IPC {
14
15// static
rockot502c94f2016-02-03 20:20:1616void ParamTraits<MachPortMac>::Write(base::Pickle* m, const param_type& p) {
erikchen1c1e6652015-10-01 18:51:3217 if (!m->WriteAttachment(
18 new IPC::internal::MachPortAttachmentMac(p.get_mach_port()))) {
19 NOTREACHED();
20 }
21}
22
23// static
rockot502c94f2016-02-03 20:20:1624bool ParamTraits<MachPortMac>::Read(const base::Pickle* m,
erikchen1c1e6652015-10-01 18:51:3225 base::PickleIterator* iter,
26 param_type* r) {
rockot502c94f2016-02-03 20:20:1627 scoped_refptr<base::Pickle::Attachment> base_attachment;
28 if (!m->ReadAttachment(iter, &base_attachment))
erikchen1c1e6652015-10-01 18:51:3229 return false;
rockot502c94f2016-02-03 20:20:1630 MessageAttachment* attachment =
31 static_cast<MessageAttachment*>(base_attachment.get());
sammc6ed3efb2016-11-23 03:17:3532 if (attachment->GetType() != MessageAttachment::Type::MACH_PORT)
erikchen1c1e6652015-10-01 18:51:3233 return false;
erikchen1c1e6652015-10-01 18:51:3234 IPC::internal::MachPortAttachmentMac* mach_port_attachment =
sammc6ed3efb2016-11-23 03:17:3535 static_cast<IPC::internal::MachPortAttachmentMac*>(attachment);
erikchen1c1e6652015-10-01 18:51:3236 r->set_mach_port(mach_port_attachment->get_mach_port());
erikchen8a6f3f4e2016-01-06 22:04:4337 mach_port_attachment->reset_mach_port_ownership();
erikchen1c1e6652015-10-01 18:51:3238 return true;
39}
40
41// static
42void 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