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