| 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 const UsbConfigDescriptor* config = device->GetActiveConfiguration(); | 71 for (const UsbConfigDescriptor& config : device->configurations()) { |
| 72 if (!config) { | 72 for (const UsbInterfaceDescriptor& iface : config.interfaces) { |
| 73 return false; | 73 if (iface.interface_class == interface_class_ && |
| 74 } | 74 (!interface_subclass_set_ || |
| 75 | 75 (iface.interface_subclass == interface_subclass_ && |
| 76 // TODO(reillyg): Check device configuration if the class is not defined at | 76 (!interface_protocol_set_ || |
| 77 // a per-interface level. This is not really important because most devices | 77 iface.interface_protocol == interface_protocol_)))) { |
| 78 // have per-interface classes. The only counter-examples I know of are hubs. | 78 return true; |
| 79 | 79 } |
| 80 bool foundMatch = false; | |
| 81 for (const UsbInterfaceDescriptor& iface : config->interfaces) { | |
| 82 if (iface.interface_class == interface_class_ && | |
| 83 (!interface_subclass_set_ || | |
| 84 (iface.interface_subclass == interface_subclass_ && | |
| 85 (!interface_protocol_set_ || | |
| 86 iface.interface_protocol == interface_protocol_)))) { | |
| 87 foundMatch = true; | |
| 88 } | 80 } |
| 89 } | 81 } |
| 90 | 82 |
| 91 if (!foundMatch) { | 83 return false; |
| 92 return false; | |
| 93 } | |
| 94 } | 84 } |
| 95 | 85 |
| 96 return true; | 86 return true; |
| 97 } | 87 } |
| 98 | 88 |
| 99 scoped_ptr<base::Value> UsbDeviceFilter::ToValue() const { | 89 scoped_ptr<base::Value> UsbDeviceFilter::ToValue() const { |
| 100 scoped_ptr<base::DictionaryValue> obj(new base::DictionaryValue()); | 90 scoped_ptr<base::DictionaryValue> obj(new base::DictionaryValue()); |
| 101 | 91 |
| 102 if (vendor_id_set_) { | 92 if (vendor_id_set_) { |
| 103 obj->SetInteger(kVendorIdKey, vendor_id_); | 93 obj->SetInteger(kVendorIdKey, vendor_id_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 126 i != filters.end(); | 116 i != filters.end(); |
| 127 ++i) { | 117 ++i) { |
| 128 if (i->Matches(device)) { | 118 if (i->Matches(device)) { |
| 129 return true; | 119 return true; |
| 130 } | 120 } |
| 131 } | 121 } |
| 132 return false; | 122 return false; |
| 133 } | 123 } |
| 134 | 124 |
| 135 } // namespace device | 125 } // namespace device |
| OLD | NEW |