Chromium Code Reviews| Index: chromeos/dbus/bluetooth_le_advertisement_service_provider.cc |
| diff --git a/chromeos/dbus/bluetooth_le_advertisement_service_provider.cc b/chromeos/dbus/bluetooth_le_advertisement_service_provider.cc |
| index a4aca3a8b4835bc0df4e5f7203cd141f655fc925..0a9f390635c7416cae6f1da396ebfb63162cfd75 100644 |
| --- a/chromeos/dbus/bluetooth_le_advertisement_service_provider.cc |
| +++ b/chromeos/dbus/bluetooth_le_advertisement_service_provider.cc |
| @@ -258,28 +258,46 @@ class BluetoothAdvertisementServiceProviderImpl |
| response_sender.Run(response.Pass()); |
| } |
| + void AppendArrayVariantOfStrings(dbus::MessageWriter* dict_writer, |
|
armansito
2015/07/09 21:03:35
Do you mean AppendVariantArrayOfStrings?
rkc
2015/07/15 20:03:54
Done.
|
| + const UUIDList& strings) { |
| + dbus::MessageWriter strings_array_variant(nullptr); |
| + dict_writer->OpenVariant("as", &strings_array_variant); |
| + dbus::MessageWriter strings_array(nullptr); |
| + strings_array_variant.OpenArray("s", &strings_array); |
|
armansito
2015/07/09 21:03:35
You should be able to just call strings_array_vari
rkc
2015/07/15 20:03:54
Done.
|
| + |
| + for (auto& it : strings) |
| + strings_array.AppendString(it); |
| + |
| + strings_array_variant.CloseContainer(&strings_array); |
| + dict_writer->CloseContainer(&strings_array_variant); |
| + } |
| + |
| void AppendType(dbus::MessageWriter* array_writer) { |
| dbus::MessageWriter dict_entry_writer(NULL); |
| array_writer->OpenDictEntry(&dict_entry_writer); |
| dict_entry_writer.AppendString(bluetooth_advertisement::kTypeProperty); |
| if (type_ == ADVERTISEMENT_TYPE_BROADCAST) { |
| - dict_entry_writer.AppendString("broadcast"); |
| + dict_entry_writer.AppendVariantOfString("broadcast"); |
| } else { |
| - dict_entry_writer.AppendString("peripheral"); |
| + dict_entry_writer.AppendVariantOfString("peripheral"); |
| } |
| array_writer->CloseContainer(&dict_entry_writer); |
| } |
| void AppendServiceUUIDs(dbus::MessageWriter* array_writer) { |
| + if (!service_uuids_) |
| + return; |
| dbus::MessageWriter dict_entry_writer(NULL); |
| array_writer->OpenDictEntry(&dict_entry_writer); |
| dict_entry_writer.AppendString( |
| bluetooth_advertisement::kServiceUUIDsProperty); |
| - dict_entry_writer.AppendArrayOfStrings(*service_uuids_); |
| + AppendArrayVariantOfStrings(&dict_entry_writer, *service_uuids_); |
| array_writer->CloseContainer(&dict_entry_writer); |
| } |
| void AppendManufacturerData(dbus::MessageWriter* array_writer) { |
| + if (!manufacturer_data_) |
| + return; |
| dbus::MessageWriter dict_entry_writer(NULL); |
| array_writer->OpenDictEntry(&dict_entry_writer); |
| dict_entry_writer.AppendString( |
| @@ -292,15 +310,19 @@ class BluetoothAdvertisementServiceProviderImpl |
| } |
| void AppendSolicitUUIDs(dbus::MessageWriter* array_writer) { |
| + if (!solicit_uuids_) |
| + return; |
| dbus::MessageWriter dict_entry_writer(NULL); |
| array_writer->OpenDictEntry(&dict_entry_writer); |
| dict_entry_writer.AppendString( |
| bluetooth_advertisement::kSolicitUUIDsProperty); |
| - dict_entry_writer.AppendArrayOfStrings(*solicit_uuids_); |
| + AppendArrayVariantOfStrings(&dict_entry_writer, *solicit_uuids_); |
| array_writer->CloseContainer(&dict_entry_writer); |
| } |
| void AppendServiceData(dbus::MessageWriter* array_writer) { |
| + if (!service_data_) |
| + return; |
| dbus::MessageWriter dict_entry_writer(NULL); |
| array_writer->OpenDictEntry(&dict_entry_writer); |
| dict_entry_writer.AppendString( |
| @@ -313,6 +335,7 @@ class BluetoothAdvertisementServiceProviderImpl |
| } |
| void AppendManufacturerDataVariant(dbus::MessageWriter* writer) { |
| + DCHECK(manufacturer_data_); |
| dbus::MessageWriter array_writer(NULL); |
| writer->OpenArray("{qay}", &array_writer); |
| for (const auto& m : *manufacturer_data_) { |
| @@ -330,6 +353,7 @@ class BluetoothAdvertisementServiceProviderImpl |
| } |
| void AppendServiceDataVariant(dbus::MessageWriter* writer) { |
| + DCHECK(service_data_); |
| dbus::MessageWriter array_writer(NULL); |
| writer->OpenArray("{say}", &array_writer); |
| for (const auto& m : *service_data_) { |
| @@ -337,7 +361,7 @@ class BluetoothAdvertisementServiceProviderImpl |
| array_writer.OpenDictEntry(&entry_writer); |
| - entry_writer.AppendString(m.first); |
| + entry_writer.AppendVariantOfString(m.first); |
| entry_writer.AppendArrayOfBytes(vector_as_array(&m.second), |
| m.second.size()); |