mach_port_mac.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #include "ipc/mach_port_mac.h"
  5. #include "base/memory/ref_counted.h"
  6. #include "base/notreached.h"
  7. #include "base/strings/string_number_conversions.h"
  8. #include "base/strings/stringprintf.h"
  9. #include "ipc/mach_port_attachment_mac.h"
  10. namespace IPC {
  11. // static
  12. void ParamTraits<MachPortMac>::Write(base::Pickle* m, const param_type& p) {
  13. if (!m->WriteAttachment(
  14. new IPC::internal::MachPortAttachmentMac(p.get_mach_port()))) {
  15. NOTREACHED();
  16. }
  17. }
  18. // static
  19. bool ParamTraits<MachPortMac>::Read(const base::Pickle* m,
  20. base::PickleIterator* iter,
  21. param_type* r) {
  22. scoped_refptr<base::Pickle::Attachment> base_attachment;
  23. if (!m->ReadAttachment(iter, &base_attachment))
  24. return false;
  25. MessageAttachment* attachment =
  26. static_cast<MessageAttachment*>(base_attachment.get());
  27. if (attachment->GetType() != MessageAttachment::Type::MACH_PORT)
  28. return false;
  29. IPC::internal::MachPortAttachmentMac* mach_port_attachment =
  30. static_cast<IPC::internal::MachPortAttachmentMac*>(attachment);
  31. r->set_mach_port(mach_port_attachment->get_mach_port());
  32. mach_port_attachment->reset_mach_port_ownership();
  33. return true;
  34. }
  35. // static
  36. void ParamTraits<MachPortMac>::Log(const param_type& p, std::string* l) {
  37. l->append(base::StringPrintf("mach port: 0x%X", p.get_mach_port()));
  38. }
  39. } // namespace IPC