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

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

Issue 2727633004: Change UsbDeviceFilter to use const references instead of (Closed)
Patch Set: Fix callsite missed earlier due to not building for CrOS Created 3 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
« no previous file with comments | « device/usb/usb_device_filter.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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 13 matching lines...) Expand all
24 const char kInterfaceProtocolKey[] = "interfaceProtocol"; 24 const char kInterfaceProtocolKey[] = "interfaceProtocol";
25 25
26 } // namespace 26 } // namespace
27 27
28 UsbDeviceFilter::UsbDeviceFilter() = default; 28 UsbDeviceFilter::UsbDeviceFilter() = default;
29 29
30 UsbDeviceFilter::UsbDeviceFilter(const UsbDeviceFilter& other) = default; 30 UsbDeviceFilter::UsbDeviceFilter(const UsbDeviceFilter& other) = default;
31 31
32 UsbDeviceFilter::~UsbDeviceFilter() = default; 32 UsbDeviceFilter::~UsbDeviceFilter() = default;
33 33
34 bool UsbDeviceFilter::Matches(scoped_refptr<UsbDevice> device) const { 34 bool UsbDeviceFilter::Matches(const UsbDevice& device) const {
35 if (vendor_id) { 35 if (vendor_id) {
36 if (device->vendor_id() != *vendor_id) 36 if (device.vendor_id() != *vendor_id)
37 return false; 37 return false;
38 38
39 if (product_id && device->product_id() != *product_id) 39 if (product_id && device.product_id() != *product_id)
40 return false; 40 return false;
41 } 41 }
42 42
43 if (serial_number && 43 if (serial_number &&
44 device->serial_number() != base::UTF8ToUTF16(*serial_number)) { 44 device.serial_number() != base::UTF8ToUTF16(*serial_number)) {
45 return false; 45 return false;
46 } 46 }
47 47
48 if (interface_class) { 48 if (interface_class) {
49 for (const UsbConfigDescriptor& config : device->configurations()) { 49 for (const UsbConfigDescriptor& config : device.configurations()) {
50 for (const UsbInterfaceDescriptor& iface : config.interfaces) { 50 for (const UsbInterfaceDescriptor& iface : config.interfaces) {
51 if (iface.interface_class == *interface_class && 51 if (iface.interface_class == *interface_class &&
52 (!interface_subclass || 52 (!interface_subclass ||
53 (iface.interface_subclass == *interface_subclass && 53 (iface.interface_subclass == *interface_subclass &&
54 (!interface_protocol || 54 (!interface_protocol ||
55 iface.interface_protocol == *interface_protocol)))) { 55 iface.interface_protocol == *interface_protocol)))) {
56 return true; 56 return true;
57 } 57 }
58 } 58 }
59 } 59 }
(...skipping 19 matching lines...) Expand all
79 obj->SetInteger(kInterfaceSubclassKey, *interface_subclass); 79 obj->SetInteger(kInterfaceSubclassKey, *interface_subclass);
80 if (interface_protocol) 80 if (interface_protocol)
81 obj->SetInteger(kInterfaceProtocolKey, *interface_protocol); 81 obj->SetInteger(kInterfaceProtocolKey, *interface_protocol);
82 } 82 }
83 } 83 }
84 84
85 return std::move(obj); 85 return std::move(obj);
86 } 86 }
87 87
88 // static 88 // static
89 bool UsbDeviceFilter::MatchesAny(scoped_refptr<UsbDevice> device, 89 bool UsbDeviceFilter::MatchesAny(const UsbDevice& device,
90 const std::vector<UsbDeviceFilter>& filters) { 90 const std::vector<UsbDeviceFilter>& filters) {
91 if (filters.empty()) 91 if (filters.empty())
92 return true; 92 return true;
93 93
94 for (const auto& filter : filters) { 94 for (const auto& filter : filters) {
95 if (filter.Matches(device)) 95 if (filter.Matches(device))
96 return true; 96 return true;
97 } 97 }
98 return false; 98 return false;
99 } 99 }
100 100
101 } // namespace device 101 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_device_filter.h ('k') | device/usb/usb_device_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698