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