| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/usb/mojo/type_converters.h" | 5 #include "device/usb/mojo/type_converters.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 Convert(const device::UsbConfigDescriptor& config) { | 205 Convert(const device::UsbConfigDescriptor& config) { |
| 206 device::usb::ConfigurationInfoPtr info = | 206 device::usb::ConfigurationInfoPtr info = |
| 207 device::usb::ConfigurationInfo::New(); | 207 device::usb::ConfigurationInfo::New(); |
| 208 info->configuration_value = config.configuration_value; | 208 info->configuration_value = config.configuration_value; |
| 209 info->interfaces = | 209 info->interfaces = |
| 210 mojo::Array<device::usb::InterfaceInfoPtr>::From(config.interfaces); | 210 mojo::Array<device::usb::InterfaceInfoPtr>::From(config.interfaces); |
| 211 return info; | 211 return info; |
| 212 } | 212 } |
| 213 | 213 |
| 214 // static | 214 // static |
| 215 device::usb::WebUsbFunctionSubsetPtr TypeConverter< | |
| 216 device::usb::WebUsbFunctionSubsetPtr, | |
| 217 device::WebUsbFunctionSubset>::Convert(const device::WebUsbFunctionSubset& | |
| 218 function) { | |
| 219 device::usb::WebUsbFunctionSubsetPtr info = | |
| 220 device::usb::WebUsbFunctionSubset::New(); | |
| 221 info->first_interface = function.first_interface; | |
| 222 info->origins = mojo::Array<mojo::String>::From(function.origins); | |
| 223 return info; | |
| 224 } | |
| 225 | |
| 226 // static | |
| 227 device::usb::WebUsbConfigurationSubsetPtr | |
| 228 TypeConverter<device::usb::WebUsbConfigurationSubsetPtr, | |
| 229 device::WebUsbConfigurationSubset>:: | |
| 230 Convert(const device::WebUsbConfigurationSubset& config) { | |
| 231 device::usb::WebUsbConfigurationSubsetPtr info = | |
| 232 device::usb::WebUsbConfigurationSubset::New(); | |
| 233 info->configuration_value = config.configuration_value; | |
| 234 info->origins = mojo::Array<mojo::String>::From(config.origins); | |
| 235 info->functions = | |
| 236 mojo::Array<device::usb::WebUsbFunctionSubsetPtr>::From(config.functions); | |
| 237 return info; | |
| 238 } | |
| 239 | |
| 240 // static | |
| 241 device::usb::WebUsbDescriptorSetPtr TypeConverter< | |
| 242 device::usb::WebUsbDescriptorSetPtr, | |
| 243 device::WebUsbAllowedOrigins>::Convert(const device::WebUsbAllowedOrigins& | |
| 244 allowed_origins) { | |
| 245 device::usb::WebUsbDescriptorSetPtr info = | |
| 246 device::usb::WebUsbDescriptorSet::New(); | |
| 247 info->origins = mojo::Array<mojo::String>::From(allowed_origins.origins); | |
| 248 info->configurations = | |
| 249 mojo::Array<device::usb::WebUsbConfigurationSubsetPtr>::From( | |
| 250 allowed_origins.configurations); | |
| 251 return info; | |
| 252 } | |
| 253 | |
| 254 // static | |
| 255 device::usb::DeviceInfoPtr | 215 device::usb::DeviceInfoPtr |
| 256 TypeConverter<device::usb::DeviceInfoPtr, device::UsbDevice>::Convert( | 216 TypeConverter<device::usb::DeviceInfoPtr, device::UsbDevice>::Convert( |
| 257 const device::UsbDevice& device) { | 217 const device::UsbDevice& device) { |
| 258 device::usb::DeviceInfoPtr info = device::usb::DeviceInfo::New(); | 218 device::usb::DeviceInfoPtr info = device::usb::DeviceInfo::New(); |
| 259 info->guid = device.guid(); | 219 info->guid = device.guid(); |
| 260 info->vendor_id = device.vendor_id(); | 220 info->vendor_id = device.vendor_id(); |
| 261 info->product_id = device.product_id(); | 221 info->product_id = device.product_id(); |
| 262 info->manufacturer_name = base::UTF16ToUTF8(device.manufacturer_string()); | 222 info->manufacturer_name = base::UTF16ToUTF8(device.manufacturer_string()); |
| 263 info->product_name = base::UTF16ToUTF8(device.product_string()); | 223 info->product_name = base::UTF16ToUTF8(device.product_string()); |
| 264 info->serial_number = base::UTF16ToUTF8(device.serial_number()); | 224 info->serial_number = base::UTF16ToUTF8(device.serial_number()); |
| 265 const device::UsbConfigDescriptor* config = device.GetActiveConfiguration(); | 225 const device::UsbConfigDescriptor* config = device.GetActiveConfiguration(); |
| 266 info->active_configuration = config ? config->configuration_value : 0; | 226 info->active_configuration = config ? config->configuration_value : 0; |
| 267 info->configurations = mojo::Array<device::usb::ConfigurationInfoPtr>::From( | 227 info->configurations = mojo::Array<device::usb::ConfigurationInfoPtr>::From( |
| 268 device.configurations()); | 228 device.configurations()); |
| 269 if (device.webusb_allowed_origins()) { | |
| 270 info->webusb_allowed_origins = device::usb::WebUsbDescriptorSet::From( | |
| 271 *device.webusb_allowed_origins()); | |
| 272 } | |
| 273 return info; | 229 return info; |
| 274 } | 230 } |
| 275 | 231 |
| 276 // static | 232 // static |
| 277 device::usb::IsochronousPacketPtr | 233 device::usb::IsochronousPacketPtr |
| 278 TypeConverter<device::usb::IsochronousPacketPtr, | 234 TypeConverter<device::usb::IsochronousPacketPtr, |
| 279 device::UsbDeviceHandle::IsochronousPacket>:: | 235 device::UsbDeviceHandle::IsochronousPacket>:: |
| 280 Convert(const device::UsbDeviceHandle::IsochronousPacket& packet) { | 236 Convert(const device::UsbDeviceHandle::IsochronousPacket& packet) { |
| 281 device::usb::IsochronousPacketPtr info = | 237 device::usb::IsochronousPacketPtr info = |
| 282 device::usb::IsochronousPacket::New(); | 238 device::usb::IsochronousPacket::New(); |
| 283 info->length = packet.length; | 239 info->length = packet.length; |
| 284 info->transferred_length = packet.transferred_length; | 240 info->transferred_length = packet.transferred_length; |
| 285 info->status = mojo::ConvertTo<device::usb::TransferStatus>(packet.status); | 241 info->status = mojo::ConvertTo<device::usb::TransferStatus>(packet.status); |
| 286 return info; | 242 return info; |
| 287 } | 243 } |
| 288 | 244 |
| 289 } // namespace mojo | 245 } // namespace mojo |
| OLD | NEW |