1*6777b538SAndroid Build Coastguard Worker // Copyright 2015 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker
5*6777b538SAndroid Build Coastguard Worker #include "ipc/mach_port_mac.h"
6*6777b538SAndroid Build Coastguard Worker
7*6777b538SAndroid Build Coastguard Worker #include "base/memory/ref_counted.h"
8*6777b538SAndroid Build Coastguard Worker #include "base/notreached.h"
9*6777b538SAndroid Build Coastguard Worker #include "base/strings/string_number_conversions.h"
10*6777b538SAndroid Build Coastguard Worker #include "base/strings/stringprintf.h"
11*6777b538SAndroid Build Coastguard Worker #include "ipc/mach_port_attachment_mac.h"
12*6777b538SAndroid Build Coastguard Worker
13*6777b538SAndroid Build Coastguard Worker namespace IPC {
14*6777b538SAndroid Build Coastguard Worker
15*6777b538SAndroid Build Coastguard Worker // static
Write(base::Pickle * m,const param_type & p)16*6777b538SAndroid Build Coastguard Worker void ParamTraits<MachPortMac>::Write(base::Pickle* m, const param_type& p) {
17*6777b538SAndroid Build Coastguard Worker if (!m->WriteAttachment(
18*6777b538SAndroid Build Coastguard Worker new IPC::internal::MachPortAttachmentMac(p.get_mach_port()))) {
19*6777b538SAndroid Build Coastguard Worker NOTREACHED();
20*6777b538SAndroid Build Coastguard Worker }
21*6777b538SAndroid Build Coastguard Worker }
22*6777b538SAndroid Build Coastguard Worker
23*6777b538SAndroid Build Coastguard Worker // static
Read(const base::Pickle * m,base::PickleIterator * iter,param_type * r)24*6777b538SAndroid Build Coastguard Worker bool ParamTraits<MachPortMac>::Read(const base::Pickle* m,
25*6777b538SAndroid Build Coastguard Worker base::PickleIterator* iter,
26*6777b538SAndroid Build Coastguard Worker param_type* r) {
27*6777b538SAndroid Build Coastguard Worker scoped_refptr<base::Pickle::Attachment> base_attachment;
28*6777b538SAndroid Build Coastguard Worker if (!m->ReadAttachment(iter, &base_attachment))
29*6777b538SAndroid Build Coastguard Worker return false;
30*6777b538SAndroid Build Coastguard Worker MessageAttachment* attachment =
31*6777b538SAndroid Build Coastguard Worker static_cast<MessageAttachment*>(base_attachment.get());
32*6777b538SAndroid Build Coastguard Worker if (attachment->GetType() != MessageAttachment::Type::MACH_PORT)
33*6777b538SAndroid Build Coastguard Worker return false;
34*6777b538SAndroid Build Coastguard Worker IPC::internal::MachPortAttachmentMac* mach_port_attachment =
35*6777b538SAndroid Build Coastguard Worker static_cast<IPC::internal::MachPortAttachmentMac*>(attachment);
36*6777b538SAndroid Build Coastguard Worker r->set_mach_port(mach_port_attachment->get_mach_port());
37*6777b538SAndroid Build Coastguard Worker mach_port_attachment->reset_mach_port_ownership();
38*6777b538SAndroid Build Coastguard Worker return true;
39*6777b538SAndroid Build Coastguard Worker }
40*6777b538SAndroid Build Coastguard Worker
41*6777b538SAndroid Build Coastguard Worker // static
Log(const param_type & p,std::string * l)42*6777b538SAndroid Build Coastguard Worker void ParamTraits<MachPortMac>::Log(const param_type& p, std::string* l) {
43*6777b538SAndroid Build Coastguard Worker l->append(base::StringPrintf("mach port: 0x%X", p.get_mach_port()));
44*6777b538SAndroid Build Coastguard Worker }
45*6777b538SAndroid Build Coastguard Worker
46*6777b538SAndroid Build Coastguard Worker } // namespace IPC
47