OLD | NEW |
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_descriptors.h" |
9 #include "device/usb/usb_device.h" | 9 #include "device/usb/usb_device.h" |
10 | 10 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 if (device->vendor_id() != vendor_id_) { | 61 if (device->vendor_id() != vendor_id_) { |
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 const UsbConfigDescriptor* config = device->GetConfiguration(); |
72 const UsbConfigDescriptor& config = device->GetConfiguration(); | 72 if (!config) { |
| 73 return false; |
| 74 } |
73 | 75 |
74 // TODO(reillyg): Check device configuration if the class is not defined at | 76 // 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 | 77 // 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. | 78 // have per-interface classes. The only counter-examples I know of are hubs. |
77 | 79 |
78 for (UsbInterfaceDescriptor::Iterator ifaceIt = config.interfaces.begin(); | 80 bool foundMatch = false; |
79 ifaceIt != config.interfaces.end() && !foundMatch; | 81 for (const UsbInterfaceDescriptor& iface : config->interfaces) { |
80 ++ifaceIt) { | 82 if (iface.interface_class == interface_class_ && |
81 if (ifaceIt->interface_class == interface_class_ && | |
82 (!interface_subclass_set_ || | 83 (!interface_subclass_set_ || |
83 (ifaceIt->interface_subclass == interface_subclass_ && | 84 (iface.interface_subclass == interface_subclass_ && |
84 (!interface_protocol_set_ || | 85 (!interface_protocol_set_ || |
85 ifaceIt->interface_protocol == interface_protocol_)))) { | 86 iface.interface_protocol == interface_protocol_)))) { |
86 foundMatch = true; | 87 foundMatch = true; |
87 } | 88 } |
88 } | 89 } |
89 | 90 |
90 if (!foundMatch) { | 91 if (!foundMatch) { |
91 return false; | 92 return false; |
92 } | 93 } |
93 } | 94 } |
94 | 95 |
95 return true; | 96 return true; |
(...skipping 29 matching lines...) Expand all Loading... |
125 i != filters.end(); | 126 i != filters.end(); |
126 ++i) { | 127 ++i) { |
127 if (i->Matches(device)) { | 128 if (i->Matches(device)) { |
128 return true; | 129 return true; |
129 } | 130 } |
130 } | 131 } |
131 return false; | 132 return false; |
132 } | 133 } |
133 | 134 |
134 } // namespace device | 135 } // namespace device |
OLD | NEW |