[email protected] | a7c03d4f3 | 2012-01-24 02:36:05 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ipc/ipc_message_utils.h" |
| 6 | |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 10 | #include "base/files/file_path.h" |
[email protected] | 93d49d7 | 2009-10-23 20:00:20 | [diff] [blame] | 11 | #include "base/json/json_writer.h" |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 12 | #include "base/memory/ptr_util.h" |
erikchen | 22a813b | 2017-04-28 17:10:50 | [diff] [blame] | 13 | #include "base/memory/shared_memory_handle.h" |
[email protected] | 0238a16 | 2013-06-13 13:47:46 | [diff] [blame] | 14 | #include "base/strings/nullable_string16.h" |
[email protected] | 4aa794a1 | 2013-06-11 06:32:18 | [diff] [blame] | 15 | #include "base/strings/string_number_conversions.h" |
[email protected] | 90626587 | 2013-06-07 22:40:45 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
[email protected] | b43e556 | 2013-06-28 15:20:02 | [diff] [blame] | 17 | #include "base/time/time.h" |
tguilbert | 4a5ac60 | 2016-09-19 21:11:25 | [diff] [blame] | 18 | #include "base/unguessable_token.h" |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 19 | #include "base/values.h" |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 20 | #include "build/build_config.h" |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 21 | #include "ipc/ipc_channel_handle.h" |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 22 | #include "ipc/ipc_message_attachment.h" |
morrita | 4b5c28e2 | 2015-01-14 21:17:06 | [diff] [blame] | 23 | #include "ipc/ipc_message_attachment_set.h" |
amistry | 3618252 | 2016-06-27 06:34:42 | [diff] [blame] | 24 | #include "ipc/ipc_mojo_param_traits.h" |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 25 | |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 26 | #if defined(OS_POSIX) |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 27 | #include "base/file_descriptor_posix.h" |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 28 | #include "ipc/ipc_platform_file_attachment_posix.h" |
| 29 | #endif |
| 30 | |
erikchen | af8299d | 2015-10-09 19:12:06 | [diff] [blame] | 31 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 32 | #include "ipc/mach_port_mac.h" |
| 33 | #endif |
| 34 | |
morrita | 4b5c28e2 | 2015-01-14 21:17:06 | [diff] [blame] | 35 | #if defined(OS_WIN) |
[email protected] | 2e02cfe8 | 2012-11-21 00:58:00 | [diff] [blame] | 36 | #include <tchar.h> |
erikchen | 5ea2ab7 | 2015-09-25 22:34:31 | [diff] [blame] | 37 | #include "ipc/handle_win.h" |
erikchen | d804e105 | 2017-04-29 02:24:36 | [diff] [blame] | 38 | #include "ipc/ipc_platform_file.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 39 | #endif |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 40 | |
Scott Graham | 3eebff0 | 2017-06-30 01:07:10 | [diff] [blame^] | 41 | #if defined(OS_FUCHSIA) |
| 42 | #include "ipc/handle_fuchsia.h" |
| 43 | #endif |
| 44 | |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 45 | namespace IPC { |
| 46 | |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 47 | namespace { |
| 48 | |
joaodasilva | 383b174a | 2017-01-10 09:55:36 | [diff] [blame] | 49 | const int kMaxRecursionDepth = 200; |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 50 | |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 51 | template<typename CharType> |
| 52 | void LogBytes(const std::vector<CharType>& data, std::string* out) { |
| 53 | #if defined(OS_WIN) |
| 54 | // Windows has a GUI for logging, which can handle arbitrary binary data. |
| 55 | for (size_t i = 0; i < data.size(); ++i) |
| 56 | out->push_back(data[i]); |
| 57 | #else |
| 58 | // On POSIX, we log to stdout, which we assume can display ASCII. |
| 59 | static const size_t kMaxBytesToLog = 100; |
| 60 | for (size_t i = 0; i < std::min(data.size(), kMaxBytesToLog); ++i) { |
| 61 | if (isprint(data[i])) |
| 62 | out->push_back(data[i]); |
| 63 | else |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 64 | out->append( |
| 65 | base::StringPrintf("[%02X]", static_cast<unsigned char>(data[i]))); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 66 | } |
| 67 | if (data.size() > kMaxBytesToLog) { |
[email protected] | f8660f8 | 2013-03-30 17:29:28 | [diff] [blame] | 68 | out->append(base::StringPrintf( |
| 69 | " and %u more bytes", |
| 70 | static_cast<unsigned>(data.size() - kMaxBytesToLog))); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 71 | } |
| 72 | #endif |
| 73 | } |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 74 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 75 | bool ReadValue(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 76 | base::PickleIterator* iter, |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 77 | std::unique_ptr<base::Value>* value, |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 78 | int recursion); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 79 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 80 | void GetValueSize(base::PickleSizer* sizer, |
| 81 | const base::Value* value, |
| 82 | int recursion) { |
| 83 | if (recursion > kMaxRecursionDepth) { |
joaodasilva | 383b174a | 2017-01-10 09:55:36 | [diff] [blame] | 84 | LOG(ERROR) << "Max recursion depth hit in GetValueSize."; |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 85 | return; |
| 86 | } |
| 87 | |
| 88 | sizer->AddInt(); |
| 89 | switch (value->GetType()) { |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 90 | case base::Value::Type::NONE: |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 91 | break; |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 92 | case base::Value::Type::BOOLEAN: |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 93 | sizer->AddBool(); |
| 94 | break; |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 95 | case base::Value::Type::INTEGER: |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 96 | sizer->AddInt(); |
| 97 | break; |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 98 | case base::Value::Type::DOUBLE: |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 99 | sizer->AddDouble(); |
| 100 | break; |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 101 | case base::Value::Type::STRING: { |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 102 | const base::Value* result; |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 103 | value->GetAsString(&result); |
amistry | c7a7a76 | 2016-04-08 04:21:54 | [diff] [blame] | 104 | if (value->GetAsString(&result)) { |
| 105 | DCHECK(result); |
| 106 | GetParamSize(sizer, result->GetString()); |
| 107 | } else { |
| 108 | std::string str; |
| 109 | bool as_string_result = value->GetAsString(&str); |
| 110 | DCHECK(as_string_result); |
| 111 | GetParamSize(sizer, str); |
| 112 | } |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 113 | break; |
| 114 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 115 | case base::Value::Type::BINARY: { |
jdoerrie | 5328aff | 2017-04-25 20:08:15 | [diff] [blame] | 116 | sizer->AddData(static_cast<int>(value->GetBlob().size())); |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 117 | break; |
| 118 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 119 | case base::Value::Type::DICTIONARY: { |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 120 | sizer->AddInt(); |
| 121 | const base::DictionaryValue* dict = |
| 122 | static_cast<const base::DictionaryValue*>(value); |
| 123 | for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); |
| 124 | it.Advance()) { |
| 125 | GetParamSize(sizer, it.key()); |
| 126 | GetValueSize(sizer, &it.value(), recursion + 1); |
| 127 | } |
| 128 | break; |
| 129 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 130 | case base::Value::Type::LIST: { |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 131 | sizer->AddInt(); |
| 132 | const base::ListValue* list = static_cast<const base::ListValue*>(value); |
dcheng | cb60e70 | 2016-05-25 18:30:47 | [diff] [blame] | 133 | for (const auto& entry : *list) { |
jdoerrie | a5676c6 | 2017-04-11 18:09:14 | [diff] [blame] | 134 | GetValueSize(sizer, &entry, recursion + 1); |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 135 | } |
| 136 | break; |
| 137 | } |
| 138 | default: |
| 139 | NOTREACHED() << "Invalid base::Value type."; |
| 140 | } |
| 141 | } |
| 142 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 143 | void WriteValue(base::Pickle* m, const base::Value* value, int recursion) { |
[email protected] | dbc761a | 2012-07-26 01:29:21 | [diff] [blame] | 144 | bool result; |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 145 | if (recursion > kMaxRecursionDepth) { |
joaodasilva | 383b174a | 2017-01-10 09:55:36 | [diff] [blame] | 146 | LOG(ERROR) << "Max recursion depth hit in WriteValue."; |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 147 | return; |
| 148 | } |
| 149 | |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 150 | m->WriteInt(static_cast<int>(value->GetType())); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 151 | |
| 152 | switch (value->GetType()) { |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 153 | case base::Value::Type::NONE: |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 154 | break; |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 155 | case base::Value::Type::BOOLEAN: { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 156 | bool val; |
[email protected] | dbc761a | 2012-07-26 01:29:21 | [diff] [blame] | 157 | result = value->GetAsBoolean(&val); |
| 158 | DCHECK(result); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 159 | WriteParam(m, val); |
| 160 | break; |
| 161 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 162 | case base::Value::Type::INTEGER: { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 163 | int val; |
[email protected] | dbc761a | 2012-07-26 01:29:21 | [diff] [blame] | 164 | result = value->GetAsInteger(&val); |
| 165 | DCHECK(result); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 166 | WriteParam(m, val); |
| 167 | break; |
| 168 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 169 | case base::Value::Type::DOUBLE: { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 170 | double val; |
[email protected] | dbc761a | 2012-07-26 01:29:21 | [diff] [blame] | 171 | result = value->GetAsDouble(&val); |
| 172 | DCHECK(result); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 173 | WriteParam(m, val); |
| 174 | break; |
| 175 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 176 | case base::Value::Type::STRING: { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 177 | std::string val; |
[email protected] | dbc761a | 2012-07-26 01:29:21 | [diff] [blame] | 178 | result = value->GetAsString(&val); |
| 179 | DCHECK(result); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 180 | WriteParam(m, val); |
| 181 | break; |
| 182 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 183 | case base::Value::Type::BINARY: { |
jdoerrie | 5328aff | 2017-04-25 20:08:15 | [diff] [blame] | 184 | m->WriteData(value->GetBlob().data(), |
| 185 | static_cast<int>(value->GetBlob().size())); |
[email protected] | e4dad9fb | 2009-10-06 18:15:58 | [diff] [blame] | 186 | break; |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 187 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 188 | case base::Value::Type::DICTIONARY: { |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 189 | const base::DictionaryValue* dict = |
| 190 | static_cast<const base::DictionaryValue*>(value); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 191 | |
[email protected] | 4dad9ad8 | 2009-11-25 20:47:52 | [diff] [blame] | 192 | WriteParam(m, static_cast<int>(dict->size())); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 193 | |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 194 | for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); |
| 195 | it.Advance()) { |
[email protected] | a899c0b0 | 2013-01-18 14:43:27 | [diff] [blame] | 196 | WriteParam(m, it.key()); |
| 197 | WriteValue(m, &it.value(), recursion + 1); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 198 | } |
| 199 | break; |
| 200 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 201 | case base::Value::Type::LIST: { |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 202 | const base::ListValue* list = static_cast<const base::ListValue*>(value); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 203 | WriteParam(m, static_cast<int>(list->GetSize())); |
dcheng | cb60e70 | 2016-05-25 18:30:47 | [diff] [blame] | 204 | for (const auto& entry : *list) { |
jdoerrie | a5676c6 | 2017-04-11 18:09:14 | [diff] [blame] | 205 | WriteValue(m, &entry, recursion + 1); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 206 | } |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // Helper for ReadValue that reads a DictionaryValue into a pre-allocated |
| 213 | // object. |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 214 | bool ReadDictionaryValue(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 215 | base::PickleIterator* iter, |
| 216 | base::DictionaryValue* value, |
| 217 | int recursion) { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 218 | int size; |
| 219 | if (!ReadParam(m, iter, &size)) |
| 220 | return false; |
| 221 | |
| 222 | for (int i = 0; i < size; ++i) { |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 223 | std::string key; |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 224 | std::unique_ptr<base::Value> subval; |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 225 | if (!ReadParam(m, iter, &key) || |
| 226 | !ReadValue(m, iter, &subval, recursion + 1)) |
| 227 | return false; |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 228 | value->SetWithoutPathExpansion(key, std::move(subval)); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | return true; |
| 232 | } |
| 233 | |
| 234 | // Helper for ReadValue that reads a ReadListValue into a pre-allocated |
| 235 | // object. |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 236 | bool ReadListValue(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 237 | base::PickleIterator* iter, |
| 238 | base::ListValue* value, |
| 239 | int recursion) { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 240 | int size; |
| 241 | if (!ReadParam(m, iter, &size)) |
| 242 | return false; |
| 243 | |
| 244 | for (int i = 0; i < size; ++i) { |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 245 | std::unique_ptr<base::Value> subval; |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 246 | if (!ReadValue(m, iter, &subval, recursion + 1)) |
| 247 | return false; |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 248 | value->Set(i, std::move(subval)); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | return true; |
| 252 | } |
| 253 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 254 | bool ReadValue(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 255 | base::PickleIterator* iter, |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 256 | std::unique_ptr<base::Value>* value, |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 257 | int recursion) { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 258 | if (recursion > kMaxRecursionDepth) { |
joaodasilva | 383b174a | 2017-01-10 09:55:36 | [diff] [blame] | 259 | LOG(ERROR) << "Max recursion depth hit in ReadValue."; |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 260 | return false; |
| 261 | } |
| 262 | |
| 263 | int type; |
| 264 | if (!ReadParam(m, iter, &type)) |
| 265 | return false; |
| 266 | |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 267 | switch (static_cast<base::Value::Type>(type)) { |
| 268 | case base::Value::Type::NONE: |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 269 | *value = base::MakeUnique<base::Value>(); |
jdoerrie | e067999a | 2017-04-07 06:39:00 | [diff] [blame] | 270 | break; |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 271 | case base::Value::Type::BOOLEAN: { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 272 | bool val; |
| 273 | if (!ReadParam(m, iter, &val)) |
| 274 | return false; |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 275 | *value = base::MakeUnique<base::Value>(val); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 276 | break; |
| 277 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 278 | case base::Value::Type::INTEGER: { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 279 | int val; |
| 280 | if (!ReadParam(m, iter, &val)) |
| 281 | return false; |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 282 | *value = base::MakeUnique<base::Value>(val); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 283 | break; |
| 284 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 285 | case base::Value::Type::DOUBLE: { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 286 | double val; |
| 287 | if (!ReadParam(m, iter, &val)) |
| 288 | return false; |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 289 | *value = base::MakeUnique<base::Value>(val); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 290 | break; |
| 291 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 292 | case base::Value::Type::STRING: { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 293 | std::string val; |
| 294 | if (!ReadParam(m, iter, &val)) |
| 295 | return false; |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 296 | *value = base::MakeUnique<base::Value>(std::move(val)); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 297 | break; |
| 298 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 299 | case base::Value::Type::BINARY: { |
[email protected] | e4dad9fb | 2009-10-06 18:15:58 | [diff] [blame] | 300 | const char* data; |
| 301 | int length; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 302 | if (!iter->ReadData(&data, &length)) |
[email protected] | e4dad9fb | 2009-10-06 18:15:58 | [diff] [blame] | 303 | return false; |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 304 | *value = base::Value::CreateWithCopiedBuffer(data, length); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 305 | break; |
| 306 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 307 | case base::Value::Type::DICTIONARY: { |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 308 | base::DictionaryValue val; |
| 309 | if (!ReadDictionaryValue(m, iter, &val, recursion)) |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 310 | return false; |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 311 | *value = base::MakeUnique<base::Value>(std::move(val)); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 312 | break; |
| 313 | } |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 314 | case base::Value::Type::LIST: { |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 315 | base::ListValue val; |
| 316 | if (!ReadListValue(m, iter, &val, recursion)) |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 317 | return false; |
jdoerrie | f1e72e3 | 2017-04-26 16:23:55 | [diff] [blame] | 318 | *value = base::MakeUnique<base::Value>(std::move(val)); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 319 | break; |
| 320 | } |
[email protected] | e4dad9fb | 2009-10-06 18:15:58 | [diff] [blame] | 321 | default: |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 322 | return false; |
| 323 | } |
| 324 | |
| 325 | return true; |
| 326 | } |
| 327 | |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 328 | } // namespace |
| 329 | |
| 330 | // ----------------------------------------------------------------------------- |
| 331 | |
| 332 | LogData::LogData() |
| 333 | : routing_id(0), |
| 334 | type(0), |
| 335 | sent(0), |
| 336 | receive(0), |
| 337 | dispatch(0) { |
| 338 | } |
| 339 | |
vmpstr | bf0d713a | 2016-03-24 20:22:54 | [diff] [blame] | 340 | LogData::LogData(const LogData& other) = default; |
| 341 | |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 342 | LogData::~LogData() { |
| 343 | } |
| 344 | |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 345 | void ParamTraits<bool>::Log(const param_type& p, std::string* l) { |
| 346 | l->append(p ? "true" : "false"); |
| 347 | } |
| 348 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 349 | void ParamTraits<signed char>::GetSize(base::PickleSizer* sizer, |
| 350 | const param_type& p) { |
| 351 | sizer->AddBytes(sizeof(param_type)); |
| 352 | } |
| 353 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 354 | void ParamTraits<signed char>::Write(base::Pickle* m, const param_type& p) { |
ortuno | 19ecf184 | 2015-10-30 00:46:20 | [diff] [blame] | 355 | m->WriteBytes(&p, sizeof(param_type)); |
| 356 | } |
| 357 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 358 | bool ParamTraits<signed char>::Read(const base::Pickle* m, |
| 359 | base::PickleIterator* iter, |
| 360 | param_type* r) { |
ortuno | 19ecf184 | 2015-10-30 00:46:20 | [diff] [blame] | 361 | const char* data; |
| 362 | if (!iter->ReadBytes(&data, sizeof(param_type))) |
| 363 | return false; |
| 364 | memcpy(r, data, sizeof(param_type)); |
| 365 | return true; |
| 366 | } |
| 367 | |
| 368 | void ParamTraits<signed char>::Log(const param_type& p, std::string* l) { |
| 369 | l->append(base::IntToString(p)); |
| 370 | } |
| 371 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 372 | void ParamTraits<unsigned char>::GetSize(base::PickleSizer* sizer, |
| 373 | const param_type& p) { |
| 374 | sizer->AddBytes(sizeof(param_type)); |
| 375 | } |
| 376 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 377 | void ParamTraits<unsigned char>::Write(base::Pickle* m, const param_type& p) { |
[email protected] | c1ee48d | 2013-07-12 23:12:28 | [diff] [blame] | 378 | m->WriteBytes(&p, sizeof(param_type)); |
| 379 | } |
| 380 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 381 | bool ParamTraits<unsigned char>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 382 | base::PickleIterator* iter, |
| 383 | param_type* r) { |
[email protected] | c1ee48d | 2013-07-12 23:12:28 | [diff] [blame] | 384 | const char* data; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 385 | if (!iter->ReadBytes(&data, sizeof(param_type))) |
[email protected] | c1ee48d | 2013-07-12 23:12:28 | [diff] [blame] | 386 | return false; |
| 387 | memcpy(r, data, sizeof(param_type)); |
| 388 | return true; |
| 389 | } |
| 390 | |
| 391 | void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) { |
| 392 | l->append(base::UintToString(p)); |
| 393 | } |
| 394 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 395 | void ParamTraits<unsigned short>::GetSize(base::PickleSizer* sizer, |
| 396 | const param_type& p) { |
| 397 | sizer->AddBytes(sizeof(param_type)); |
| 398 | } |
| 399 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 400 | void ParamTraits<unsigned short>::Write(base::Pickle* m, const param_type& p) { |
[email protected] | c1ee48d | 2013-07-12 23:12:28 | [diff] [blame] | 401 | m->WriteBytes(&p, sizeof(param_type)); |
| 402 | } |
| 403 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 404 | bool ParamTraits<unsigned short>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 405 | base::PickleIterator* iter, |
[email protected] | c1ee48d | 2013-07-12 23:12:28 | [diff] [blame] | 406 | param_type* r) { |
| 407 | const char* data; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 408 | if (!iter->ReadBytes(&data, sizeof(param_type))) |
[email protected] | c1ee48d | 2013-07-12 23:12:28 | [diff] [blame] | 409 | return false; |
| 410 | memcpy(r, data, sizeof(param_type)); |
| 411 | return true; |
| 412 | } |
| 413 | |
| 414 | void ParamTraits<unsigned short>::Log(const param_type& p, std::string* l) { |
| 415 | l->append(base::UintToString(p)); |
| 416 | } |
| 417 | |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 418 | void ParamTraits<int>::Log(const param_type& p, std::string* l) { |
| 419 | l->append(base::IntToString(p)); |
| 420 | } |
| 421 | |
| 422 | void ParamTraits<unsigned int>::Log(const param_type& p, std::string* l) { |
| 423 | l->append(base::UintToString(p)); |
| 424 | } |
| 425 | |
jam | ac78d7d8 | 2016-02-11 00:50:28 | [diff] [blame] | 426 | #if defined(OS_WIN) || defined(OS_LINUX) || \ |
| 427 | (defined(OS_ANDROID) && defined(ARCH_CPU_64_BITS)) |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 428 | void ParamTraits<long>::Log(const param_type& p, std::string* l) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 429 | l->append(base::Int64ToString(static_cast<int64_t>(p))); |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | void ParamTraits<unsigned long>::Log(const param_type& p, std::string* l) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 433 | l->append(base::Uint64ToString(static_cast<uint64_t>(p))); |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 434 | } |
jam | 03d8a78 | 2016-02-10 20:13:39 | [diff] [blame] | 435 | #endif |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 436 | |
| 437 | void ParamTraits<long long>::Log(const param_type& p, std::string* l) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 438 | l->append(base::Int64ToString(static_cast<int64_t>(p))); |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) { |
| 442 | l->append(base::Uint64ToString(p)); |
| 443 | } |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 444 | |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 445 | void ParamTraits<float>::Log(const param_type& p, std::string* l) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 446 | l->append(base::StringPrintf("%e", p)); |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 447 | } |
| 448 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 449 | void ParamTraits<double>::GetSize(base::PickleSizer* sizer, |
| 450 | const param_type& p) { |
| 451 | sizer->AddBytes(sizeof(param_type)); |
| 452 | } |
| 453 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 454 | void ParamTraits<double>::Write(base::Pickle* m, const param_type& p) { |
[email protected] | 48328ff | 2013-10-31 09:27:31 | [diff] [blame] | 455 | m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type)); |
[email protected] | d84e48b | 2010-10-21 22:04:52 | [diff] [blame] | 456 | } |
| 457 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 458 | bool ParamTraits<double>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 459 | base::PickleIterator* iter, |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 460 | param_type* r) { |
| 461 | const char *data; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 462 | if (!iter->ReadBytes(&data, sizeof(*r))) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 463 | NOTREACHED(); |
| 464 | return false; |
| 465 | } |
| 466 | memcpy(r, data, sizeof(param_type)); |
| 467 | return true; |
[email protected] | d84e48b | 2010-10-21 22:04:52 | [diff] [blame] | 468 | } |
| 469 | |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 470 | void ParamTraits<double>::Log(const param_type& p, std::string* l) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 471 | l->append(base::StringPrintf("%e", p)); |
[email protected] | 1d14f58 | 2011-09-02 20:42:04 | [diff] [blame] | 472 | } |
| 473 | |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 474 | |
| 475 | void ParamTraits<std::string>::Log(const param_type& p, std::string* l) { |
| 476 | l->append(p); |
[email protected] | 1d14f58 | 2011-09-02 20:42:04 | [diff] [blame] | 477 | } |
| 478 | |
[email protected] | 476dafb | 2013-12-03 00:39:26 | [diff] [blame] | 479 | void ParamTraits<base::string16>::Log(const param_type& p, std::string* l) { |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 480 | l->append(base::UTF16ToUTF8(p)); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 481 | } |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 482 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 483 | void ParamTraits<std::vector<char>>::GetSize(base::PickleSizer* sizer, |
| 484 | const param_type& p) { |
| 485 | sizer->AddData(static_cast<int>(p.size())); |
| 486 | } |
| 487 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 488 | void ParamTraits<std::vector<char>>::Write(base::Pickle* m, |
| 489 | const param_type& p) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 490 | if (p.empty()) { |
| 491 | m->WriteData(NULL, 0); |
| 492 | } else { |
| 493 | m->WriteData(&p.front(), static_cast<int>(p.size())); |
| 494 | } |
| 495 | } |
| 496 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 497 | bool ParamTraits<std::vector<char>>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 498 | base::PickleIterator* iter, |
| 499 | param_type* r) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 500 | const char *data; |
| 501 | int data_size = 0; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 502 | if (!iter->ReadData(&data, &data_size) || data_size < 0) |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 503 | return false; |
| 504 | r->resize(data_size); |
| 505 | if (data_size) |
| 506 | memcpy(&r->front(), data, data_size); |
| 507 | return true; |
| 508 | } |
| 509 | |
| 510 | void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) { |
| 511 | LogBytes(p, l); |
| 512 | } |
| 513 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 514 | void ParamTraits<std::vector<unsigned char>>::GetSize(base::PickleSizer* sizer, |
| 515 | const param_type& p) { |
| 516 | sizer->AddData(static_cast<int>(p.size())); |
| 517 | } |
| 518 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 519 | void ParamTraits<std::vector<unsigned char>>::Write(base::Pickle* m, |
| 520 | const param_type& p) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 521 | if (p.empty()) { |
| 522 | m->WriteData(NULL, 0); |
| 523 | } else { |
| 524 | m->WriteData(reinterpret_cast<const char*>(&p.front()), |
| 525 | static_cast<int>(p.size())); |
| 526 | } |
| 527 | } |
| 528 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 529 | bool ParamTraits<std::vector<unsigned char>>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 530 | base::PickleIterator* iter, |
| 531 | param_type* r) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 532 | const char *data; |
| 533 | int data_size = 0; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 534 | if (!iter->ReadData(&data, &data_size) || data_size < 0) |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 535 | return false; |
| 536 | r->resize(data_size); |
| 537 | if (data_size) |
| 538 | memcpy(&r->front(), data, data_size); |
| 539 | return true; |
| 540 | } |
| 541 | |
| 542 | void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p, |
| 543 | std::string* l) { |
| 544 | LogBytes(p, l); |
| 545 | } |
| 546 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 547 | void ParamTraits<std::vector<bool>>::GetSize(base::PickleSizer* sizer, |
| 548 | const param_type& p) { |
| 549 | GetParamSize(sizer, static_cast<int>(p.size())); |
| 550 | for (size_t i = 0; i < p.size(); ++i) |
| 551 | GetParamSize(sizer, static_cast<bool>(p[i])); |
| 552 | } |
| 553 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 554 | void ParamTraits<std::vector<bool>>::Write(base::Pickle* m, |
| 555 | const param_type& p) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 556 | WriteParam(m, static_cast<int>(p.size())); |
[email protected] | d412485 | 2013-03-20 20:25:00 | [diff] [blame] | 557 | // Cast to bool below is required because libc++'s |
| 558 | // vector<bool>::const_reference is different from bool, and we want to avoid |
| 559 | // writing an extra specialization of ParamTraits for it. |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 560 | for (size_t i = 0; i < p.size(); i++) |
[email protected] | d412485 | 2013-03-20 20:25:00 | [diff] [blame] | 561 | WriteParam(m, static_cast<bool>(p[i])); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 562 | } |
| 563 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 564 | bool ParamTraits<std::vector<bool>>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 565 | base::PickleIterator* iter, |
| 566 | param_type* r) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 567 | int size; |
| 568 | // ReadLength() checks for < 0 itself. |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 569 | if (!iter->ReadLength(&size)) |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 570 | return false; |
| 571 | r->resize(size); |
| 572 | for (int i = 0; i < size; i++) { |
| 573 | bool value; |
| 574 | if (!ReadParam(m, iter, &value)) |
| 575 | return false; |
| 576 | (*r)[i] = value; |
| 577 | } |
| 578 | return true; |
| 579 | } |
| 580 | |
| 581 | void ParamTraits<std::vector<bool> >::Log(const param_type& p, std::string* l) { |
| 582 | for (size_t i = 0; i < p.size(); ++i) { |
| 583 | if (i != 0) |
| 584 | l->push_back(' '); |
[email protected] | d412485 | 2013-03-20 20:25:00 | [diff] [blame] | 585 | LogParam(static_cast<bool>(p[i]), l); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 586 | } |
[email protected] | d84e48b | 2010-10-21 22:04:52 | [diff] [blame] | 587 | } |
| 588 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 589 | void ParamTraits<base::DictionaryValue>::GetSize(base::PickleSizer* sizer, |
| 590 | const param_type& p) { |
| 591 | GetValueSize(sizer, &p, 0); |
| 592 | } |
| 593 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 594 | void ParamTraits<base::DictionaryValue>::Write(base::Pickle* m, |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 595 | const param_type& p) { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 596 | WriteValue(m, &p, 0); |
| 597 | } |
| 598 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 599 | bool ParamTraits<base::DictionaryValue>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 600 | base::PickleIterator* iter, |
| 601 | param_type* r) { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 602 | int type; |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 603 | if (!ReadParam(m, iter, &type) || |
| 604 | type != static_cast<int>(base::Value::Type::DICTIONARY)) |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 605 | return false; |
| 606 | |
| 607 | return ReadDictionaryValue(m, iter, r, 0); |
| 608 | } |
| 609 | |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 610 | void ParamTraits<base::DictionaryValue>::Log(const param_type& p, |
| 611 | std::string* l) { |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 612 | std::string json; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 613 | base::JSONWriter::Write(p, &json); |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 614 | l->append(json); |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 615 | } |
| 616 | |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 617 | #if defined(OS_POSIX) |
jam | 45eceef | 2016-05-11 21:05:05 | [diff] [blame] | 618 | void ParamTraits<base::FileDescriptor>::GetSize(base::PickleSizer* sizer, |
| 619 | const param_type& p) { |
| 620 | GetParamSize(sizer, p.fd >= 0); |
amistry | 3618252 | 2016-06-27 06:34:42 | [diff] [blame] | 621 | if (p.fd >= 0) |
| 622 | sizer->AddAttachment(); |
jam | 45eceef | 2016-05-11 21:05:05 | [diff] [blame] | 623 | } |
| 624 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 625 | void ParamTraits<base::FileDescriptor>::Write(base::Pickle* m, |
| 626 | const param_type& p) { |
erikchen | 1452520 | 2017-05-06 19:16:51 | [diff] [blame] | 627 | // This serialization must be kept in sync with |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 628 | // nacl_message_scanner.cc:WriteHandle(). |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 629 | const bool valid = p.fd >= 0; |
| 630 | WriteParam(m, valid); |
| 631 | |
morrita | 9669385 | 2014-09-24 20:11:45 | [diff] [blame] | 632 | if (!valid) |
| 633 | return; |
| 634 | |
| 635 | if (p.auto_close) { |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 636 | if (!m->WriteAttachment( |
| 637 | new internal::PlatformFileAttachment(base::ScopedFD(p.fd)))) |
morrita | 9669385 | 2014-09-24 20:11:45 | [diff] [blame] | 638 | NOTREACHED(); |
| 639 | } else { |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 640 | if (!m->WriteAttachment(new internal::PlatformFileAttachment(p.fd))) |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 641 | NOTREACHED(); |
| 642 | } |
| 643 | } |
| 644 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 645 | bool ParamTraits<base::FileDescriptor>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 646 | base::PickleIterator* iter, |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 647 | param_type* r) { |
morrita | 9669385 | 2014-09-24 20:11:45 | [diff] [blame] | 648 | *r = base::FileDescriptor(); |
| 649 | |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 650 | bool valid; |
| 651 | if (!ReadParam(m, iter, &valid)) |
| 652 | return false; |
| 653 | |
morrita | 9669385 | 2014-09-24 20:11:45 | [diff] [blame] | 654 | if (!valid) |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 655 | return true; |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 656 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 657 | scoped_refptr<base::Pickle::Attachment> attachment; |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 658 | if (!m->ReadAttachment(iter, &attachment)) |
morrita | 9669385 | 2014-09-24 20:11:45 | [diff] [blame] | 659 | return false; |
| 660 | |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 661 | if (static_cast<MessageAttachment*>(attachment.get())->GetType() != |
| 662 | MessageAttachment::Type::PLATFORM_FILE) { |
| 663 | return false; |
| 664 | } |
| 665 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 666 | *r = base::FileDescriptor( |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 667 | static_cast<internal::PlatformFileAttachment*>(attachment.get()) |
| 668 | ->TakePlatformFile(), |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 669 | true); |
morrita | 9669385 | 2014-09-24 20:11:45 | [diff] [blame] | 670 | return true; |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | void ParamTraits<base::FileDescriptor>::Log(const param_type& p, |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 674 | std::string* l) { |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 675 | if (p.auto_close) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 676 | l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 677 | } else { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 678 | l->append(base::StringPrintf("FD(%d)", p.fd)); |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 679 | } |
| 680 | } |
| 681 | #endif // defined(OS_POSIX) |
| 682 | |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 683 | void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* sizer, |
| 684 | const param_type& p) { |
| 685 | GetParamSize(sizer, p.IsValid()); |
| 686 | if (!p.IsValid()) |
| 687 | return; |
| 688 | |
scottmg | d19b4f7 | 2015-06-19 22:51:00 | [diff] [blame] | 689 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 690 | GetParamSize(sizer, p.GetMemoryObject()); |
erikchen | 1452520 | 2017-05-06 19:16:51 | [diff] [blame] | 691 | #elif defined(OS_WIN) |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 692 | GetParamSize(sizer, p.GetHandle()); |
| 693 | #else |
| 694 | sizer->AddAttachment(); |
| 695 | #endif |
erikchen | 1452520 | 2017-05-06 19:16:51 | [diff] [blame] | 696 | |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 697 | GetParamSize(sizer, p.GetGUID()); |
| 698 | GetParamSize(sizer, static_cast<uint64_t>(p.GetSize())); |
erikchen | 22a813b | 2017-04-28 17:10:50 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
| 702 | const param_type& p) { |
erikchen | 1452520 | 2017-05-06 19:16:51 | [diff] [blame] | 703 | // This serialization must be kept in sync with |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 704 | // nacl_message_scanner.cc:WriteHandle(). |
erikchen | 22a813b | 2017-04-28 17:10:50 | [diff] [blame] | 705 | const bool valid = p.IsValid(); |
| 706 | WriteParam(m, valid); |
| 707 | |
| 708 | if (!valid) |
| 709 | return; |
| 710 | |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 711 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 712 | MachPortMac mach_port_mac(p.GetMemoryObject()); |
| 713 | WriteParam(m, mach_port_mac); |
| 714 | #elif defined(OS_WIN) |
| 715 | HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE); |
| 716 | WriteParam(m, handle_win); |
| 717 | #else |
erikchen | 22a813b | 2017-04-28 17:10:50 | [diff] [blame] | 718 | if (p.OwnershipPassesToIPC()) { |
| 719 | if (!m->WriteAttachment(new internal::PlatformFileAttachment( |
| 720 | base::ScopedFD(p.GetHandle())))) |
| 721 | NOTREACHED(); |
| 722 | } else { |
| 723 | if (!m->WriteAttachment( |
| 724 | new internal::PlatformFileAttachment(p.GetHandle()))) |
| 725 | NOTREACHED(); |
| 726 | } |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 727 | #endif |
| 728 | |
| 729 | #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) |
| 730 | // If the caller intended to pass ownership to the IPC stack, release a |
| 731 | // reference. |
| 732 | if (p.OwnershipPassesToIPC()) |
| 733 | p.Close(); |
| 734 | #endif |
| 735 | |
erikchen | 1452520 | 2017-05-06 19:16:51 | [diff] [blame] | 736 | DCHECK(!p.GetGUID().is_empty()); |
| 737 | WriteParam(m, p.GetGUID()); |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 738 | WriteParam(m, static_cast<uint64_t>(p.GetSize())); |
erikchen | 22a813b | 2017-04-28 17:10:50 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
| 742 | base::PickleIterator* iter, |
| 743 | param_type* r) { |
| 744 | *r = base::SharedMemoryHandle(); |
| 745 | |
| 746 | bool valid; |
| 747 | if (!ReadParam(m, iter, &valid)) |
| 748 | return false; |
erikchen | 22a813b | 2017-04-28 17:10:50 | [diff] [blame] | 749 | if (!valid) |
| 750 | return true; |
| 751 | |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 752 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 753 | MachPortMac mach_port_mac; |
| 754 | if (!ReadParam(m, iter, &mach_port_mac)) |
| 755 | return false; |
| 756 | #elif defined(OS_WIN) |
| 757 | HandleWin handle_win; |
| 758 | if (!ReadParam(m, iter, &handle_win)) |
| 759 | return false; |
Scott Graham | 3eebff0 | 2017-06-30 01:07:10 | [diff] [blame^] | 760 | #elif defined(OS_FUCHSIA) |
| 761 | HandleFuchsia handle_fuchsia; |
| 762 | if (!ReadParam(m, iter, &handle_fuchsia)) |
| 763 | return false; |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 764 | #else |
erikchen | 22a813b | 2017-04-28 17:10:50 | [diff] [blame] | 765 | scoped_refptr<base::Pickle::Attachment> attachment; |
| 766 | if (!m->ReadAttachment(iter, &attachment)) |
| 767 | return false; |
| 768 | |
| 769 | if (static_cast<MessageAttachment*>(attachment.get())->GetType() != |
| 770 | MessageAttachment::Type::PLATFORM_FILE) { |
| 771 | return false; |
| 772 | } |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 773 | #endif |
erikchen | 22a813b | 2017-04-28 17:10:50 | [diff] [blame] | 774 | |
erikchen | 1452520 | 2017-05-06 19:16:51 | [diff] [blame] | 775 | base::UnguessableToken guid; |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 776 | uint64_t size; |
| 777 | if (!ReadParam(m, iter, &guid) || !ReadParam(m, iter, &size)) { |
erikchen | 1452520 | 2017-05-06 19:16:51 | [diff] [blame] | 778 | return false; |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 779 | } |
erikchen | 1452520 | 2017-05-06 19:16:51 | [diff] [blame] | 780 | |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 781 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 782 | *r = base::SharedMemoryHandle(mach_port_mac.get_mach_port(), |
| 783 | static_cast<size_t>(size), guid); |
| 784 | #elif defined(OS_WIN) |
| 785 | *r = base::SharedMemoryHandle(handle_win.get_handle(), |
| 786 | static_cast<size_t>(size), guid); |
Scott Graham | 3eebff0 | 2017-06-30 01:07:10 | [diff] [blame^] | 787 | #elif defined(OS_FUCHSIA) |
| 788 | *r = base::SharedMemoryHandle(handle_fuchsia.get_handle(), |
| 789 | static_cast<size_t>(size), guid); |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 790 | #else |
erikchen | 1452520 | 2017-05-06 19:16:51 | [diff] [blame] | 791 | *r = base::SharedMemoryHandle( |
| 792 | base::FileDescriptor( |
| 793 | static_cast<internal::PlatformFileAttachment*>(attachment.get()) |
| 794 | ->TakePlatformFile(), |
| 795 | true), |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 796 | static_cast<size_t>(size), guid); |
| 797 | #endif |
| 798 | |
erikchen | 22a813b | 2017-04-28 17:10:50 | [diff] [blame] | 799 | return true; |
| 800 | } |
| 801 | |
| 802 | void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
| 803 | std::string* l) { |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 804 | #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 805 | l->append("Mach port: "); |
| 806 | LogParam(p.GetMemoryObject(), l); |
| 807 | #elif defined(OS_WIN) |
| 808 | l->append("HANDLE: "); |
| 809 | LogParam(p.GetHandle(), l); |
| 810 | #else |
| 811 | l->append("FD: "); |
| 812 | LogParam(p.GetHandle(), l); |
| 813 | #endif |
| 814 | |
erikchen | 1452520 | 2017-05-06 19:16:51 | [diff] [blame] | 815 | l->append("GUID: "); |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 816 | LogParam(p.GetGUID(), l); |
| 817 | l->append("size: "); |
| 818 | LogParam(static_cast<uint64_t>(p.GetSize()), l); |
erikchen | 22a813b | 2017-04-28 17:10:50 | [diff] [blame] | 819 | } |
scottmg | d19b4f7 | 2015-06-19 22:51:00 | [diff] [blame] | 820 | |
erikchen | d804e105 | 2017-04-29 02:24:36 | [diff] [blame] | 821 | #if defined(OS_WIN) |
| 822 | void ParamTraits<PlatformFileForTransit>::GetSize(base::PickleSizer* s, |
| 823 | const param_type& p) { |
| 824 | GetParamSize(s, p.IsValid()); |
| 825 | if (p.IsValid()) |
| 826 | GetParamSize(s, p.GetHandle()); |
| 827 | } |
| 828 | |
| 829 | void ParamTraits<PlatformFileForTransit>::Write(base::Pickle* m, |
| 830 | const param_type& p) { |
| 831 | m->WriteBool(p.IsValid()); |
| 832 | if (p.IsValid()) { |
| 833 | HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE); |
| 834 | ParamTraits<HandleWin>::Write(m, handle_win); |
| 835 | ::CloseHandle(p.GetHandle()); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | bool ParamTraits<PlatformFileForTransit>::Read(const base::Pickle* m, |
| 840 | base::PickleIterator* iter, |
| 841 | param_type* r) { |
| 842 | bool is_valid; |
| 843 | if (!iter->ReadBool(&is_valid)) |
| 844 | return false; |
| 845 | if (!is_valid) { |
| 846 | *r = PlatformFileForTransit(); |
| 847 | return true; |
| 848 | } |
| 849 | |
| 850 | HandleWin handle_win; |
| 851 | if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win)) |
| 852 | return false; |
| 853 | *r = PlatformFileForTransit(handle_win.get_handle()); |
| 854 | return true; |
| 855 | } |
| 856 | |
| 857 | void ParamTraits<PlatformFileForTransit>::Log(const param_type& p, |
| 858 | std::string* l) { |
| 859 | LogParam(p.GetHandle(), l); |
| 860 | } |
| 861 | #endif // defined(OS_WIN) |
| 862 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 863 | void ParamTraits<base::FilePath>::GetSize(base::PickleSizer* sizer, |
| 864 | const param_type& p) { |
| 865 | p.GetSizeForPickle(sizer); |
| 866 | } |
| 867 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 868 | void ParamTraits<base::FilePath>::Write(base::Pickle* m, const param_type& p) { |
[email protected] | aeae59f | 2013-01-28 13:47:55 | [diff] [blame] | 869 | p.WriteToPickle(m); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 870 | } |
| 871 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 872 | bool ParamTraits<base::FilePath>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 873 | base::PickleIterator* iter, |
[email protected] | 6d4b67a | 2013-02-10 04:49:30 | [diff] [blame] | 874 | param_type* r) { |
[email protected] | aeae59f | 2013-01-28 13:47:55 | [diff] [blame] | 875 | return r->ReadFromPickle(iter); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 876 | } |
| 877 | |
[email protected] | 6d4b67a | 2013-02-10 04:49:30 | [diff] [blame] | 878 | void ParamTraits<base::FilePath>::Log(const param_type& p, std::string* l) { |
| 879 | ParamTraits<base::FilePath::StringType>::Log(p.value(), l); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 880 | } |
| 881 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 882 | void ParamTraits<base::ListValue>::GetSize(base::PickleSizer* sizer, |
| 883 | const param_type& p) { |
| 884 | GetValueSize(sizer, &p, 0); |
| 885 | } |
| 886 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 887 | void ParamTraits<base::ListValue>::Write(base::Pickle* m, const param_type& p) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 888 | WriteValue(m, &p, 0); |
| 889 | } |
| 890 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 891 | bool ParamTraits<base::ListValue>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 892 | base::PickleIterator* iter, |
| 893 | param_type* r) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 894 | int type; |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 895 | if (!ReadParam(m, iter, &type) || |
| 896 | type != static_cast<int>(base::Value::Type::LIST)) |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 897 | return false; |
| 898 | |
| 899 | return ReadListValue(m, iter, r, 0); |
| 900 | } |
| 901 | |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 902 | void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 903 | std::string json; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 904 | base::JSONWriter::Write(p, &json); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 905 | l->append(json); |
| 906 | } |
| 907 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 908 | void ParamTraits<base::NullableString16>::GetSize(base::PickleSizer* sizer, |
| 909 | const param_type& p) { |
| 910 | GetParamSize(sizer, p.string()); |
| 911 | GetParamSize(sizer, p.is_null()); |
| 912 | } |
| 913 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 914 | void ParamTraits<base::NullableString16>::Write(base::Pickle* m, |
[email protected] | 0238a16 | 2013-06-13 13:47:46 | [diff] [blame] | 915 | const param_type& p) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 916 | WriteParam(m, p.string()); |
| 917 | WriteParam(m, p.is_null()); |
| 918 | } |
| 919 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 920 | bool ParamTraits<base::NullableString16>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 921 | base::PickleIterator* iter, |
[email protected] | 0238a16 | 2013-06-13 13:47:46 | [diff] [blame] | 922 | param_type* r) { |
[email protected] | 476dafb | 2013-12-03 00:39:26 | [diff] [blame] | 923 | base::string16 string; |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 924 | if (!ReadParam(m, iter, &string)) |
| 925 | return false; |
| 926 | bool is_null; |
| 927 | if (!ReadParam(m, iter, &is_null)) |
| 928 | return false; |
[email protected] | 0238a16 | 2013-06-13 13:47:46 | [diff] [blame] | 929 | *r = base::NullableString16(string, is_null); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 930 | return true; |
| 931 | } |
| 932 | |
[email protected] | 0238a16 | 2013-06-13 13:47:46 | [diff] [blame] | 933 | void ParamTraits<base::NullableString16>::Log(const param_type& p, |
| 934 | std::string* l) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 935 | l->append("("); |
| 936 | LogParam(p.string(), l); |
| 937 | l->append(", "); |
| 938 | LogParam(p.is_null(), l); |
| 939 | l->append(")"); |
| 940 | } |
| 941 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 942 | void ParamTraits<base::File::Info>::GetSize(base::PickleSizer* sizer, |
| 943 | const param_type& p) { |
| 944 | GetParamSize(sizer, p.size); |
| 945 | GetParamSize(sizer, p.is_directory); |
| 946 | GetParamSize(sizer, p.last_modified.ToDoubleT()); |
| 947 | GetParamSize(sizer, p.last_accessed.ToDoubleT()); |
| 948 | GetParamSize(sizer, p.creation_time.ToDoubleT()); |
| 949 | } |
| 950 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 951 | void ParamTraits<base::File::Info>::Write(base::Pickle* m, |
[email protected] | 141bcc5 | 2014-01-27 21:36:00 | [diff] [blame] | 952 | const param_type& p) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 953 | WriteParam(m, p.size); |
| 954 | WriteParam(m, p.is_directory); |
| 955 | WriteParam(m, p.last_modified.ToDoubleT()); |
| 956 | WriteParam(m, p.last_accessed.ToDoubleT()); |
| 957 | WriteParam(m, p.creation_time.ToDoubleT()); |
| 958 | } |
| 959 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 960 | bool ParamTraits<base::File::Info>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 961 | base::PickleIterator* iter, |
[email protected] | 141bcc5 | 2014-01-27 21:36:00 | [diff] [blame] | 962 | param_type* p) { |
[email protected] | 481c3e8 | 2014-07-18 01:40:47 | [diff] [blame] | 963 | double last_modified, last_accessed, creation_time; |
| 964 | if (!ReadParam(m, iter, &p->size) || |
| 965 | !ReadParam(m, iter, &p->is_directory) || |
| 966 | !ReadParam(m, iter, &last_modified) || |
| 967 | !ReadParam(m, iter, &last_accessed) || |
| 968 | !ReadParam(m, iter, &creation_time)) |
| 969 | return false; |
| 970 | p->last_modified = base::Time::FromDoubleT(last_modified); |
| 971 | p->last_accessed = base::Time::FromDoubleT(last_accessed); |
| 972 | p->creation_time = base::Time::FromDoubleT(creation_time); |
| 973 | return true; |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 974 | } |
| 975 | |
[email protected] | 141bcc5 | 2014-01-27 21:36:00 | [diff] [blame] | 976 | void ParamTraits<base::File::Info>::Log(const param_type& p, |
| 977 | std::string* l) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 978 | l->append("("); |
| 979 | LogParam(p.size, l); |
| 980 | l->append(","); |
| 981 | LogParam(p.is_directory, l); |
| 982 | l->append(","); |
| 983 | LogParam(p.last_modified.ToDoubleT(), l); |
| 984 | l->append(","); |
| 985 | LogParam(p.last_accessed.ToDoubleT(), l); |
| 986 | l->append(","); |
| 987 | LogParam(p.creation_time.ToDoubleT(), l); |
| 988 | l->append(")"); |
| 989 | } |
| 990 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 991 | void ParamTraits<base::Time>::GetSize(base::PickleSizer* sizer, |
| 992 | const param_type& p) { |
| 993 | sizer->AddInt64(); |
| 994 | } |
| 995 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 996 | void ParamTraits<base::Time>::Write(base::Pickle* m, const param_type& p) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 997 | ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 998 | } |
| 999 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1000 | bool ParamTraits<base::Time>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 1001 | base::PickleIterator* iter, |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1002 | param_type* r) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1003 | int64_t value; |
| 1004 | if (!ParamTraits<int64_t>::Read(m, iter, &value)) |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1005 | return false; |
| 1006 | *r = base::Time::FromInternalValue(value); |
| 1007 | return true; |
| 1008 | } |
| 1009 | |
| 1010 | void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1011 | ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1012 | } |
| 1013 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 1014 | void ParamTraits<base::TimeDelta>::GetSize(base::PickleSizer* sizer, |
| 1015 | const param_type& p) { |
| 1016 | sizer->AddInt64(); |
| 1017 | } |
| 1018 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1019 | void ParamTraits<base::TimeDelta>::Write(base::Pickle* m, const param_type& p) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1020 | ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1021 | } |
| 1022 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1023 | bool ParamTraits<base::TimeDelta>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 1024 | base::PickleIterator* iter, |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1025 | param_type* r) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1026 | int64_t value; |
| 1027 | bool ret = ParamTraits<int64_t>::Read(m, iter, &value); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1028 | if (ret) |
| 1029 | *r = base::TimeDelta::FromInternalValue(value); |
| 1030 | |
| 1031 | return ret; |
| 1032 | } |
| 1033 | |
| 1034 | void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1035 | ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1036 | } |
| 1037 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 1038 | void ParamTraits<base::TimeTicks>::GetSize(base::PickleSizer* sizer, |
| 1039 | const param_type& p) { |
| 1040 | sizer->AddInt64(); |
| 1041 | } |
| 1042 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1043 | void ParamTraits<base::TimeTicks>::Write(base::Pickle* m, const param_type& p) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1044 | ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1045 | } |
| 1046 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1047 | bool ParamTraits<base::TimeTicks>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 1048 | base::PickleIterator* iter, |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1049 | param_type* r) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1050 | int64_t value; |
| 1051 | bool ret = ParamTraits<int64_t>::Read(m, iter, &value); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1052 | if (ret) |
| 1053 | *r = base::TimeTicks::FromInternalValue(value); |
| 1054 | |
| 1055 | return ret; |
| 1056 | } |
| 1057 | |
| 1058 | void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1059 | ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1060 | } |
| 1061 | |
tguilbert | 4a5ac60 | 2016-09-19 21:11:25 | [diff] [blame] | 1062 | // If base::UnguessableToken is no longer 128 bits, the IPC serialization logic |
| 1063 | // below should be updated. |
| 1064 | static_assert(sizeof(base::UnguessableToken) == 2 * sizeof(uint64_t), |
| 1065 | "base::UnguessableToken should be of size 2 * sizeof(uint64_t)."); |
| 1066 | |
| 1067 | void ParamTraits<base::UnguessableToken>::GetSize(base::PickleSizer* sizer, |
| 1068 | const param_type& p) { |
| 1069 | sizer->AddBytes(2 * sizeof(uint64_t)); |
| 1070 | } |
| 1071 | |
| 1072 | void ParamTraits<base::UnguessableToken>::Write(base::Pickle* m, |
| 1073 | const param_type& p) { |
| 1074 | DCHECK(!p.is_empty()); |
| 1075 | |
erikchen | 1452520 | 2017-05-06 19:16:51 | [diff] [blame] | 1076 | // This serialization must be kept in sync with |
erikchen | 9d6afd71 | 2017-05-18 17:49:06 | [diff] [blame] | 1077 | // nacl_message_scanner.cc:WriteHandle(). |
tguilbert | 4a5ac60 | 2016-09-19 21:11:25 | [diff] [blame] | 1078 | ParamTraits<uint64_t>::Write(m, p.GetHighForSerialization()); |
| 1079 | ParamTraits<uint64_t>::Write(m, p.GetLowForSerialization()); |
| 1080 | } |
| 1081 | |
| 1082 | bool ParamTraits<base::UnguessableToken>::Read(const base::Pickle* m, |
| 1083 | base::PickleIterator* iter, |
| 1084 | param_type* r) { |
| 1085 | uint64_t high, low; |
| 1086 | if (!ParamTraits<uint64_t>::Read(m, iter, &high) || |
| 1087 | !ParamTraits<uint64_t>::Read(m, iter, &low)) |
| 1088 | return false; |
| 1089 | |
| 1090 | // Receiving a zeroed UnguessableToken is a security issue. |
| 1091 | if (high == 0 && low == 0) |
| 1092 | return false; |
| 1093 | |
| 1094 | *r = base::UnguessableToken::Deserialize(high, low); |
| 1095 | return true; |
| 1096 | } |
| 1097 | |
| 1098 | void ParamTraits<base::UnguessableToken>::Log(const param_type& p, |
| 1099 | std::string* l) { |
| 1100 | l->append(p.ToString()); |
| 1101 | } |
| 1102 | |
jam | 3db6b6d | 2016-05-13 15:09:58 | [diff] [blame] | 1103 | void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer, |
| 1104 | const param_type& p) { |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 1105 | #if defined(OS_NACL_SFI) |
jam | 3db6b6d | 2016-05-13 15:09:58 | [diff] [blame] | 1106 | GetParamSize(sizer, p.socket); |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 1107 | #else |
amistry | 3618252 | 2016-06-27 06:34:42 | [diff] [blame] | 1108 | GetParamSize(sizer, p.mojo_handle); |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 1109 | #endif |
jam | 3db6b6d | 2016-05-13 15:09:58 | [diff] [blame] | 1110 | } |
| 1111 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1112 | void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m, |
| 1113 | const param_type& p) { |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 1114 | #if defined(OS_NACL_SFI) |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 1115 | WriteParam(m, p.socket); |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 1116 | #else |
amistry | 3618252 | 2016-06-27 06:34:42 | [diff] [blame] | 1117 | WriteParam(m, p.mojo_handle); |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 1118 | #endif |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 1119 | } |
| 1120 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1121 | bool ParamTraits<IPC::ChannelHandle>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 1122 | base::PickleIterator* iter, |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 1123 | param_type* r) { |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 1124 | #if defined(OS_NACL_SFI) |
| 1125 | return ReadParam(m, iter, &r->socket); |
| 1126 | #else |
| 1127 | return ReadParam(m, iter, &r->mojo_handle); |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 1128 | #endif |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 1132 | std::string* l) { |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 1133 | l->append("ChannelHandle("); |
| 1134 | #if defined(OS_NACL_SFI) |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 1135 | ParamTraits<base::FileDescriptor>::Log(p.socket, l); |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 1136 | #else |
amistry | 3618252 | 2016-06-27 06:34:42 | [diff] [blame] | 1137 | LogParam(p.mojo_handle, l); |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 1138 | #endif |
[email protected] | 252cad6 | 2010-08-18 18:33:57 | [diff] [blame] | 1139 | l->append(")"); |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 1140 | } |
| 1141 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 1142 | void ParamTraits<LogData>::GetSize(base::PickleSizer* sizer, |
| 1143 | const param_type& p) { |
| 1144 | GetParamSize(sizer, p.channel); |
| 1145 | GetParamSize(sizer, p.routing_id); |
| 1146 | GetParamSize(sizer, p.type); |
| 1147 | GetParamSize(sizer, p.flags); |
| 1148 | GetParamSize(sizer, p.sent); |
| 1149 | GetParamSize(sizer, p.receive); |
| 1150 | GetParamSize(sizer, p.dispatch); |
| 1151 | GetParamSize(sizer, p.message_name); |
| 1152 | GetParamSize(sizer, p.params); |
| 1153 | } |
| 1154 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1155 | void ParamTraits<LogData>::Write(base::Pickle* m, const param_type& p) { |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 1156 | WriteParam(m, p.channel); |
| 1157 | WriteParam(m, p.routing_id); |
[email protected] | 8bf55ca | 2011-10-17 22:15:27 | [diff] [blame] | 1158 | WriteParam(m, p.type); |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 1159 | WriteParam(m, p.flags); |
| 1160 | WriteParam(m, p.sent); |
| 1161 | WriteParam(m, p.receive); |
| 1162 | WriteParam(m, p.dispatch); |
[email protected] | bae578e9 | 2012-11-15 03:17:45 | [diff] [blame] | 1163 | WriteParam(m, p.message_name); |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 1164 | WriteParam(m, p.params); |
| 1165 | } |
| 1166 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1167 | bool ParamTraits<LogData>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 1168 | base::PickleIterator* iter, |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 1169 | param_type* r) { |
[email protected] | 8bf55ca | 2011-10-17 22:15:27 | [diff] [blame] | 1170 | return |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 1171 | ReadParam(m, iter, &r->channel) && |
| 1172 | ReadParam(m, iter, &r->routing_id) && |
[email protected] | 8bf55ca | 2011-10-17 22:15:27 | [diff] [blame] | 1173 | ReadParam(m, iter, &r->type) && |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 1174 | ReadParam(m, iter, &r->flags) && |
| 1175 | ReadParam(m, iter, &r->sent) && |
| 1176 | ReadParam(m, iter, &r->receive) && |
| 1177 | ReadParam(m, iter, &r->dispatch) && |
[email protected] | bae578e9 | 2012-11-15 03:17:45 | [diff] [blame] | 1178 | ReadParam(m, iter, &r->message_name) && |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 1179 | ReadParam(m, iter, &r->params); |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 1180 | } |
| 1181 | |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1182 | void ParamTraits<LogData>::Log(const param_type& p, std::string* l) { |
| 1183 | // Doesn't make sense to implement this! |
| 1184 | } |
| 1185 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1186 | void ParamTraits<Message>::Write(base::Pickle* m, const Message& p) { |
[email protected] | 34d4861 | 2012-06-29 00:05:04 | [diff] [blame] | 1187 | #if defined(OS_POSIX) |
| 1188 | // We don't serialize the file descriptors in the nested message, so there |
| 1189 | // better not be any. |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 1190 | DCHECK(!p.HasAttachments()); |
[email protected] | 34d4861 | 2012-06-29 00:05:04 | [diff] [blame] | 1191 | #endif |
| 1192 | |
| 1193 | // Don't just write out the message. This is used to send messages between |
| 1194 | // NaCl (Posix environment) and the browser (could be on Windows). The message |
| 1195 | // header formats differ between these systems (so does handle sharing, but |
| 1196 | // we already asserted we don't have any handles). So just write out the |
| 1197 | // parts of the header we use. |
| 1198 | // |
| 1199 | // Be careful also to use only explicitly-sized types. The NaCl environment |
| 1200 | // could be 64-bit and the host browser could be 32-bits. The nested message |
| 1201 | // may or may not be safe to send between 32-bit and 64-bit systems, but we |
| 1202 | // leave that up to the code sending the message to ensure. |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1203 | m->WriteUInt32(static_cast<uint32_t>(p.routing_id())); |
[email protected] | 34d4861 | 2012-06-29 00:05:04 | [diff] [blame] | 1204 | m->WriteUInt32(p.type()); |
| 1205 | m->WriteUInt32(p.flags()); |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1206 | m->WriteData(p.payload(), static_cast<uint32_t>(p.payload_size())); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1207 | } |
| 1208 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1209 | bool ParamTraits<Message>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 1210 | base::PickleIterator* iter, |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1211 | Message* r) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1212 | uint32_t routing_id, type, flags; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 1213 | if (!iter->ReadUInt32(&routing_id) || |
| 1214 | !iter->ReadUInt32(&type) || |
| 1215 | !iter->ReadUInt32(&flags)) |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1216 | return false; |
[email protected] | 34d4861 | 2012-06-29 00:05:04 | [diff] [blame] | 1217 | |
| 1218 | int payload_size; |
| 1219 | const char* payload; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 1220 | if (!iter->ReadData(&payload, &payload_size)) |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1221 | return false; |
[email protected] | 34d4861 | 2012-06-29 00:05:04 | [diff] [blame] | 1222 | |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1223 | r->SetHeaderValues(static_cast<int32_t>(routing_id), type, flags); |
[email protected] | 34d4861 | 2012-06-29 00:05:04 | [diff] [blame] | 1224 | return r->WriteBytes(payload, payload_size); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | void ParamTraits<Message>::Log(const Message& p, std::string* l) { |
| 1228 | l->append("<IPC::Message>"); |
| 1229 | } |
| 1230 | |
| 1231 | #if defined(OS_WIN) |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 1232 | void ParamTraits<HANDLE>::GetSize(base::PickleSizer* sizer, |
| 1233 | const param_type& p) { |
| 1234 | sizer->AddInt(); |
| 1235 | } |
| 1236 | |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1237 | // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 |
[email protected] | 4a635b7 | 2013-03-04 02:29:03 | [diff] [blame] | 1238 | // bit systems. That's why we use the Windows macros to convert to 32 bits. |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1239 | void ParamTraits<HANDLE>::Write(base::Pickle* m, const param_type& p) { |
[email protected] | 4a635b7 | 2013-03-04 02:29:03 | [diff] [blame] | 1240 | m->WriteInt(HandleToLong(p)); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1241 | } |
| 1242 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1243 | bool ParamTraits<HANDLE>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 1244 | base::PickleIterator* iter, |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1245 | param_type* r) { |
tfarina | 10a5c06 | 2015-09-04 18:47:57 | [diff] [blame] | 1246 | int32_t temp; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 1247 | if (!iter->ReadInt(&temp)) |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1248 | return false; |
[email protected] | 4a635b7 | 2013-03-04 02:29:03 | [diff] [blame] | 1249 | *r = LongToHandle(temp); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1250 | return true; |
| 1251 | } |
| 1252 | |
| 1253 | void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) { |
brucedawson | 5604a11d | 2015-10-06 19:22:00 | [diff] [blame] | 1254 | l->append(base::StringPrintf("0x%p", p)); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1255 | } |
| 1256 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 1257 | void ParamTraits<LOGFONT>::GetSize(base::PickleSizer* sizer, |
| 1258 | const param_type& p) { |
| 1259 | sizer->AddData(sizeof(LOGFONT)); |
| 1260 | } |
| 1261 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1262 | void ParamTraits<LOGFONT>::Write(base::Pickle* m, const param_type& p) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1263 | m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT)); |
| 1264 | } |
| 1265 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1266 | bool ParamTraits<LOGFONT>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 1267 | base::PickleIterator* iter, |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1268 | param_type* r) { |
| 1269 | const char *data; |
| 1270 | int data_size = 0; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 1271 | if (iter->ReadData(&data, &data_size) && data_size == sizeof(LOGFONT)) { |
[email protected] | 2e02cfe8 | 2012-11-21 00:58:00 | [diff] [blame] | 1272 | const LOGFONT *font = reinterpret_cast<LOGFONT*>(const_cast<char*>(data)); |
| 1273 | if (_tcsnlen(font->lfFaceName, LF_FACESIZE) < LF_FACESIZE) { |
| 1274 | memcpy(r, data, sizeof(LOGFONT)); |
| 1275 | return true; |
| 1276 | } |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1277 | } |
| 1278 | |
[email protected] | 2e02cfe8 | 2012-11-21 00:58:00 | [diff] [blame] | 1279 | NOTREACHED(); |
| 1280 | return false; |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 1284 | l->append(base::StringPrintf("<LOGFONT>")); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1285 | } |
| 1286 | |
rockot | 0457af10 | 2016-02-05 02:12:32 | [diff] [blame] | 1287 | void ParamTraits<MSG>::GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 1288 | sizer->AddData(sizeof(MSG)); |
| 1289 | } |
| 1290 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1291 | void ParamTraits<MSG>::Write(base::Pickle* m, const param_type& p) { |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1292 | m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG)); |
| 1293 | } |
| 1294 | |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 1295 | bool ParamTraits<MSG>::Read(const base::Pickle* m, |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 1296 | base::PickleIterator* iter, |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1297 | param_type* r) { |
| 1298 | const char *data; |
| 1299 | int data_size = 0; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 1300 | bool result = iter->ReadData(&data, &data_size); |
[email protected] | bf5aedf0 | 2012-06-04 21:18:25 | [diff] [blame] | 1301 | if (result && data_size == sizeof(MSG)) { |
| 1302 | memcpy(r, data, sizeof(MSG)); |
| 1303 | } else { |
| 1304 | result = false; |
| 1305 | NOTREACHED(); |
| 1306 | } |
| 1307 | |
| 1308 | return result; |
| 1309 | } |
| 1310 | |
| 1311 | void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
| 1312 | l->append("<MSG>"); |
| 1313 | } |
| 1314 | |
| 1315 | #endif // OS_WIN |
| 1316 | |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 1317 | } // namespace IPC |