| 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/hid/hid_device_filter.h" | 5 #include "device/hid/hid_device_filter.h" |
| 6 | 6 |
| 7 #include "device/hid/hid_device_info.h" | 7 #include "device/hid/hid_device_info.h" |
| 8 | 8 |
| 9 namespace device { | 9 namespace device { |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 void HidDeviceFilter::SetUsagePage(uint16_t usage_page) { | 31 void HidDeviceFilter::SetUsagePage(uint16_t usage_page) { |
| 32 usage_page_set_ = true; | 32 usage_page_set_ = true; |
| 33 usage_page_ = usage_page; | 33 usage_page_ = usage_page; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void HidDeviceFilter::SetUsage(uint16_t usage) { | 36 void HidDeviceFilter::SetUsage(uint16_t usage) { |
| 37 usage_set_ = true; | 37 usage_set_ = true; |
| 38 usage_ = usage; | 38 usage_ = usage; |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool HidDeviceFilter::Matches(const HidDeviceInfo& device_info) const { | 41 bool HidDeviceFilter::Matches( |
| 42 scoped_refptr<const HidDeviceInfo> device_info) const { |
| 42 if (vendor_id_set_) { | 43 if (vendor_id_set_) { |
| 43 if (device_info.vendor_id != vendor_id_) { | 44 if (device_info->vendor_id() != vendor_id_) { |
| 44 return false; | 45 return false; |
| 45 } | 46 } |
| 46 | 47 |
| 47 if (product_id_set_ && device_info.product_id != product_id_) { | 48 if (product_id_set_ && device_info->product_id() != product_id_) { |
| 48 return false; | 49 return false; |
| 49 } | 50 } |
| 50 } | 51 } |
| 51 | 52 |
| 52 if (usage_page_set_) { | 53 if (usage_page_set_) { |
| 53 bool found_matching_collection = false; | 54 bool found_matching_collection = false; |
| 54 for (std::vector<HidCollectionInfo>::const_iterator i = | 55 for (const HidCollectionInfo& collection : device_info->collections()) { |
| 55 device_info.collections.begin(); | |
| 56 i != device_info.collections.end() && !found_matching_collection; | |
| 57 ++i) { | |
| 58 const HidCollectionInfo& collection = *i; | |
| 59 if (collection.usage.usage_page != usage_page_) { | 56 if (collection.usage.usage_page != usage_page_) { |
| 60 continue; | 57 continue; |
| 61 } | 58 } |
| 62 if (usage_set_ && collection.usage.usage != usage_) { | 59 if (usage_set_ && collection.usage.usage != usage_) { |
| 63 continue; | 60 continue; |
| 64 } | 61 } |
| 65 found_matching_collection = true; | 62 found_matching_collection = true; |
| 66 } | 63 } |
| 67 if (!found_matching_collection) { | 64 if (!found_matching_collection) { |
| 68 return false; | 65 return false; |
| 69 } | 66 } |
| 70 } | 67 } |
| 71 | 68 |
| 72 return true; | 69 return true; |
| 73 } | 70 } |
| 74 | 71 |
| 75 // static | 72 // static |
| 76 bool HidDeviceFilter::MatchesAny( | 73 bool HidDeviceFilter::MatchesAny(scoped_refptr<const HidDeviceInfo> device_info, |
| 77 const HidDeviceInfo& device_info, | 74 const std::vector<HidDeviceFilter>& filters) { |
| 78 const std::vector<HidDeviceFilter>& filters) { | 75 for (const HidDeviceFilter& filter : filters) { |
| 79 for (std::vector<HidDeviceFilter>::const_iterator i = filters.begin(); | 76 if (filter.Matches(device_info)) { |
| 80 i != filters.end(); | |
| 81 ++i) { | |
| 82 if (i->Matches(device_info)) { | |
| 83 return true; | 77 return true; |
| 84 } | 78 } |
| 85 } | 79 } |
| 86 return false; | 80 return false; |
| 87 } | 81 } |
| 88 | 82 |
| 89 } // namespace device | 83 } // namespace device |
| OLD | NEW |