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