Chromium Code Reviews| Index: content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| index d10d56e1266d48b1f242041cffe9db05d790b299..19463bd9b38be1b19fb5e4cde4ced39bac72c75e 100644 |
| --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| @@ -49,25 +49,44 @@ const int kTestingDelayTime = 0; // No need to wait during tests |
| // Defined at |
| // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter |
| -bool MatchesFilter(const std::set<BluetoothUUID>& device_uuids, |
| +bool MatchesFilter(const device::BluetoothDevice& device, |
| const content::BluetoothScanFilter& filter) { |
| - if (filter.services.empty()) |
| - return false; |
| - for (const BluetoothUUID& service : filter.services) { |
| - if (!ContainsKey(device_uuids, service)) { |
| + DCHECK(!(filter.name.empty() && filter.namePrefix.empty() && |
|
scheib
2015/10/22 04:58:42
Malformed data from a renderer should kill it. Tha
ortuno
2015/10/22 16:21:31
Done.
|
| + filter.services.empty())); |
| + |
| + const std::string device_name = base::UTF16ToUTF8(device.GetName()); |
| + |
| + if (!filter.name.empty()) { |
| + if (device_name != filter.name) { |
| + return false; |
| + } |
| + } |
| + |
| + if (!filter.namePrefix.empty()) { |
| + if (!base::StartsWith(device_name, filter.namePrefix, |
| + base::CompareCase::SENSITIVE)) { |
| return false; |
| } |
| } |
| + |
| + if (!filter.services.empty()) { |
| + const std::vector<BluetoothUUID>& device_uuid_list = device.GetUUIDs(); |
| + const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(), |
| + device_uuid_list.end()); |
| + for (const BluetoothUUID& service : filter.services) { |
| + if (!ContainsKey(device_uuids, service)) { |
| + return false; |
| + } |
| + } |
| + } |
| + |
| return true; |
| } |
| bool MatchesFilters(const device::BluetoothDevice& device, |
| const std::vector<content::BluetoothScanFilter>& filters) { |
| - const std::vector<BluetoothUUID>& device_uuid_list = device.GetUUIDs(); |
| - const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(), |
| - device_uuid_list.end()); |
| for (const content::BluetoothScanFilter& filter : filters) { |
| - if (MatchesFilter(device_uuids, filter)) { |
| + if (MatchesFilter(device, filter)) { |
| return true; |
| } |
| } |
| @@ -443,6 +462,9 @@ void BluetoothDispatcherHost::OnRequestDevice( |
| VLOG(1) << "requestDevice called with the following filters: "; |
| for (const BluetoothScanFilter& filter : filters) { |
| + VLOG(1) << "Name: " << filter.name; |
| + VLOG(1) << "Name Prefix: " << filter.namePrefix; |
| + VLOG(1) << "Services:"; |
| VLOG(1) << "\t["; |
| for (const BluetoothUUID& service : filter.services) |
| VLOG(1) << "\t\t" << service.value(); |