hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 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 "dbus/values_util.h" |
| 6 | |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 7 | #include <utility> |
dcheng | 30c5a17 | 2016-04-09 07:55:04 +0900 | [diff] [blame] | 8 | |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 9 | #include "base/json/json_writer.h" |
| 10 | #include "base/logging.h" |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 11 | #include "base/memory/ptr_util.h" |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 12 | #include "base/values.h" |
| 13 | #include "dbus/message.h" |
| 14 | |
| 15 | namespace dbus { |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | // Returns whether |value| is exactly representable by double or not. |
| 20 | template<typename T> |
| 21 | bool IsExactlyRepresentableByDouble(T value) { |
| 22 | return value == static_cast<T>(static_cast<double>(value)); |
| 23 | } |
| 24 | |
| 25 | // Pops values from |reader| and appends them to |list_value|. |
thestig@chromium.org | e1acdf8 | 2013-02-13 05:06:15 +0900 | [diff] [blame] | 26 | bool PopListElements(MessageReader* reader, base::ListValue* list_value) { |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 27 | while (reader->HasMoreData()) { |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 28 | std::unique_ptr<base::Value> element_value = PopDataAsValue(reader); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 29 | if (!element_value) |
| 30 | return false; |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 31 | list_value->Append(std::move(element_value)); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 32 | } |
| 33 | return true; |
| 34 | } |
| 35 | |
| 36 | // Pops dict-entries from |reader| and sets them to |dictionary_value| |
| 37 | bool PopDictionaryEntries(MessageReader* reader, |
thestig@chromium.org | e1acdf8 | 2013-02-13 05:06:15 +0900 | [diff] [blame] | 38 | base::DictionaryValue* dictionary_value) { |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 39 | while (reader->HasMoreData()) { |
| 40 | DCHECK_EQ(Message::DICT_ENTRY, reader->GetDataType()); |
| 41 | MessageReader entry_reader(NULL); |
| 42 | if (!reader->PopDictEntry(&entry_reader)) |
| 43 | return false; |
| 44 | // Get key as a string. |
| 45 | std::string key_string; |
| 46 | if (entry_reader.GetDataType() == Message::STRING) { |
| 47 | // If the type of keys is STRING, pop it directly. |
| 48 | if (!entry_reader.PopString(&key_string)) |
| 49 | return false; |
| 50 | } else { |
| 51 | // If the type of keys is not STRING, convert it to string. |
dcheng | 30c5a17 | 2016-04-09 07:55:04 +0900 | [diff] [blame] | 52 | std::unique_ptr<base::Value> key(PopDataAsValue(&entry_reader)); |
estade | b5f30dd | 2015-05-16 10:02:34 +0900 | [diff] [blame] | 53 | if (!key) |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 54 | return false; |
| 55 | // Use JSONWriter to convert an arbitrary value to a string. |
estade | b5f30dd | 2015-05-16 10:02:34 +0900 | [diff] [blame] | 56 | base::JSONWriter::Write(*key, &key_string); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 57 | } |
| 58 | // Get the value and set the key-value pair. |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 59 | std::unique_ptr<base::Value> value = PopDataAsValue(&entry_reader); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 60 | if (!value) |
| 61 | return false; |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 62 | dictionary_value->SetWithoutPathExpansion(key_string, std::move(value)); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 63 | } |
| 64 | return true; |
| 65 | } |
| 66 | |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 67 | // Gets the D-Bus type signature for the value. |
| 68 | std::string GetTypeSignature(const base::Value& value) { |
| 69 | switch (value.GetType()) { |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 70 | case base::Value::Type::BOOLEAN: |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 71 | return "b"; |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 72 | case base::Value::Type::INTEGER: |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 73 | return "i"; |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 74 | case base::Value::Type::DOUBLE: |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 75 | return "d"; |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 76 | case base::Value::Type::STRING: |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 77 | return "s"; |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 78 | case base::Value::Type::BINARY: |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 79 | return "ay"; |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 80 | case base::Value::Type::DICTIONARY: |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 81 | return "a{sv}"; |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 82 | case base::Value::Type::LIST: |
armansito@chromium.org | 39d51b9 | 2014-05-22 20:52:55 +0900 | [diff] [blame] | 83 | return "av"; |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 84 | default: |
| 85 | DLOG(ERROR) << "Unexpected type " << value.GetType(); |
dcheng@chromium.org | 8164c2c | 2013-04-09 17:46:45 +0900 | [diff] [blame] | 86 | return std::string(); |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 90 | } // namespace |
| 91 | |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 92 | std::unique_ptr<base::Value> PopDataAsValue(MessageReader* reader) { |
| 93 | std::unique_ptr<base::Value> result; |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 94 | switch (reader->GetDataType()) { |
| 95 | case Message::INVALID_DATA: |
| 96 | // Do nothing. |
| 97 | break; |
| 98 | case Message::BYTE: { |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 99 | uint8_t value = 0; |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 100 | if (reader->PopByte(&value)) |
jdoerrie | bfe825e | 2017-03-02 21:09:19 +0900 | [diff] [blame] | 101 | result = base::MakeUnique<base::Value>(value); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 102 | break; |
| 103 | } |
| 104 | case Message::BOOL: { |
| 105 | bool value = false; |
| 106 | if (reader->PopBool(&value)) |
jdoerrie | bfe825e | 2017-03-02 21:09:19 +0900 | [diff] [blame] | 107 | result = base::MakeUnique<base::Value>(value); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 108 | break; |
| 109 | } |
| 110 | case Message::INT16: { |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 111 | int16_t value = 0; |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 112 | if (reader->PopInt16(&value)) |
jdoerrie | bfe825e | 2017-03-02 21:09:19 +0900 | [diff] [blame] | 113 | result = base::MakeUnique<base::Value>(value); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 114 | break; |
| 115 | } |
| 116 | case Message::UINT16: { |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 117 | uint16_t value = 0; |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 118 | if (reader->PopUint16(&value)) |
jdoerrie | bfe825e | 2017-03-02 21:09:19 +0900 | [diff] [blame] | 119 | result = base::MakeUnique<base::Value>(value); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 120 | break; |
| 121 | } |
| 122 | case Message::INT32: { |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 123 | int32_t value = 0; |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 124 | if (reader->PopInt32(&value)) |
jdoerrie | bfe825e | 2017-03-02 21:09:19 +0900 | [diff] [blame] | 125 | result = base::MakeUnique<base::Value>(value); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 126 | break; |
| 127 | } |
| 128 | case Message::UINT32: { |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 129 | uint32_t value = 0; |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 130 | if (reader->PopUint32(&value)) { |
jdoerrie | bfe825e | 2017-03-02 21:09:19 +0900 | [diff] [blame] | 131 | result = base::MakeUnique<base::Value>(static_cast<double>(value)); |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 132 | } |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 133 | break; |
| 134 | } |
| 135 | case Message::INT64: { |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 136 | int64_t value = 0; |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 137 | if (reader->PopInt64(&value)) { |
| 138 | DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) << |
| 139 | value << " is not exactly representable by double"; |
jdoerrie | bfe825e | 2017-03-02 21:09:19 +0900 | [diff] [blame] | 140 | result = base::MakeUnique<base::Value>(static_cast<double>(value)); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 141 | } |
| 142 | break; |
| 143 | } |
| 144 | case Message::UINT64: { |
avi | 0ad0ce0 | 2015-12-23 03:12:45 +0900 | [diff] [blame] | 145 | uint64_t value = 0; |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 146 | if (reader->PopUint64(&value)) { |
| 147 | DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) << |
| 148 | value << " is not exactly representable by double"; |
jdoerrie | bfe825e | 2017-03-02 21:09:19 +0900 | [diff] [blame] | 149 | result = base::MakeUnique<base::Value>(static_cast<double>(value)); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 150 | } |
| 151 | break; |
| 152 | } |
| 153 | case Message::DOUBLE: { |
| 154 | double value = 0; |
| 155 | if (reader->PopDouble(&value)) |
jdoerrie | bfe825e | 2017-03-02 21:09:19 +0900 | [diff] [blame] | 156 | result = base::MakeUnique<base::Value>(value); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 157 | break; |
| 158 | } |
| 159 | case Message::STRING: { |
| 160 | std::string value; |
| 161 | if (reader->PopString(&value)) |
jdoerrie | 0d1295b | 2017-03-06 20:12:04 +0900 | [diff] [blame] | 162 | result = base::MakeUnique<base::Value>(value); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 163 | break; |
| 164 | } |
| 165 | case Message::OBJECT_PATH: { |
| 166 | ObjectPath value; |
| 167 | if (reader->PopObjectPath(&value)) |
jdoerrie | 0d1295b | 2017-03-06 20:12:04 +0900 | [diff] [blame] | 168 | result = base::MakeUnique<base::Value>(value.value()); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 169 | break; |
| 170 | } |
sleffler@chromium.org | 22fab40 | 2012-03-30 15:46:20 +0900 | [diff] [blame] | 171 | case Message::UNIX_FD: { |
| 172 | // Cannot distinguish a file descriptor from an int |
| 173 | NOTREACHED(); |
| 174 | break; |
| 175 | } |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 176 | case Message::ARRAY: { |
| 177 | MessageReader sub_reader(NULL); |
| 178 | if (reader->PopArray(&sub_reader)) { |
| 179 | // If the type of the array's element is DICT_ENTRY, create a |
| 180 | // DictionaryValue, otherwise create a ListValue. |
| 181 | if (sub_reader.GetDataType() == Message::DICT_ENTRY) { |
dcheng | 30c5a17 | 2016-04-09 07:55:04 +0900 | [diff] [blame] | 182 | std::unique_ptr<base::DictionaryValue> dictionary_value( |
thestig@chromium.org | e1acdf8 | 2013-02-13 05:06:15 +0900 | [diff] [blame] | 183 | new base::DictionaryValue); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 184 | if (PopDictionaryEntries(&sub_reader, dictionary_value.get())) |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 185 | result = std::move(dictionary_value); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 186 | } else { |
dcheng | 30c5a17 | 2016-04-09 07:55:04 +0900 | [diff] [blame] | 187 | std::unique_ptr<base::ListValue> list_value(new base::ListValue); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 188 | if (PopListElements(&sub_reader, list_value.get())) |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 189 | result = std::move(list_value); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | break; |
| 193 | } |
| 194 | case Message::STRUCT: { |
| 195 | MessageReader sub_reader(NULL); |
| 196 | if (reader->PopStruct(&sub_reader)) { |
dcheng | 30c5a17 | 2016-04-09 07:55:04 +0900 | [diff] [blame] | 197 | std::unique_ptr<base::ListValue> list_value(new base::ListValue); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 198 | if (PopListElements(&sub_reader, list_value.get())) |
dcheng | 6ad83f3 | 2016-05-30 15:33:58 +0900 | [diff] [blame] | 199 | result = std::move(list_value); |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 200 | } |
| 201 | break; |
| 202 | } |
| 203 | case Message::DICT_ENTRY: |
| 204 | // DICT_ENTRY must be popped as an element of an array. |
| 205 | NOTREACHED(); |
| 206 | break; |
| 207 | case Message::VARIANT: { |
| 208 | MessageReader sub_reader(NULL); |
| 209 | if (reader->PopVariant(&sub_reader)) |
| 210 | result = PopDataAsValue(&sub_reader); |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | return result; |
| 215 | } |
| 216 | |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 217 | void AppendBasicTypeValueData(MessageWriter* writer, const base::Value& value) { |
| 218 | switch (value.GetType()) { |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 219 | case base::Value::Type::BOOLEAN: { |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 220 | bool bool_value = false; |
khorimoto@chromium.org | 3a56779 | 2012-03-29 04:00:06 +0900 | [diff] [blame] | 221 | bool success = value.GetAsBoolean(&bool_value); |
| 222 | DCHECK(success); |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 223 | writer->AppendBool(bool_value); |
| 224 | break; |
| 225 | } |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 226 | case base::Value::Type::INTEGER: { |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 227 | int int_value = 0; |
khorimoto@chromium.org | 3a56779 | 2012-03-29 04:00:06 +0900 | [diff] [blame] | 228 | bool success = value.GetAsInteger(&int_value); |
| 229 | DCHECK(success); |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 230 | writer->AppendInt32(int_value); |
| 231 | break; |
| 232 | } |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 233 | case base::Value::Type::DOUBLE: { |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 234 | double double_value = 0; |
khorimoto@chromium.org | 3a56779 | 2012-03-29 04:00:06 +0900 | [diff] [blame] | 235 | bool success = value.GetAsDouble(&double_value); |
| 236 | DCHECK(success); |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 237 | writer->AppendDouble(double_value); |
| 238 | break; |
| 239 | } |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 240 | case base::Value::Type::STRING: { |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 241 | std::string string_value; |
khorimoto@chromium.org | 3a56779 | 2012-03-29 04:00:06 +0900 | [diff] [blame] | 242 | bool success = value.GetAsString(&string_value); |
| 243 | DCHECK(success); |
hashimoto@chromium.org | ea59982 | 2012-03-25 05:37:18 +0900 | [diff] [blame] | 244 | writer->AppendString(string_value); |
| 245 | break; |
| 246 | } |
| 247 | default: |
| 248 | DLOG(ERROR) << "Unexpected type " << value.GetType(); |
| 249 | break; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | void AppendBasicTypeValueDataAsVariant(MessageWriter* writer, |
| 254 | const base::Value& value) { |
| 255 | MessageWriter sub_writer(NULL); |
| 256 | writer->OpenVariant(GetTypeSignature(value), &sub_writer); |
| 257 | AppendBasicTypeValueData(&sub_writer, value); |
| 258 | writer->CloseContainer(&sub_writer); |
| 259 | } |
| 260 | |
armansito@chromium.org | 39d51b9 | 2014-05-22 20:52:55 +0900 | [diff] [blame] | 261 | void AppendValueData(MessageWriter* writer, const base::Value& value) { |
| 262 | switch (value.GetType()) { |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 263 | case base::Value::Type::DICTIONARY: { |
armansito@chromium.org | 39d51b9 | 2014-05-22 20:52:55 +0900 | [diff] [blame] | 264 | const base::DictionaryValue* dictionary = NULL; |
| 265 | value.GetAsDictionary(&dictionary); |
| 266 | dbus::MessageWriter array_writer(NULL); |
| 267 | writer->OpenArray("{sv}", &array_writer); |
| 268 | for (base::DictionaryValue::Iterator iter(*dictionary); |
| 269 | !iter.IsAtEnd(); iter.Advance()) { |
| 270 | dbus::MessageWriter dict_entry_writer(NULL); |
| 271 | array_writer.OpenDictEntry(&dict_entry_writer); |
| 272 | dict_entry_writer.AppendString(iter.key()); |
| 273 | AppendValueDataAsVariant(&dict_entry_writer, iter.value()); |
| 274 | array_writer.CloseContainer(&dict_entry_writer); |
| 275 | } |
| 276 | writer->CloseContainer(&array_writer); |
| 277 | break; |
| 278 | } |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 279 | case base::Value::Type::LIST: { |
armansito@chromium.org | 39d51b9 | 2014-05-22 20:52:55 +0900 | [diff] [blame] | 280 | const base::ListValue* list = NULL; |
| 281 | value.GetAsList(&list); |
| 282 | dbus::MessageWriter array_writer(NULL); |
| 283 | writer->OpenArray("v", &array_writer); |
dcheng | 1fa44fb | 2016-05-26 03:30:47 +0900 | [diff] [blame] | 284 | for (const auto& value : *list) { |
jdoerrie | 0143ef0 | 2017-04-11 23:20:20 +0900 | [diff] [blame^] | 285 | AppendValueDataAsVariant(&array_writer, value); |
armansito@chromium.org | 39d51b9 | 2014-05-22 20:52:55 +0900 | [diff] [blame] | 286 | } |
| 287 | writer->CloseContainer(&array_writer); |
| 288 | break; |
| 289 | } |
jdoerrie | 89ee31a | 2016-12-08 00:43:28 +0900 | [diff] [blame] | 290 | case base::Value::Type::BOOLEAN: |
| 291 | case base::Value::Type::INTEGER: |
| 292 | case base::Value::Type::DOUBLE: |
| 293 | case base::Value::Type::STRING: |
armansito@chromium.org | 39d51b9 | 2014-05-22 20:52:55 +0900 | [diff] [blame] | 294 | AppendBasicTypeValueData(writer, value); |
| 295 | break; |
| 296 | default: |
| 297 | DLOG(ERROR) << "Unexpected type: " << value.GetType(); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | void AppendValueDataAsVariant(MessageWriter* writer, const base::Value& value) { |
| 302 | MessageWriter variant_writer(NULL); |
| 303 | writer->OpenVariant(GetTypeSignature(value), &variant_writer); |
| 304 | AppendValueData(&variant_writer, value); |
| 305 | writer->CloseContainer(&variant_writer); |
| 306 | } |
| 307 | |
hashimoto@chromium.org | 8fb5a2b | 2012-03-17 08:08:42 +0900 | [diff] [blame] | 308 | } // namespace dbus |