Chromium Code Reviews| Index: ipc/ipc_message_utils.cc |
| diff --git a/ipc/ipc_message_utils.cc b/ipc/ipc_message_utils.cc |
| index 8053318110d78f2eda9b81f9721a9070c59f6c29..df069d5d567e9b95e30f7c40ea68e71e8edf82a9 100644 |
| --- a/ipc/ipc_message_utils.cc |
| +++ b/ipc/ipc_message_utils.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/files/file_path.h" |
| #include "base/json/json_writer.h" |
| #include "base/memory/ptr_util.h" |
| +#include "base/memory/shared_memory_handle.h" |
| #include "base/strings/nullable_string16.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -27,10 +28,6 @@ |
| #include "ipc/ipc_platform_file_attachment_posix.h" |
| #endif |
| -#if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) |
| -#include "base/memory/shared_memory_handle.h" |
| -#endif // (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) |
| - |
| #if defined(OS_MACOSX) && !defined(OS_IOS) |
| #include "ipc/mach_port_mac.h" |
| #endif |
| @@ -781,6 +778,70 @@ void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
| l->append(" needs brokering: "); |
| LogParam(p.NeedsBrokering(), l); |
| } |
| +#elif defined(OS_POSIX) |
| +void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* sizer, |
| + const param_type& p) { |
| + GetParamSize(sizer, p.IsValid()); |
| + if (p.IsValid()) |
| + sizer->AddAttachment(); |
| +} |
| + |
| +void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
| + const param_type& p) { |
| + const bool valid = p.IsValid(); |
| + WriteParam(m, valid); |
| + |
| + if (!valid) |
| + return; |
| + |
| + if (p.file_descriptor.auto_close) { |
| + if (!m->WriteAttachment(new internal::PlatformFileAttachment( |
| + base::ScopedFD(p.GetHandle())))) |
| + NOTREACHED(); |
| + } else { |
| + if (!m->WriteAttachment( |
| + new internal::PlatformFileAttachment(p.GetHandle()))) |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
| + base::PickleIterator* iter, |
| + param_type* r) { |
| + *r = base::SharedMemoryHandle(); |
| + |
| + bool valid; |
| + if (!ReadParam(m, iter, &valid)) |
| + return false; |
| + |
| + // TODO(morrita): Seems like this should return false. |
|
Nico
2017/04/27 16:24:44
I take it you copied this block from somewhere; I
erikchen
2017/04/27 17:08:10
This file needs a separate IPC review anyways. I'l
|
| + if (!valid) |
| + return true; |
| + |
| + scoped_refptr<base::Pickle::Attachment> attachment; |
| + if (!m->ReadAttachment(iter, &attachment)) |
| + return false; |
| + |
| + if (static_cast<MessageAttachment*>(attachment.get())->GetType() != |
| + MessageAttachment::Type::PLATFORM_FILE) { |
| + return false; |
| + } |
| + |
| + *r = base::SharedMemoryHandle(base::FileDescriptor( |
| + static_cast<internal::PlatformFileAttachment*>(attachment.get()) |
| + ->TakePlatformFile(), |
| + true)); |
| + return true; |
| +} |
| + |
| +void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
| + std::string* l) { |
| + if (p.file_descriptor.auto_close) { |
| + l->append(base::StringPrintf("FD(%d auto-close)", p.GetHandle())); |
| + } else { |
| + l->append(base::StringPrintf("FD(%d)", p.GetHandle())); |
| + } |
| +} |
| #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| void ParamTraits<base::FilePath>::GetSize(base::PickleSizer* sizer, |