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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 2047233002: Support using a Mojo message pipe in a ChannelHandle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-handle-attachemnt-public-api
Patch Set: rebase Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ipc/ipc_message_utils.h" 5 #include "ipc/ipc_message_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/strings/nullable_string16.h" 12 #include "base/strings/nullable_string16.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "ipc/ipc_channel_handle.h" 18 #include "ipc/ipc_channel_handle.h"
19 #include "ipc/ipc_message_attachment.h" 19 #include "ipc/ipc_message_attachment.h"
20 #include "ipc/ipc_message_attachment_set.h" 20 #include "ipc/ipc_message_attachment_set.h"
21 #include "ipc/ipc_mojo_param_traits.h"
21 22
22 #if defined(OS_POSIX) 23 #if defined(OS_POSIX)
23 #include "ipc/ipc_platform_file_attachment_posix.h" 24 #include "ipc/ipc_platform_file_attachment_posix.h"
24 #endif 25 #endif
25 26
26 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) 27 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN)
27 #include "base/memory/shared_memory_handle.h" 28 #include "base/memory/shared_memory_handle.h"
28 #endif // (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) 29 #endif // (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN)
29 30
30 #if defined(OS_MACOSX) && !defined(OS_IOS) 31 #if defined(OS_MACOSX) && !defined(OS_IOS)
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 std::string* l) { 632 std::string* l) {
632 std::string json; 633 std::string json;
633 base::JSONWriter::Write(p, &json); 634 base::JSONWriter::Write(p, &json);
634 l->append(json); 635 l->append(json);
635 } 636 }
636 637
637 #if defined(OS_POSIX) 638 #if defined(OS_POSIX)
638 void ParamTraits<base::FileDescriptor>::GetSize(base::PickleSizer* sizer, 639 void ParamTraits<base::FileDescriptor>::GetSize(base::PickleSizer* sizer,
639 const param_type& p) { 640 const param_type& p) {
640 GetParamSize(sizer, p.fd >= 0); 641 GetParamSize(sizer, p.fd >= 0);
641 sizer->AddAttachment(); 642 if (p.fd >= 0)
643 sizer->AddAttachment();
642 } 644 }
643 645
644 void ParamTraits<base::FileDescriptor>::Write(base::Pickle* m, 646 void ParamTraits<base::FileDescriptor>::Write(base::Pickle* m,
645 const param_type& p) { 647 const param_type& p) {
646 const bool valid = p.fd >= 0; 648 const bool valid = p.fd >= 0;
647 WriteParam(m, valid); 649 WriteParam(m, valid);
648 650
649 if (!valid) 651 if (!valid)
650 return; 652 return;
651 653
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { 997 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) {
996 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); 998 ParamTraits<int64_t>::Log(p.ToInternalValue(), l);
997 } 999 }
998 1000
999 void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer, 1001 void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer,
1000 const param_type& p) { 1002 const param_type& p) {
1001 GetParamSize(sizer, p.name); 1003 GetParamSize(sizer, p.name);
1002 #if defined(OS_POSIX) 1004 #if defined(OS_POSIX)
1003 GetParamSize(sizer, p.socket); 1005 GetParamSize(sizer, p.socket);
1004 #endif 1006 #endif
1007 GetParamSize(sizer, p.mojo_handle);
1005 } 1008 }
1006 1009
1007 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m, 1010 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m,
1008 const param_type& p) { 1011 const param_type& p) {
1009 #if defined(OS_WIN) 1012 #if defined(OS_WIN)
1010 // On Windows marshalling pipe handle is not supported. 1013 // On Windows marshalling pipe handle is not supported.
1011 DCHECK(p.pipe.handle == NULL); 1014 DCHECK(p.pipe.handle == NULL);
1012 #endif // defined (OS_WIN) 1015 #endif // defined (OS_WIN)
1013 WriteParam(m, p.name); 1016 WriteParam(m, p.name);
1014 #if defined(OS_POSIX) 1017 #if defined(OS_POSIX)
1015 WriteParam(m, p.socket); 1018 WriteParam(m, p.socket);
1016 #endif 1019 #endif
1020 ParamTraits<mojo::MessagePipeHandle>::Write(
1021 static_cast<IPC::Message*>(m), p.mojo_handle);
dcheng 2016/06/24 07:50:48 Why does this need the explicit static_cast? Norma
Anand Mistry (off Chromium) 2016/06/27 00:46:23 Because ParamTraits<> functions operate on base::P
1017 } 1022 }
1018 1023
1019 bool ParamTraits<IPC::ChannelHandle>::Read(const base::Pickle* m, 1024 bool ParamTraits<IPC::ChannelHandle>::Read(const base::Pickle* m,
1020 base::PickleIterator* iter, 1025 base::PickleIterator* iter,
1021 param_type* r) { 1026 param_type* r) {
1022 return ReadParam(m, iter, &r->name) 1027 return ReadParam(m, iter, &r->name)
1023 #if defined(OS_POSIX) 1028 #if defined(OS_POSIX)
1024 && ReadParam(m, iter, &r->socket) 1029 && ReadParam(m, iter, &r->socket)
1025 #endif 1030 #endif
1026 ; 1031 && ParamTraits<mojo::MessagePipeHandle>::Read(
1032 static_cast<const IPC::Message*>(m), iter, &r->mojo_handle);
1027 } 1033 }
1028 1034
1029 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, 1035 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p,
1030 std::string* l) { 1036 std::string* l) {
1031 l->append(base::StringPrintf("ChannelHandle(%s", p.name.c_str())); 1037 l->append(base::StringPrintf("ChannelHandle(%s", p.name.c_str()));
1032 #if defined(OS_POSIX) 1038 #if defined(OS_POSIX)
1033 l->append(", "); 1039 l->append(", ");
1034 ParamTraits<base::FileDescriptor>::Log(p.socket, l); 1040 ParamTraits<base::FileDescriptor>::Log(p.socket, l);
1035 #endif 1041 #endif
1042 l->append(", ");
1043 ParamTraits<mojo::MessagePipeHandle>::Log(p.mojo_handle, l);
1036 l->append(")"); 1044 l->append(")");
1037 } 1045 }
1038 1046
1039 void ParamTraits<LogData>::GetSize(base::PickleSizer* sizer, 1047 void ParamTraits<LogData>::GetSize(base::PickleSizer* sizer,
1040 const param_type& p) { 1048 const param_type& p) {
1041 GetParamSize(sizer, p.channel); 1049 GetParamSize(sizer, p.channel);
1042 GetParamSize(sizer, p.routing_id); 1050 GetParamSize(sizer, p.routing_id);
1043 GetParamSize(sizer, p.type); 1051 GetParamSize(sizer, p.type);
1044 GetParamSize(sizer, p.flags); 1052 GetParamSize(sizer, p.flags);
1045 GetParamSize(sizer, p.sent); 1053 GetParamSize(sizer, p.sent);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 return result; 1213 return result;
1206 } 1214 }
1207 1215
1208 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 1216 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
1209 l->append("<MSG>"); 1217 l->append("<MSG>");
1210 } 1218 }
1211 1219
1212 #endif // OS_WIN 1220 #endif // OS_WIN
1213 1221
1214 } // namespace IPC 1222 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698