Add ICU message format support
[chromium-blink-merge.git] / device / hid / hid_device_filter.cc
blob3be57ab69fc6c28c2225083d4245054854c936ef
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"
9 namespace device {
11 HidDeviceFilter::HidDeviceFilter()
12 : vendor_id_set_(false),
13 product_id_set_(false),
14 usage_page_set_(false),
15 usage_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) {
37 usage_set_ = true;
38 usage_ = usage;
41 bool HidDeviceFilter::Matches(
42 scoped_refptr<const HidDeviceInfo> device_info) const {
43 if (vendor_id_set_) {
44 if (device_info->vendor_id() != vendor_id_) {
45 return false;
48 if (product_id_set_ && device_info->product_id() != product_id_) {
49 return false;
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_) {
57 continue;
59 if (usage_set_ && collection.usage.usage != usage_) {
60 continue;
62 found_matching_collection = true;
64 if (!found_matching_collection) {
65 return false;
69 return true;
72 // static
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)) {
77 return true;
80 return false;
83 } // namespace device