Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Unified Diff: ipc/ipc_message_utils.cc

Issue 2843113002: make base::SharedMemoryHandle a class on POSIX. (Closed)
Patch Set: Fix test error. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ipc/ipc_message_utils.cc
diff --git a/ipc/ipc_message_utils.cc b/ipc/ipc_message_utils.cc
index 8053318110d78f2eda9b81f9721a9070c59f6c29..db36c0fe7a62622fd0b7e4489c2bfdfd26f4a2f7 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
@@ -647,7 +644,6 @@ bool ParamTraits<base::FileDescriptor>::Read(const base::Pickle* m,
if (!ReadParam(m, iter, &valid))
return false;
- // TODO(morrita): Seems like this should return false.
if (!valid)
return true;
@@ -781,6 +777,69 @@ 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.OwnershipPassesToIPC()) {
+ 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;
+
+ 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.OwnershipPassesToIPC()) {
+ 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,

Powered by Google App Engine
This is Rietveld 408576698