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
3 // found in the LICENSE file.
5 #include "device/hid/hid_device_filter.h"
7 #include "device/hid/hid_device_info.h"
11 HidDeviceFilter::HidDeviceFilter()
12 : vendor_id_set_(false),
13 product_id_set_(false),
14 usage_page_set_(false),
18 HidDeviceFilter::~HidDeviceFilter() {
21 void HidDeviceFilter::SetVendorId(uint16_t vendor_id
) {
22 vendor_id_set_
= true;
23 vendor_id_
= vendor_id
;
26 void HidDeviceFilter::SetProductId(uint16_t product_id
) {
27 product_id_set_
= true;
28 product_id_
= product_id
;
31 void HidDeviceFilter::SetUsagePage(uint16_t usage_page
) {
32 usage_page_set_
= true;
33 usage_page_
= usage_page
;
36 void HidDeviceFilter::SetUsage(uint16_t usage
) {
41 bool HidDeviceFilter::Matches(
42 scoped_refptr
<const HidDeviceInfo
> device_info
) const {
44 if (device_info
->vendor_id() != vendor_id_
) {
48 if (product_id_set_
&& device_info
->product_id() != product_id_
) {
53 if (usage_page_set_
) {
54 bool found_matching_collection
= false;
55 for (const HidCollectionInfo
& collection
: device_info
->collections()) {
56 if (collection
.usage
.usage_page
!= usage_page_
) {
59 if (usage_set_
&& collection
.usage
.usage
!= usage_
) {
62 found_matching_collection
= true;
64 if (!found_matching_collection
) {
73 bool HidDeviceFilter::MatchesAny(scoped_refptr
<const HidDeviceInfo
> device_info
,
74 const std::vector
<HidDeviceFilter
>& filters
) {
75 for (const HidDeviceFilter
& filter
: filters
) {
76 if (filter
.Matches(device_info
)) {