| 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 "modules/webusb/USBConfiguration.h" | 5 #include "modules/webusb/USBConfiguration.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "device/usb/public/interfaces/device.mojom-blink.h" | 8 #include "device/usb/public/interfaces/device.mojom-blink.h" |
| 9 #include "modules/webusb/USBDevice.h" | 9 #include "modules/webusb/USBDevice.h" |
| 10 #include "modules/webusb/USBInterface.h" | 10 #include "modules/webusb/USBInterface.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 return new USBConfiguration(device, i); | 25 return new USBConfiguration(device, i); |
| 26 } | 26 } |
| 27 exception_state.ThrowRangeError("Invalid configuration value."); | 27 exception_state.ThrowRangeError("Invalid configuration value."); |
| 28 return nullptr; | 28 return nullptr; |
| 29 } | 29 } |
| 30 | 30 |
| 31 USBConfiguration::USBConfiguration(const USBDevice* device, | 31 USBConfiguration::USBConfiguration(const USBDevice* device, |
| 32 size_t configuration_index) | 32 size_t configuration_index) |
| 33 : device_(device), configuration_index_(configuration_index) { | 33 : device_(device), configuration_index_(configuration_index) { |
| 34 DCHECK(device_); | 34 DCHECK(device_); |
| 35 ASSERT(configuration_index_ < device_->Info().configurations.size()); | 35 DCHECK_LT(configuration_index_, device_->Info().configurations.size()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 const USBDevice* USBConfiguration::Device() const { | 38 const USBDevice* USBConfiguration::Device() const { |
| 39 return device_; | 39 return device_; |
| 40 } | 40 } |
| 41 | 41 |
| 42 size_t USBConfiguration::Index() const { | 42 size_t USBConfiguration::Index() const { |
| 43 return configuration_index_; | 43 return configuration_index_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 const device::mojom::blink::UsbConfigurationInfo& USBConfiguration::Info() | 46 const device::mojom::blink::UsbConfigurationInfo& USBConfiguration::Info() |
| 47 const { | 47 const { |
| 48 return *device_->Info().configurations[configuration_index_]; | 48 return *device_->Info().configurations[configuration_index_]; |
| 49 } | 49 } |
| 50 | 50 |
| 51 HeapVector<Member<USBInterface>> USBConfiguration::interfaces() const { | 51 HeapVector<Member<USBInterface>> USBConfiguration::interfaces() const { |
| 52 HeapVector<Member<USBInterface>> interfaces; | 52 HeapVector<Member<USBInterface>> interfaces; |
| 53 for (size_t i = 0; i < Info().interfaces.size(); ++i) | 53 for (size_t i = 0; i < Info().interfaces.size(); ++i) |
| 54 interfaces.push_back(USBInterface::Create(this, i)); | 54 interfaces.push_back(USBInterface::Create(this, i)); |
| 55 return interfaces; | 55 return interfaces; |
| 56 } | 56 } |
| 57 | 57 |
| 58 DEFINE_TRACE(USBConfiguration) { | 58 DEFINE_TRACE(USBConfiguration) { |
| 59 visitor->Trace(device_); | 59 visitor->Trace(device_); |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace blink | 62 } // namespace blink |
| OLD | NEW |