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

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

Issue 1337413003: Match against all configurations in UsbDeviceFilter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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_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
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 bool foundMatch = false;
72 if (!config) { 72 for (const UsbConfigDescriptor& config : device->configurations()) {
73 return false; 73 for (const UsbInterfaceDescriptor& iface : config.interfaces) {
74 if (iface.interface_class == interface_class_ &&
75 (!interface_subclass_set_ ||
76 (iface.interface_subclass == interface_subclass_ &&
77 (!interface_protocol_set_ ||
78 iface.interface_protocol == interface_protocol_)))) {
Ken Rockot(use gerrit already) 2015/09/15 17:40:09 I think foundMatch is unnecessary, and you can jus
Reilly Grant (use Gerrit) 2015/09/15 17:45:54 Done.
79 foundMatch = true;
80 break;
81 }
82 }
83 if (foundMatch)
84 break;
74 } 85 }
75 86
76 // TODO(reillyg): Check device configuration if the class is not defined at 87 if (!foundMatch)
77 // a per-interface level. This is not really important because most devices
78 // have per-interface classes. The only counter-examples I know of are hubs.
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 }
89 }
90
91 if (!foundMatch) {
92 return false; 88 return false;
93 }
94 } 89 }
95 90
96 return true; 91 return true;
97 } 92 }
98 93
99 scoped_ptr<base::Value> UsbDeviceFilter::ToValue() const { 94 scoped_ptr<base::Value> UsbDeviceFilter::ToValue() const {
100 scoped_ptr<base::DictionaryValue> obj(new base::DictionaryValue()); 95 scoped_ptr<base::DictionaryValue> obj(new base::DictionaryValue());
101 96
102 if (vendor_id_set_) { 97 if (vendor_id_set_) {
103 obj->SetInteger(kVendorIdKey, vendor_id_); 98 obj->SetInteger(kVendorIdKey, vendor_id_);
(...skipping 22 matching lines...) Expand all
126 i != filters.end(); 121 i != filters.end();
127 ++i) { 122 ++i) {
128 if (i->Matches(device)) { 123 if (i->Matches(device)) {
129 return true; 124 return true;
130 } 125 }
131 } 126 }
132 return false; 127 return false;
133 } 128 }
134 129
135 } // namespace device 130 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698