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