Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / device / usb / usb_descriptors.cc
blobc783b70106609ee1d1b120a376213396803d50fd
1 // Copyright 2014 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.
5 #include "device/usb/usb_descriptors.h"
7 #include <algorithm>
9 namespace device {
11 namespace {
12 const uint8_t kStringDescriptorType = 0x03;
15 UsbEndpointDescriptor::UsbEndpointDescriptor()
16 : address(0),
17 direction(USB_DIRECTION_INBOUND),
18 maximum_packet_size(0),
19 synchronization_type(USB_SYNCHRONIZATION_NONE),
20 transfer_type(USB_TRANSFER_CONTROL),
21 usage_type(USB_USAGE_DATA),
22 polling_interval(0) {
25 UsbEndpointDescriptor::~UsbEndpointDescriptor() {
28 UsbInterfaceDescriptor::UsbInterfaceDescriptor()
29 : interface_number(0),
30 alternate_setting(0),
31 interface_class(0),
32 interface_subclass(0),
33 interface_protocol(0) {
36 UsbInterfaceDescriptor::~UsbInterfaceDescriptor() {
39 UsbConfigDescriptor::UsbConfigDescriptor()
40 : configuration_value(0),
41 self_powered(false),
42 remote_wakeup(false),
43 maximum_power(0) {
46 UsbConfigDescriptor::~UsbConfigDescriptor() {
49 bool ParseUsbStringDescriptor(const std::vector<uint8_t>& descriptor,
50 base::string16* output) {
51 if (descriptor.size() < 2 || descriptor[1] != kStringDescriptorType) {
52 return false;
54 // Let the device return a buffer larger than the actual string but prefer the
55 // length reported inside the descriptor.
56 size_t length = descriptor[0];
57 length = std::min(length, descriptor.size());
58 if (length < 2) {
59 return false;
60 } else if (length == 2) {
61 // Special case to avoid indexing beyond the end of |descriptor|.
62 *output = base::string16();
63 } else {
64 *output = base::string16(
65 reinterpret_cast<const base::char16*>(&descriptor[2]), length / 2 - 1);
67 return true;
70 } // namespace device