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

Side by Side Diff: third_party/WebKit/Source/modules/webusb/USBInterface.cpp

Issue 1850023002: Consume Mojo services directly in Blink's WebUSB implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't do assignments in if statements. 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
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 "modules/webusb/USBInterface.h" 5 #include "modules/webusb/USBInterface.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-wtf.h"
8 #include "modules/webusb/USBAlternateInterface.h" 9 #include "modules/webusb/USBAlternateInterface.h"
9 #include "modules/webusb/USBConfiguration.h" 10 #include "modules/webusb/USBConfiguration.h"
10 #include "modules/webusb/USBDevice.h" 11 #include "modules/webusb/USBDevice.h"
11 12
12 namespace blink { 13 namespace blink {
13 14
14 USBInterface* USBInterface::create(const USBConfiguration* configuration, size_t interfaceIndex) 15 USBInterface* USBInterface::create(const USBConfiguration* configuration, size_t interfaceIndex)
15 { 16 {
16 return new USBInterface(configuration->device(), configuration->index(), int erfaceIndex); 17 return new USBInterface(configuration->device(), configuration->index(), int erfaceIndex);
17 } 18 }
18 19
19 USBInterface* USBInterface::create(const USBConfiguration* configuration, size_t interfaceNumber, ExceptionState& exceptionState) 20 USBInterface* USBInterface::create(const USBConfiguration* configuration, size_t interfaceNumber, ExceptionState& exceptionState)
20 { 21 {
21 const auto& interfaces = configuration->info().interfaces; 22 const auto& interfaces = configuration->info().interfaces;
22 for (size_t i = 0; i < interfaces.size(); ++i) { 23 for (size_t i = 0; i < interfaces.size(); ++i) {
23 if (interfaces[i].interfaceNumber == interfaceNumber) 24 if (interfaces[i]->interface_number == interfaceNumber)
24 return new USBInterface(configuration->device(), configuration->inde x(), i); 25 return new USBInterface(configuration->device(), configuration->inde x(), i);
25 } 26 }
26 exceptionState.throwRangeError("Invalid interface index."); 27 exceptionState.throwRangeError("Invalid interface index.");
27 return nullptr; 28 return nullptr;
28 } 29 }
29 30
30 USBInterface::USBInterface(const USBDevice* device, size_t configurationIndex, s ize_t interfaceIndex) 31 USBInterface::USBInterface(const USBDevice* device, size_t configurationIndex, s ize_t interfaceIndex)
31 : m_device(device) 32 : m_device(device)
32 , m_configurationIndex(configurationIndex) 33 , m_configurationIndex(configurationIndex)
33 , m_interfaceIndex(interfaceIndex) 34 , m_interfaceIndex(interfaceIndex)
34 { 35 {
35 ASSERT(m_configurationIndex < m_device->info().configurations.size()); 36 ASSERT(m_configurationIndex < m_device->info().configurations.size());
36 ASSERT(m_interfaceIndex < m_device->info().configurations[m_configurationInd ex].interfaces.size()); 37 ASSERT(m_interfaceIndex < m_device->info().configurations[m_configurationInd ex]->interfaces.size());
37 } 38 }
38 39
39 const WebUSBDeviceInfo::Interface& USBInterface::info() const 40 const device::usb::wtf::InterfaceInfo& USBInterface::info() const
40 { 41 {
41 return m_device->info().configurations[m_configurationIndex].interfaces[m_in terfaceIndex]; 42 return *m_device->info().configurations[m_configurationIndex]->interfaces[m_ interfaceIndex];
42 } 43 }
43 44
44 USBAlternateInterface* USBInterface::alternate() const 45 USBAlternateInterface* USBInterface::alternate() const
45 { 46 {
46 if (m_device->isInterfaceClaimed(m_configurationIndex, m_interfaceIndex)) 47 if (m_device->isInterfaceClaimed(m_configurationIndex, m_interfaceIndex))
47 return USBAlternateInterface::create(this, m_device->selectedAlternateIn terface(m_interfaceIndex)); 48 return USBAlternateInterface::create(this, m_device->selectedAlternateIn terface(m_interfaceIndex));
48 return nullptr; 49 return nullptr;
49 } 50 }
50 51
51 HeapVector<Member<USBAlternateInterface>> USBInterface::alternates() const 52 HeapVector<Member<USBAlternateInterface>> USBInterface::alternates() const
52 { 53 {
53 HeapVector<Member<USBAlternateInterface>> alternates; 54 HeapVector<Member<USBAlternateInterface>> alternates;
54 for (size_t i = 0; i < info().alternates.size(); ++i) 55 for (size_t i = 0; i < info().alternates.size(); ++i)
55 alternates.append(USBAlternateInterface::create(this, i)); 56 alternates.append(USBAlternateInterface::create(this, i));
56 return alternates; 57 return alternates;
57 } 58 }
58 59
59 uint8_t USBInterface::interfaceNumber() const
60 {
61 return info().interfaceNumber;
62 }
63
64 bool USBInterface::claimed() const 60 bool USBInterface::claimed() const
65 { 61 {
66 return m_device->isInterfaceClaimed(m_configurationIndex, m_interfaceIndex); 62 return m_device->isInterfaceClaimed(m_configurationIndex, m_interfaceIndex);
67 } 63 }
68 64
69 DEFINE_TRACE(USBInterface) 65 DEFINE_TRACE(USBInterface)
70 { 66 {
71 visitor->trace(m_device); 67 visitor->trace(m_device);
72 } 68 }
73 69
74 } // namespace blink 70 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698