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

Side by Side Diff: device/usb/usb_device_filter.cc

Issue 562763002: Convert device::UsbConfigDescriptor and friends to structs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add interface and endpoint descriptor iterator typedefs. Created 6 years, 3 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 | « device/usb/usb_device.h ('k') | device/usb/usb_device_filter_unittest.cc » ('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 2014 The Chromium Authors. All rights reserved. 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 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 "device/usb/usb_device_filter.h" 5 #include "device/usb/usb_device_filter.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "device/usb/usb_descriptors.h"
8 #include "device/usb/usb_device.h" 9 #include "device/usb/usb_device.h"
9 #include "device/usb/usb_interface.h"
10 10
11 namespace device { 11 namespace device {
12 12
13 namespace { 13 namespace {
14 14
15 const char kProductIdKey[] = "productId"; 15 const char kProductIdKey[] = "productId";
16 const char kVendorIdKey[] = "vendorId"; 16 const char kVendorIdKey[] = "vendorId";
17 const char kInterfaceClassKey[] = "interfaceClass"; 17 const char kInterfaceClassKey[] = "interfaceClass";
18 const char kInterfaceSubclassKey[] = "interfaceSubclass"; 18 const char kInterfaceSubclassKey[] = "interfaceSubclass";
19 const char kInterfaceProtocolKey[] = "interfaceProtocol"; 19 const char kInterfaceProtocolKey[] = "interfaceProtocol";
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return false; 62 return false;
63 } 63 }
64 64
65 if (product_id_set_ && device->product_id() != product_id_) { 65 if (product_id_set_ && device->product_id() != product_id_) {
66 return false; 66 return false;
67 } 67 }
68 } 68 }
69 69
70 if (interface_class_set_) { 70 if (interface_class_set_) {
71 bool foundMatch = false; 71 bool foundMatch = false;
72 scoped_refptr<const UsbConfigDescriptor> config = device->ListInterfaces(); 72 const UsbConfigDescriptor& config = device->GetConfiguration();
73 73
74 // TODO(reillyg): Check device configuration if the class is not defined at 74 // TODO(reillyg): Check device configuration if the class is not defined at
75 // a per-interface level. This is not really important because most devices 75 // a per-interface level. This is not really important because most devices
76 // have per-interface classes. The only counter-examples I know of are hubs. 76 // have per-interface classes. The only counter-examples I know of are hubs.
77 77
78 for (size_t i = 0; i < config->GetNumInterfaces() && !foundMatch; ++i) { 78 for (UsbInterfaceDescriptor::Iterator ifaceIt = config.interfaces.begin();
79 scoped_refptr<const UsbInterfaceDescriptor> iface = 79 ifaceIt != config.interfaces.end() && !foundMatch;
80 config->GetInterface(i); 80 ++ifaceIt) {
81 81 if (ifaceIt->interface_class == interface_class_ &&
82 for (size_t j = 0; j < iface->GetNumAltSettings() && !foundMatch; ++j) { 82 (!interface_subclass_set_ ||
83 scoped_refptr<const UsbInterfaceAltSettingDescriptor> altSetting = 83 (ifaceIt->interface_subclass == interface_subclass_ &&
84 iface->GetAltSetting(j); 84 (!interface_protocol_set_ ||
85 85 ifaceIt->interface_protocol == interface_protocol_)))) {
86 if (altSetting->GetInterfaceClass() == interface_class_ && 86 foundMatch = true;
87 (!interface_subclass_set_ ||
88 (altSetting->GetInterfaceSubclass() == interface_subclass_ &&
89 (!interface_protocol_set_ ||
90 altSetting->GetInterfaceProtocol() == interface_protocol_)))) {
91 foundMatch = true;
92 }
93 } 87 }
94 } 88 }
95 89
96 if (!foundMatch) { 90 if (!foundMatch) {
97 return false; 91 return false;
98 } 92 }
99 } 93 }
100 94
101 return true; 95 return true;
102 } 96 }
(...skipping 28 matching lines...) Expand all
131 i != filters.end(); 125 i != filters.end();
132 ++i) { 126 ++i) {
133 if (i->Matches(device)) { 127 if (i->Matches(device)) {
134 return true; 128 return true;
135 } 129 }
136 } 130 }
137 return false; 131 return false;
138 } 132 }
139 133
140 } // namespace device 134 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_device.h ('k') | device/usb/usb_device_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698