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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 | 62 |
| 63 bool IsEmptyOrInvalidFilter( | 63 bool IsEmptyOrInvalidFilter( |
| 64 const blink::mojom::WebBluetoothScanFilterPtr& filter) { | 64 const blink::mojom::WebBluetoothScanFilterPtr& filter) { |
| 65 // At least one member needs to be present. | 65 // At least one member needs to be present. |
| 66 if (filter->name.is_null() && filter->name_prefix.is_null() && | 66 if (filter->name.is_null() && filter->name_prefix.is_null() && |
| 67 filter->services.is_null()) | 67 filter->services.is_null()) |
| 68 return true; | 68 return true; |
| 69 | 69 |
| 70 // The renderer will never send a name or a name_prefix longer than | 70 // The renderer will never send a name or a name_prefix longer than |
| 71 // kMaxLengthForDeviceName. | 71 // kMaxLengthForDeviceName. |
| 72 if (!filter->name.is_null() && filter->name.size() > kMaxLengthForDeviceName) | 72 if (filter->name.size() > kMaxLengthForDeviceName) |
|
ortuno
2016/07/31 18:00:05
I don't think we should remove the is_null. Once w
scheib
2016/08/02 03:24:33
Done.
| |
| 73 return true; | 73 return true; |
| 74 if (!filter->name_prefix.is_null() && | 74 if (!filter->name_prefix.is_null() && filter->name_prefix.size() == 0) |
| 75 filter->name_prefix.size() > kMaxLengthForDeviceName) | 75 return true; |
| 76 if (filter->name_prefix.size() > kMaxLengthForDeviceName) | |
|
ortuno
2016/07/31 18:00:05
Same here. I don't think we should remove the chec
scheib
2016/08/02 03:24:33
Done.
| |
| 76 return true; | 77 return true; |
| 77 | 78 |
| 78 return false; | 79 return false; |
| 79 } | 80 } |
| 80 | 81 |
| 81 bool HasEmptyOrInvalidFilter( | 82 bool HasEmptyOrInvalidFilter( |
| 82 const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { | 83 const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { |
| 83 return filters.empty() | 84 return filters.empty() |
| 84 ? true | 85 ? true |
| 85 : filters.end() != std::find_if(filters.begin(), filters.end(), | 86 : filters.end() != std::find_if(filters.begin(), filters.end(), |
| 86 IsEmptyOrInvalidFilter); | 87 IsEmptyOrInvalidFilter); |
| 87 } | 88 } |
| 88 | 89 |
| 89 bool MatchesFilter(const device::BluetoothDevice& device, | 90 bool MatchesFilter(const device::BluetoothDevice& device, |
| 90 const blink::mojom::WebBluetoothScanFilterPtr& filter) { | 91 const blink::mojom::WebBluetoothScanFilterPtr& filter) { |
| 91 DCHECK(!IsEmptyOrInvalidFilter(filter)); | 92 CHECK(!IsEmptyOrInvalidFilter(filter)); |
|
ortuno
2016/07/31 18:00:05
Not sure if we actually need this CHECK. We alread
scheib
2016/08/02 03:24:33
Ok, removing the DCHECK here. MatchesFilters calls
| |
| 92 | 93 |
| 93 // TODO(615720): Use the upcoming GetName (was GetDeviceName). | 94 if (!filter->name.is_null()) { |
| 94 const std::string device_name = base::UTF16ToUTF8(device.GetNameForDisplay()); | 95 if (!device.GetName()) |
| 95 | 96 return false; |
| 96 if (!filter->name.is_null() && (device_name != filter->name)) { | 97 if (filter->name != device.GetName().value()) |
| 97 return false; | 98 return false; |
| 98 } | 99 } |
| 99 | 100 |
| 100 if (!filter->name_prefix.is_null() && | 101 if (filter->name_prefix.size()) { |
|
ortuno
2016/07/31 18:00:05
Same here. I don't think we should change the is_n
scheib
2016/08/02 03:24:33
Done.
| |
| 101 (!base::StartsWith(device_name, filter->name_prefix.get(), | 102 if (!device.GetName()) |
| 102 base::CompareCase::SENSITIVE))) { | 103 return false; |
| 103 return false; | 104 if (!base::StartsWith(device.GetName().value(), filter->name_prefix.get(), |
| 105 base::CompareCase::SENSITIVE)) | |
| 106 return false; | |
| 104 } | 107 } |
| 105 | 108 |
| 106 if (!filter->services.is_null()) { | 109 if (!filter->services.is_null()) { |
| 107 const auto& device_uuid_list = device.GetUUIDs(); | 110 const auto& device_uuid_list = device.GetUUIDs(); |
| 108 const std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> | 111 const std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> |
| 109 device_uuids(device_uuid_list.begin(), device_uuid_list.end()); | 112 device_uuids(device_uuid_list.begin(), device_uuid_list.end()); |
| 110 for (const base::Optional<BluetoothUUID>& service : filter->services) { | 113 for (const base::Optional<BluetoothUUID>& service : filter->services) { |
| 111 if (!ContainsKey(device_uuids, service.value())) { | 114 if (!ContainsKey(device_uuids, service.value())) { |
| 112 return false; | 115 return false; |
| 113 } | 116 } |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 | 482 |
| 480 void BluetoothDeviceChooserController::PostErrorCallback( | 483 void BluetoothDeviceChooserController::PostErrorCallback( |
| 481 blink::mojom::WebBluetoothError error) { | 484 blink::mojom::WebBluetoothError error) { |
| 482 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( | 485 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 483 FROM_HERE, base::Bind(error_callback_, error))) { | 486 FROM_HERE, base::Bind(error_callback_, error))) { |
| 484 LOG(WARNING) << "No TaskRunner."; | 487 LOG(WARNING) << "No TaskRunner."; |
| 485 } | 488 } |
| 486 } | 489 } |
| 487 | 490 |
| 488 } // namespace content | 491 } // namespace content |
| OLD | NEW |