Chromium Code Reviews

Side by Side Diff: Source/modules/webusb/USBConfiguration.cpp

Issue 1352283005: Add getConfiguration method to USBDevice. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update webexposed/global-interface-listing-expected.txt. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « Source/modules/webusb/USBConfiguration.h ('k') | Source/modules/webusb/USBDevice.h » ('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 "config.h" 5 #include "config.h"
6 #include "modules/webusb/USBConfiguration.h" 6 #include "modules/webusb/USBConfiguration.h"
7 7
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.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"
11 11
12 namespace blink { 12 namespace blink {
13 13
14 USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t confi gurationIndex) 14 USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t confi gurationIndex)
15 { 15 {
16 return new USBConfiguration(device, configurationIndex); 16 return new USBConfiguration(device, configurationIndex);
17 } 17 }
18 18
19 USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t confi gurationValue, ExceptionState& exceptionState) 19 USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t confi gurationValue, ExceptionState& exceptionState)
20 { 20 {
21 for (size_t i = 0; i < device->info().configurations.size(); ++i) { 21 for (size_t i = 0; i < device->info().configurations.size(); ++i) {
22 if (device->info().configurations[i].configurationValue == configuration Value) 22 if (device->info().configurations[i].configurationValue == configuration Value)
23 return new USBConfiguration(device, i); 23 return new USBConfiguration(device, i);
24 } 24 }
25 exceptionState.throwRangeError("Invalid configuration value."); 25 exceptionState.throwRangeError("Invalid configuration value.");
26 return nullptr; 26 return nullptr;
27 } 27 }
28 28
29 USBConfiguration* USBConfiguration::createFromValue(const USBDevice* device, uin t8_t configurationValue)
30 {
31 for (size_t i = 0; i < device->info().configurations.size(); ++i) {
32 if (device->info().configurations[i].configurationValue == configuration Value)
33 return new USBConfiguration(device, i);
34 }
35 return nullptr;
36 }
37
29 USBConfiguration::USBConfiguration(const USBDevice* device, size_t configuration Index) 38 USBConfiguration::USBConfiguration(const USBDevice* device, size_t configuration Index)
30 : m_device(device) 39 : m_device(device)
31 , m_configurationIndex(configurationIndex) 40 , m_configurationIndex(configurationIndex)
32 { 41 {
33 ASSERT(m_device); 42 ASSERT(m_device);
34 ASSERT(m_configurationIndex < m_device->info().configurations.size()); 43 ASSERT(m_configurationIndex < m_device->info().configurations.size());
35 } 44 }
36 45
37 const WebUSBDeviceInfo::Configuration& USBConfiguration::info() const 46 const WebUSBDeviceInfo::Configuration& USBConfiguration::info() const
38 { 47 {
(...skipping 17 matching lines...)
56 interfaces.append(USBInterface::create(this, i)); 65 interfaces.append(USBInterface::create(this, i));
57 return interfaces; 66 return interfaces;
58 } 67 }
59 68
60 DEFINE_TRACE(USBConfiguration) 69 DEFINE_TRACE(USBConfiguration)
61 { 70 {
62 visitor->trace(m_device); 71 visitor->trace(m_device);
63 } 72 }
64 73
65 } // namespace blink 74 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/webusb/USBConfiguration.h ('k') | Source/modules/webusb/USBDevice.h » ('j') | no next file with comments »

Powered by Google App Engine