OLD | NEW |
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 Loading... |
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 Loading... |
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 WriteParam(m, p.mojo_handle); |
1017 } | 1021 } |
1018 | 1022 |
1019 bool ParamTraits<IPC::ChannelHandle>::Read(const base::Pickle* m, | 1023 bool ParamTraits<IPC::ChannelHandle>::Read(const base::Pickle* m, |
1020 base::PickleIterator* iter, | 1024 base::PickleIterator* iter, |
1021 param_type* r) { | 1025 param_type* r) { |
1022 return ReadParam(m, iter, &r->name) | 1026 return ReadParam(m, iter, &r->name) |
1023 #if defined(OS_POSIX) | 1027 #if defined(OS_POSIX) |
1024 && ReadParam(m, iter, &r->socket) | 1028 && ReadParam(m, iter, &r->socket) |
1025 #endif | 1029 #endif |
1026 ; | 1030 && ReadParam(m, iter, &r->mojo_handle); |
1027 } | 1031 } |
1028 | 1032 |
1029 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, | 1033 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, |
1030 std::string* l) { | 1034 std::string* l) { |
1031 l->append(base::StringPrintf("ChannelHandle(%s", p.name.c_str())); | 1035 l->append(base::StringPrintf("ChannelHandle(%s", p.name.c_str())); |
1032 #if defined(OS_POSIX) | 1036 #if defined(OS_POSIX) |
1033 l->append(", "); | 1037 l->append(", "); |
1034 ParamTraits<base::FileDescriptor>::Log(p.socket, l); | 1038 ParamTraits<base::FileDescriptor>::Log(p.socket, l); |
1035 #endif | 1039 #endif |
| 1040 l->append(", "); |
| 1041 LogParam(p.mojo_handle, l); |
1036 l->append(")"); | 1042 l->append(")"); |
1037 } | 1043 } |
1038 | 1044 |
1039 void ParamTraits<LogData>::GetSize(base::PickleSizer* sizer, | 1045 void ParamTraits<LogData>::GetSize(base::PickleSizer* sizer, |
1040 const param_type& p) { | 1046 const param_type& p) { |
1041 GetParamSize(sizer, p.channel); | 1047 GetParamSize(sizer, p.channel); |
1042 GetParamSize(sizer, p.routing_id); | 1048 GetParamSize(sizer, p.routing_id); |
1043 GetParamSize(sizer, p.type); | 1049 GetParamSize(sizer, p.type); |
1044 GetParamSize(sizer, p.flags); | 1050 GetParamSize(sizer, p.flags); |
1045 GetParamSize(sizer, p.sent); | 1051 GetParamSize(sizer, p.sent); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 return result; | 1211 return result; |
1206 } | 1212 } |
1207 | 1213 |
1208 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 1214 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
1209 l->append("<MSG>"); | 1215 l->append("<MSG>"); |
1210 } | 1216 } |
1211 | 1217 |
1212 #endif // OS_WIN | 1218 #endif // OS_WIN |
1213 | 1219 |
1214 } // namespace IPC | 1220 } // namespace IPC |
OLD | NEW |