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/nonce_token.h" |
12 #include "base/strings/nullable_string16.h" | 13 #include "base/strings/nullable_string16.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
18 #include "ipc/ipc_channel_handle.h" | 19 #include "ipc/ipc_channel_handle.h" |
19 #include "ipc/ipc_message_attachment.h" | 20 #include "ipc/ipc_message_attachment.h" |
20 #include "ipc/ipc_message_attachment_set.h" | 21 #include "ipc/ipc_message_attachment_set.h" |
21 #include "ipc/ipc_mojo_param_traits.h" | 22 #include "ipc/ipc_mojo_param_traits.h" |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 if (ret) | 992 if (ret) |
992 *r = base::TimeTicks::FromInternalValue(value); | 993 *r = base::TimeTicks::FromInternalValue(value); |
993 | 994 |
994 return ret; | 995 return ret; |
995 } | 996 } |
996 | 997 |
997 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { | 998 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { |
998 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); | 999 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
999 } | 1000 } |
1000 | 1001 |
| 1002 // If base::NonceToken is no longer 128 bits, the IPC serialization logic below |
| 1003 // should be updated. |
| 1004 static_assert(sizeof(base::NonceToken) == 2 * sizeof(uint64_t), |
| 1005 "base::NonceToken should be of size 2 * sizeof(uint64_t)."); |
| 1006 |
| 1007 void ParamTraits<base::NonceToken>::GetSize(base::PickleSizer* sizer, |
| 1008 const param_type& p) { |
| 1009 sizer->AddBytes(2 * sizeof(uint64_t)); |
| 1010 } |
| 1011 |
| 1012 void ParamTraits<base::NonceToken>::Write(base::Pickle* m, |
| 1013 const param_type& p) { |
| 1014 CHECK(!p.is_empty()); |
| 1015 |
| 1016 uint64_t high, low; |
| 1017 p.Serialize(&high, &low); |
| 1018 |
| 1019 ParamTraits<uint64_t>::Write(m, high); |
| 1020 ParamTraits<uint64_t>::Write(m, low); |
| 1021 } |
| 1022 |
| 1023 bool ParamTraits<base::NonceToken>::Read(const base::Pickle* m, |
| 1024 base::PickleIterator* iter, |
| 1025 param_type* r) { |
| 1026 uint64_t high, low; |
| 1027 if (!ParamTraits<uint64_t>::Read(m, iter, &high) || |
| 1028 !ParamTraits<uint64_t>::Read(m, iter, &low)) |
| 1029 return false; |
| 1030 |
| 1031 // Receiving a zeroed NonceToken is a security issue. |
| 1032 if (base::NonceToken::IsZeroData(high, low)) |
| 1033 return false; |
| 1034 |
| 1035 *r = base::NonceToken::Deserialize(high, low); |
| 1036 return true; |
| 1037 } |
| 1038 |
| 1039 void ParamTraits<base::NonceToken>::Log(const param_type& p, std::string* l) { |
| 1040 l->append(p.ToString()); |
| 1041 } |
| 1042 |
1001 void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer, | 1043 void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer, |
1002 const param_type& p) { | 1044 const param_type& p) { |
1003 GetParamSize(sizer, p.name); | 1045 GetParamSize(sizer, p.name); |
1004 #if defined(OS_POSIX) | 1046 #if defined(OS_POSIX) |
1005 GetParamSize(sizer, p.socket); | 1047 GetParamSize(sizer, p.socket); |
1006 #endif | 1048 #endif |
1007 GetParamSize(sizer, p.mojo_handle); | 1049 GetParamSize(sizer, p.mojo_handle); |
1008 } | 1050 } |
1009 | 1051 |
1010 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m, | 1052 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m, |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 return result; | 1253 return result; |
1212 } | 1254 } |
1213 | 1255 |
1214 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 1256 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
1215 l->append("<MSG>"); | 1257 l->append("<MSG>"); |
1216 } | 1258 } |
1217 | 1259 |
1218 #endif // OS_WIN | 1260 #endif // OS_WIN |
1219 | 1261 |
1220 } // namespace IPC | 1262 } // namespace IPC |
OLD | NEW |