Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2169)

Unified Diff: device/usb/mojo/type_converters.cc

Issue 2234443002: Mojo C++ binding: make device/usb mojom targets use STD string/vector types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move the vector converter into a private header. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/usb/mojo/type_converters.cc
diff --git a/device/usb/mojo/type_converters.cc b/device/usb/mojo/type_converters.cc
index af0ec22257eeb9e1313acdb47c31e82c50346a25..38c43f2bc9e35eb2d9e76db0d5fc67125fe4bbbc 100644
--- a/device/usb/mojo/type_converters.cc
+++ b/device/usb/mojo/type_converters.cc
@@ -13,6 +13,7 @@
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "device/usb/usb_device.h"
+#include "mojo/common/common_type_converters.h"
#include "mojo/public/cpp/bindings/array.h"
namespace mojo {
@@ -158,7 +159,7 @@ TypeConverter<device::usb::AlternateInterfaceInfoPtr,
info->protocol_code = interface.interface_protocol;
// Filter out control endpoints for the public interface.
- info->endpoints = mojo::Array<device::usb::EndpointInfoPtr>::New(0);
+ info->endpoints.reserve(interface.endpoints.size());
for (const auto& endpoint : interface.endpoints) {
if (endpoint.transfer_type != device::USB_TRANSFER_CONTROL)
info->endpoints.push_back(device::usb::EndpointInfo::From(endpoint));
@@ -168,11 +169,11 @@ TypeConverter<device::usb::AlternateInterfaceInfoPtr,
}
// static
-mojo::Array<device::usb::InterfaceInfoPtr>
-TypeConverter<mojo::Array<device::usb::InterfaceInfoPtr>,
+std::vector<device::usb::InterfaceInfoPtr>
+TypeConverter<std::vector<device::usb::InterfaceInfoPtr>,
std::vector<device::UsbInterfaceDescriptor>>::
Convert(const std::vector<device::UsbInterfaceDescriptor>& interfaces) {
- auto infos = mojo::Array<device::usb::InterfaceInfoPtr>::New(0);
+ std::vector<device::usb::InterfaceInfoPtr> infos;
// Aggregate each alternate setting into an InterfaceInfo corresponding to its
// interface number.
@@ -205,7 +206,8 @@ TypeConverter<device::usb::ConfigurationInfoPtr, device::UsbConfigDescriptor>::
device::usb::ConfigurationInfo::New();
info->configuration_value = config.configuration_value;
info->interfaces =
- mojo::Array<device::usb::InterfaceInfoPtr>::From(config.interfaces);
+ mojo::ConvertTo<std::vector<device::usb::InterfaceInfoPtr>>(
+ config.interfaces);
return info;
}
@@ -231,8 +233,9 @@ TypeConverter<device::usb::DeviceInfoPtr, device::UsbDevice>::Convert(
info->serial_number = base::UTF16ToUTF8(device.serial_number());
const device::UsbConfigDescriptor* config = device.active_configuration();
info->active_configuration = config ? config->configuration_value : 0;
- info->configurations = mojo::Array<device::usb::ConfigurationInfoPtr>::From(
- device.configurations());
+ info->configurations =
+ mojo::ConvertTo<std::vector<device::usb::ConfigurationInfoPtr>>(
+ device.configurations());
return info;
}

Powered by Google App Engine
This is Rietveld 408576698