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

Side by Side Diff: device/usb/mojo/type_converters.cc

Issue 1854483002: Remove WebUSB descriptor data from device.mojom. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@use_interface_associations
Patch Set: Rebased. Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « device/usb/mojo/type_converters.h ('k') | device/usb/public/interfaces/device.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // interface number. 179 // interface number.
180 std::map<uint8_t, device::usb::InterfaceInfo*> interface_map; 180 std::map<uint8_t, device::usb::InterfaceInfo*> interface_map;
181 for (size_t i = 0; i < interfaces.size(); ++i) { 181 for (size_t i = 0; i < interfaces.size(); ++i) {
182 auto alternate = device::usb::AlternateInterfaceInfo::From(interfaces[i]); 182 auto alternate = device::usb::AlternateInterfaceInfo::From(interfaces[i]);
183 auto iter = interface_map.find(interfaces[i].interface_number); 183 auto iter = interface_map.find(interfaces[i].interface_number);
184 if (iter == interface_map.end()) { 184 if (iter == interface_map.end()) {
185 // This is the first time we're seeing an alternate with this interface 185 // This is the first time we're seeing an alternate with this interface
186 // number, so add a new InterfaceInfo to the array and map the number. 186 // number, so add a new InterfaceInfo to the array and map the number.
187 auto info = device::usb::InterfaceInfo::New(); 187 auto info = device::usb::InterfaceInfo::New();
188 info->interface_number = interfaces[i].interface_number; 188 info->interface_number = interfaces[i].interface_number;
189 info->first_interface = interfaces[i].first_interface;
190 iter = interface_map 189 iter = interface_map
191 .insert( 190 .insert(
192 std::make_pair(interfaces[i].interface_number, info.get())) 191 std::make_pair(interfaces[i].interface_number, info.get()))
193 .first; 192 .first;
194 infos.push_back(std::move(info)); 193 infos.push_back(std::move(info));
195 } 194 }
196 iter->second->alternates.push_back(std::move(alternate)); 195 iter->second->alternates.push_back(std::move(alternate));
197 } 196 }
198 197
199 return infos; 198 return infos;
200 } 199 }
201 200
202 // static 201 // static
203 device::usb::ConfigurationInfoPtr 202 device::usb::ConfigurationInfoPtr
204 TypeConverter<device::usb::ConfigurationInfoPtr, device::UsbConfigDescriptor>:: 203 TypeConverter<device::usb::ConfigurationInfoPtr, device::UsbConfigDescriptor>::
205 Convert(const device::UsbConfigDescriptor& config) { 204 Convert(const device::UsbConfigDescriptor& config) {
206 device::usb::ConfigurationInfoPtr info = 205 device::usb::ConfigurationInfoPtr info =
207 device::usb::ConfigurationInfo::New(); 206 device::usb::ConfigurationInfo::New();
208 info->configuration_value = config.configuration_value; 207 info->configuration_value = config.configuration_value;
209 info->interfaces = 208 info->interfaces =
210 mojo::Array<device::usb::InterfaceInfoPtr>::From(config.interfaces); 209 mojo::Array<device::usb::InterfaceInfoPtr>::From(config.interfaces);
211 return info; 210 return info;
212 } 211 }
213 212
214 // static 213 // 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 214 device::usb::DeviceInfoPtr
256 TypeConverter<device::usb::DeviceInfoPtr, device::UsbDevice>::Convert( 215 TypeConverter<device::usb::DeviceInfoPtr, device::UsbDevice>::Convert(
257 const device::UsbDevice& device) { 216 const device::UsbDevice& device) {
258 device::usb::DeviceInfoPtr info = device::usb::DeviceInfo::New(); 217 device::usb::DeviceInfoPtr info = device::usb::DeviceInfo::New();
259 info->guid = device.guid(); 218 info->guid = device.guid();
260 info->usb_version_major = device.usb_version() >> 8; 219 info->usb_version_major = device.usb_version() >> 8;
261 info->usb_version_minor = device.usb_version() >> 4 & 0xf; 220 info->usb_version_minor = device.usb_version() >> 4 & 0xf;
262 info->usb_version_subminor = device.usb_version() & 0xf; 221 info->usb_version_subminor = device.usb_version() & 0xf;
263 info->class_code = device.device_class(); 222 info->class_code = device.device_class();
264 info->subclass_code = device.device_subclass(); 223 info->subclass_code = device.device_subclass();
265 info->protocol_code = device.device_protocol(); 224 info->protocol_code = device.device_protocol();
266 info->vendor_id = device.vendor_id(); 225 info->vendor_id = device.vendor_id();
267 info->product_id = device.product_id(); 226 info->product_id = device.product_id();
268 info->device_version_major = device.device_version() >> 8; 227 info->device_version_major = device.device_version() >> 8;
269 info->device_version_minor = device.device_version() >> 4 & 0xf; 228 info->device_version_minor = device.device_version() >> 4 & 0xf;
270 info->device_version_subminor = device.device_version() & 0xf; 229 info->device_version_subminor = device.device_version() & 0xf;
271 info->manufacturer_name = base::UTF16ToUTF8(device.manufacturer_string()); 230 info->manufacturer_name = base::UTF16ToUTF8(device.manufacturer_string());
272 info->product_name = base::UTF16ToUTF8(device.product_string()); 231 info->product_name = base::UTF16ToUTF8(device.product_string());
273 info->serial_number = base::UTF16ToUTF8(device.serial_number()); 232 info->serial_number = base::UTF16ToUTF8(device.serial_number());
274 const device::UsbConfigDescriptor* config = device.GetActiveConfiguration(); 233 const device::UsbConfigDescriptor* config = device.GetActiveConfiguration();
275 info->active_configuration = config ? config->configuration_value : 0; 234 info->active_configuration = config ? config->configuration_value : 0;
276 info->configurations = mojo::Array<device::usb::ConfigurationInfoPtr>::From( 235 info->configurations = mojo::Array<device::usb::ConfigurationInfoPtr>::From(
277 device.configurations()); 236 device.configurations());
278 if (device.webusb_allowed_origins()) {
279 info->webusb_allowed_origins = device::usb::WebUsbDescriptorSet::From(
280 *device.webusb_allowed_origins());
281 }
282 return info; 237 return info;
283 } 238 }
284 239
285 // static 240 // static
286 device::usb::IsochronousPacketPtr 241 device::usb::IsochronousPacketPtr
287 TypeConverter<device::usb::IsochronousPacketPtr, 242 TypeConverter<device::usb::IsochronousPacketPtr,
288 device::UsbDeviceHandle::IsochronousPacket>:: 243 device::UsbDeviceHandle::IsochronousPacket>::
289 Convert(const device::UsbDeviceHandle::IsochronousPacket& packet) { 244 Convert(const device::UsbDeviceHandle::IsochronousPacket& packet) {
290 device::usb::IsochronousPacketPtr info = 245 device::usb::IsochronousPacketPtr info =
291 device::usb::IsochronousPacket::New(); 246 device::usb::IsochronousPacket::New();
292 info->length = packet.length; 247 info->length = packet.length;
293 info->transferred_length = packet.transferred_length; 248 info->transferred_length = packet.transferred_length;
294 info->status = mojo::ConvertTo<device::usb::TransferStatus>(packet.status); 249 info->status = mojo::ConvertTo<device::usb::TransferStatus>(packet.status);
295 return info; 250 return info;
296 } 251 }
297 252
298 } // namespace mojo 253 } // namespace mojo
OLDNEW
« no previous file with comments | « device/usb/mojo/type_converters.h ('k') | device/usb/public/interfaces/device.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698