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

Side by Side Diff: content/renderer/usb/type_converters.cc

Issue 1293253002: Connect WebUSB client interface to the devices app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix memory leak in WeakBindingSet Created 5 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 unified diff | Download patch
« no previous file with comments | « content/renderer/usb/type_converters.h ('k') | content/renderer/usb/web_usb_client_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/renderer/usb/type_converters.h"
6
7 #include "base/logging.h"
8
9 namespace mojo {
10
11 // static
12 blink::WebUSBDevice::TransferDirection
13 TypeConverter<blink::WebUSBDevice::TransferDirection,
14 device::usb::TransferDirection>::
15 Convert(const device::usb::TransferDirection& direction) {
16 switch (direction) {
17 case device::usb::TRANSFER_DIRECTION_IN:
18 return blink::WebUSBDevice::TransferDirection::In;
19 case device::usb::TRANSFER_DIRECTION_OUT:
20 return blink::WebUSBDevice::TransferDirection::Out;
21 default:
22 NOTREACHED();
23 return blink::WebUSBDevice::TransferDirection::In;
24 }
25 }
26
27 // static
28 device::usb::TransferDirection
29 TypeConverter<device::usb::TransferDirection,
30 blink::WebUSBDevice::TransferDirection>::
31 Convert(const blink::WebUSBDevice::TransferDirection& direction) {
32 switch (direction) {
33 case blink::WebUSBDevice::TransferDirection::In:
34 return device::usb::TRANSFER_DIRECTION_IN;
35 case blink::WebUSBDevice::TransferDirection::Out:
36 return device::usb::TRANSFER_DIRECTION_OUT;
37 default:
38 NOTREACHED();
39 return device::usb::TRANSFER_DIRECTION_IN;
40 }
41 }
42
43 // static
44 device::usb::ControlTransferType
45 TypeConverter<device::usb::ControlTransferType,
46 blink::WebUSBDevice::RequestType>::
47 Convert(const blink::WebUSBDevice::RequestType& direction) {
48 switch (direction) {
49 case blink::WebUSBDevice::RequestType::Standard:
50 return device::usb::CONTROL_TRANSFER_TYPE_STANDARD;
51 case blink::WebUSBDevice::RequestType::Class:
52 return device::usb::CONTROL_TRANSFER_TYPE_CLASS;
53 case blink::WebUSBDevice::RequestType::Vendor:
54 return device::usb::CONTROL_TRANSFER_TYPE_VENDOR;
55 default:
56 NOTREACHED();
57 return device::usb::CONTROL_TRANSFER_TYPE_STANDARD;
58 }
59 }
60
61 // static
62 device::usb::ControlTransferRecipient
63 TypeConverter<device::usb::ControlTransferRecipient,
64 blink::WebUSBDevice::RequestRecipient>::
65 Convert(const blink::WebUSBDevice::RequestRecipient& direction) {
66 switch (direction) {
67 case blink::WebUSBDevice::RequestRecipient::Device:
68 return device::usb::CONTROL_TRANSFER_RECIPIENT_DEVICE;
69 case blink::WebUSBDevice::RequestRecipient::Interface:
70 return device::usb::CONTROL_TRANSFER_RECIPIENT_INTERFACE;
71 case blink::WebUSBDevice::RequestRecipient::Endpoint:
72 return device::usb::CONTROL_TRANSFER_RECIPIENT_ENDPOINT;
73 case blink::WebUSBDevice::RequestRecipient::Other:
74 return device::usb::CONTROL_TRANSFER_RECIPIENT_OTHER;
75 default:
76 NOTREACHED();
77 return device::usb::CONTROL_TRANSFER_RECIPIENT_DEVICE;
78 }
79 }
80
81 // static
82 device::usb::ControlTransferParamsPtr
83 TypeConverter<device::usb::ControlTransferParamsPtr,
84 blink::WebUSBDevice::ControlTransferParameters>::
85 Convert(const blink::WebUSBDevice::ControlTransferParameters& parameters) {
86 device::usb::ControlTransferParamsPtr params =
87 device::usb::ControlTransferParams::New();
88 params->type =
89 mojo::ConvertTo<device::usb::ControlTransferType>(parameters.type);
90 params->recipient = mojo::ConvertTo<device::usb::ControlTransferRecipient>(
91 parameters.recipient);
92 params->request = parameters.request;
93 params->value = parameters.value;
94 params->index = parameters.index;
95 return params.Pass();
96 }
97
98 // static
99 blink::WebUSBDeviceInfo::Endpoint::Type TypeConverter<
100 blink::WebUSBDeviceInfo::Endpoint::Type,
101 device::usb::EndpointType>::Convert(const device::usb::EndpointType&
102 endpoint_type) {
103 switch (endpoint_type) {
104 case device::usb::ENDPOINT_TYPE_BULK:
105 return blink::WebUSBDeviceInfo::Endpoint::Type::Bulk;
106 case device::usb::ENDPOINT_TYPE_INTERRUPT:
107 return blink::WebUSBDeviceInfo::Endpoint::Type::Interrupt;
108 case device::usb::ENDPOINT_TYPE_ISOCHRONOUS:
109 return blink::WebUSBDeviceInfo::Endpoint::Type::Isochronous;
110 default:
111 NOTREACHED();
112 return blink::WebUSBDeviceInfo::Endpoint::Type::Bulk;
113 }
114 }
115
116 // static
117 blink::WebUSBDeviceInfo::Endpoint
118 TypeConverter<blink::WebUSBDeviceInfo::Endpoint, device::usb::EndpointInfoPtr>::
119 Convert(const device::usb::EndpointInfoPtr& info) {
120 blink::WebUSBDeviceInfo::Endpoint endpoint;
121 endpoint.endpointNumber = info->endpoint_number;
122 endpoint.direction =
123 mojo::ConvertTo<blink::WebUSBDevice::TransferDirection>(info->direction);
124 endpoint.type =
125 mojo::ConvertTo<blink::WebUSBDeviceInfo::Endpoint::Type>(info->type);
126 endpoint.packetSize = info->packet_size;
127 return endpoint;
128 }
129
130 // static
131 blink::WebUSBDeviceInfo::AlternateInterface
132 TypeConverter<blink::WebUSBDeviceInfo::AlternateInterface,
133 device::usb::AlternateInterfaceInfoPtr>::
134 Convert(const device::usb::AlternateInterfaceInfoPtr& info) {
135 blink::WebUSBDeviceInfo::AlternateInterface alternate;
136 alternate.alternateSetting = info->alternate_setting;
137 alternate.classCode = info->class_code;
138 alternate.subclassCode = info->subclass_code;
139 alternate.protocolCode = info->protocol_code;
140 if (!info->interface_name.is_null())
141 alternate.interfaceName = blink::WebString::fromUTF8(info->interface_name);
142 alternate.endpoints = blink::WebVector<blink::WebUSBDeviceInfo::Endpoint>(
143 info->endpoints.size());
144 for (size_t i = 0; i < info->endpoints.size(); ++i) {
145 alternate.endpoints[i] =
146 mojo::ConvertTo<blink::WebUSBDeviceInfo::Endpoint>(info->endpoints[i]);
147 }
148 return alternate;
149 }
150
151 // static
152 blink::WebUSBDeviceInfo::Interface TypeConverter<
153 blink::WebUSBDeviceInfo::Interface,
154 device::usb::InterfaceInfoPtr>::Convert(const device::usb::InterfaceInfoPtr&
155 info) {
156 blink::WebUSBDeviceInfo::Interface interface;
157 interface.interfaceNumber = info->interface_number;
158 interface.alternates =
159 blink::WebVector<blink::WebUSBDeviceInfo::AlternateInterface>(
160 info->alternates.size());
161 for (size_t i = 0; i < info->alternates.size(); ++i) {
162 interface.alternates[i] =
163 mojo::ConvertTo<blink::WebUSBDeviceInfo::AlternateInterface>(
164 info->alternates[i]);
165 }
166 return interface;
167 }
168
169 // static
170 blink::WebUSBDeviceInfo::Configuration
171 TypeConverter<blink::WebUSBDeviceInfo::Configuration,
172 device::usb::ConfigurationInfoPtr>::
173 Convert(const device::usb::ConfigurationInfoPtr& info) {
174 blink::WebUSBDeviceInfo::Configuration config;
175 config.configurationValue = info->configuration_value;
176 if (!info->configuration_name.is_null()) {
177 config.configurationName =
178 blink::WebString::fromUTF8(info->configuration_name);
179 }
180 config.interfaces = blink::WebVector<blink::WebUSBDeviceInfo::Interface>(
181 info->interfaces.size());
182 for (size_t i = 0; i < info->interfaces.size(); ++i) {
183 config.interfaces[i] = mojo::ConvertTo<blink::WebUSBDeviceInfo::Interface>(
184 info->interfaces[i]);
185 }
186 return config;
187 }
188
189 // static
190 blink::WebUSBDeviceInfo
191 TypeConverter<blink::WebUSBDeviceInfo, device::usb::DeviceInfoPtr>::Convert(
192 const device::usb::DeviceInfoPtr& info) {
193 blink::WebUSBDeviceInfo device;
194 device.guid = blink::WebString::fromUTF8(info->guid);
195 device.usbVersionMajor = info->usb_version_major;
196 device.usbVersionMinor = info->usb_version_minor;
197 device.usbVersionSubminor = info->usb_version_subminor;
198 device.deviceClass = info->class_code;
199 device.deviceSubclass = info->subclass_code;
200 device.deviceProtocol = info->protocol_code;
201 device.vendorID = info->vendor_id;
202 device.productID = info->product_id;
203 device.deviceVersionMajor = info->device_version_major;
204 device.deviceVersionMinor = info->device_version_minor;
205 device.deviceVersionSubminor = info->device_version_subminor;
206 if (!info->manufacturer_name.is_null()) {
207 device.manufacturerName =
208 blink::WebString::fromUTF8(info->manufacturer_name);
209 }
210 if (!info->product_name.is_null())
211 device.productName = blink::WebString::fromUTF8(info->product_name);
212 if (!info->serial_number.is_null())
213 device.serialNumber = blink::WebString::fromUTF8(info->serial_number);
214 device.configurations =
215 blink::WebVector<blink::WebUSBDeviceInfo::Configuration>(
216 info->configurations.size());
217 for (size_t i = 0; i < info->configurations.size(); ++i) {
218 device.configurations[i] =
219 mojo::ConvertTo<blink::WebUSBDeviceInfo::Configuration>(
220 info->configurations[i]);
221 }
222 return device;
223 }
224
225 // static
226 device::usb::DeviceFilterPtr
227 TypeConverter<device::usb::DeviceFilterPtr, blink::WebUSBDeviceFilter>::Convert(
228 const blink::WebUSBDeviceFilter& web_filter) {
229 device::usb::DeviceFilterPtr filter = device::usb::DeviceFilter::New();
230 filter->has_vendor_id = web_filter.hasVendorID;
231 filter->vendor_id = web_filter.vendorID;
232 filter->has_product_id = web_filter.hasProductID;
233 filter->product_id = web_filter.productID;
234 filter->has_class_code = web_filter.hasClassCode;
235 filter->class_code = web_filter.classCode;
236 filter->has_subclass_code = web_filter.hasSubclassCode;
237 filter->subclass_code = web_filter.subclassCode;
238 filter->has_protocol_code = web_filter.hasProtocolCode;
239 filter->protocol_code = web_filter.protocolCode;
240 return filter.Pass();
241 }
242
243 // static
244 device::usb::EnumerationOptionsPtr
245 TypeConverter<device::usb::EnumerationOptionsPtr,
246 blink::WebUSBDeviceRequestOptions>::
247 Convert(const blink::WebUSBDeviceRequestOptions& web_options) {
248 device::usb::EnumerationOptionsPtr options =
249 device::usb::EnumerationOptions::New();
250 options->filters = mojo::Array<device::usb::DeviceFilterPtr>::New(
251 web_options.filters.size());
252 for (size_t i = 0; i < web_options.filters.size(); ++i) {
253 options->filters[i] =
254 device::usb::DeviceFilter::From(web_options.filters[i]);
255 }
256 return options.Pass();
257 }
258
259 } // namespace mojo
OLDNEW
« no previous file with comments | « content/renderer/usb/type_converters.h ('k') | content/renderer/usb/web_usb_client_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698