Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/bluetooth/bluetooth_device_chooser_controller.h" | 5 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <unordered_set> | 9 #include <unordered_set> |
| 10 | 10 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 return filters.empty() | 83 return filters.empty() |
| 84 ? true | 84 ? true |
| 85 : filters.end() != std::find_if(filters.begin(), filters.end(), | 85 : filters.end() != std::find_if(filters.begin(), filters.end(), |
| 86 IsEmptyOrInvalidFilter); | 86 IsEmptyOrInvalidFilter); |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool MatchesFilter(const device::BluetoothDevice& device, | 89 bool MatchesFilter(const device::BluetoothDevice& device, |
| 90 const blink::mojom::WebBluetoothScanFilterPtr& filter) { | 90 const blink::mojom::WebBluetoothScanFilterPtr& filter) { |
| 91 DCHECK(!IsEmptyOrInvalidFilter(filter)); | 91 DCHECK(!IsEmptyOrInvalidFilter(filter)); |
| 92 | 92 |
| 93 // TODO(615720): Use the upcoming GetName (was GetDeviceName). | 93 if (device.GetName()) { |
|
ortuno
2016/07/21 17:42:29
If a device doesn't have a name and name is the on
scheib
2016/07/30 02:38:13
Done.
| |
| 94 const std::string device_name = base::UTF16ToUTF8(device.GetNameForDisplay()); | 94 if (!filter->name.is_null() && (device.GetName().value() != filter->name)) { |
| 95 return false; | |
| 96 } | |
| 95 | 97 |
| 96 if (!filter->name.is_null() && (device_name != filter->name)) { | 98 if (filter->name_prefix.size() && |
| 97 return false; | 99 (!base::StartsWith(device.GetName().value(), filter->name_prefix.get(), |
| 98 } | 100 base::CompareCase::SENSITIVE))) { |
| 99 | 101 return false; |
| 100 if (!filter->name_prefix.is_null() && | 102 } |
| 101 (!base::StartsWith(device_name, filter->name_prefix.get(), | |
| 102 base::CompareCase::SENSITIVE))) { | |
| 103 return false; | |
| 104 } | 103 } |
| 105 | 104 |
| 106 if (!filter->services.is_null()) { | 105 if (!filter->services.is_null()) { |
| 107 const auto& device_uuid_list = device.GetUUIDs(); | 106 const auto& device_uuid_list = device.GetUUIDs(); |
| 108 const std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> | 107 const std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> |
| 109 device_uuids(device_uuid_list.begin(), device_uuid_list.end()); | 108 device_uuids(device_uuid_list.begin(), device_uuid_list.end()); |
| 110 for (const base::Optional<BluetoothUUID>& service : filter->services) { | 109 for (const base::Optional<BluetoothUUID>& service : filter->services) { |
| 111 if (!ContainsKey(device_uuids, service.value())) { | 110 if (!ContainsKey(device_uuids, service.value())) { |
| 112 return false; | 111 return false; |
| 113 } | 112 } |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 | 478 |
| 480 void BluetoothDeviceChooserController::PostErrorCallback( | 479 void BluetoothDeviceChooserController::PostErrorCallback( |
| 481 blink::mojom::WebBluetoothError error) { | 480 blink::mojom::WebBluetoothError error) { |
| 482 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( | 481 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 483 FROM_HERE, base::Bind(error_callback_, error))) { | 482 FROM_HERE, base::Bind(error_callback_, error))) { |
| 484 LOG(WARNING) << "No TaskRunner."; | 483 LOG(WARNING) << "No TaskRunner."; |
| 485 } | 484 } |
| 486 } | 485 } |
| 487 | 486 |
| 488 } // namespace content | 487 } // namespace content |
| OLD | NEW |