| Index: content/browser/bluetooth/bluetooth_device_chooser_controller.cc
|
| diff --git a/content/browser/bluetooth/bluetooth_device_chooser_controller.cc b/content/browser/bluetooth/bluetooth_device_chooser_controller.cc
|
| index 8f921326a892d6d1d6c516b77c0a65a9d75a90d2..b7687e1604479b87a7d3a62364c8126c2f53403e 100644
|
| --- a/content/browser/bluetooth/bluetooth_device_chooser_controller.cc
|
| +++ b/content/browser/bluetooth/bluetooth_device_chooser_controller.cc
|
| @@ -64,17 +64,17 @@ void LogRequestDeviceOptions(
|
| int i = 0;
|
| for (const auto& filter : options->filters) {
|
| VLOG(1) << "Filter #" << ++i;
|
| - if (!filter->name.is_null())
|
| - VLOG(1) << "Name: " << filter->name;
|
| + if (filter->name)
|
| + VLOG(1) << "Name: " << filter->name.value();
|
|
|
| - if (!filter->name_prefix.is_null())
|
| - VLOG(1) << "Name Prefix: " << filter->name_prefix;
|
| + if (filter->name_prefix)
|
| + VLOG(1) << "Name Prefix: " << filter->name_prefix.value();
|
|
|
| - if (!filter->services.is_null()) {
|
| + if (filter->services) {
|
| VLOG(1) << "Services: ";
|
| VLOG(1) << "\t[";
|
| - for (const auto& service : filter->services)
|
| - VLOG(1) << "\t\t" << service->canonical_value();
|
| + for (const auto& service : filter->services.value())
|
| + VLOG(1) << "\t\t" << service.canonical_value();
|
| VLOG(1) << "\t]";
|
| }
|
| }
|
| @@ -83,25 +83,24 @@ void LogRequestDeviceOptions(
|
| bool IsEmptyOrInvalidFilter(
|
| const blink::mojom::WebBluetoothScanFilterPtr& filter) {
|
| // At least one member needs to be present.
|
| - if (filter->name.is_null() && filter->name_prefix.is_null() &&
|
| - filter->services.is_null())
|
| + if (!filter->name && !filter->name_prefix && !filter->services)
|
| return true;
|
|
|
| // The renderer will never send a name or a name_prefix longer than
|
| // kMaxLengthForDeviceName.
|
| - if (!filter->name.is_null() && filter->name.size() > kMaxLengthForDeviceName)
|
| + if (filter->name && filter->name->size() > kMaxLengthForDeviceName)
|
| return true;
|
| - if (!filter->name_prefix.is_null() && filter->name_prefix.size() == 0)
|
| + if (filter->name_prefix && filter->name_prefix->size() == 0)
|
| return true;
|
| - if (!filter->name_prefix.is_null() &&
|
| - filter->name_prefix.size() > kMaxLengthForDeviceName)
|
| + if (filter->name_prefix &&
|
| + filter->name_prefix->size() > kMaxLengthForDeviceName)
|
| return true;
|
|
|
| return false;
|
| }
|
|
|
| bool HasEmptyOrInvalidFilter(
|
| - const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
|
| + const std::vector<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
|
| return filters.empty()
|
| ? true
|
| : filters.end() != std::find_if(filters.begin(), filters.end(),
|
| @@ -111,26 +110,25 @@ bool HasEmptyOrInvalidFilter(
|
| bool MatchesFilter(const std::string* device_name,
|
| const UUIDSet& device_uuids,
|
| const blink::mojom::WebBluetoothScanFilterPtr& filter) {
|
| - if (!filter->name.is_null()) {
|
| + if (filter->name) {
|
| if (device_name == nullptr)
|
| return false;
|
| - if (filter->name != *device_name)
|
| + if (filter->name.value() != *device_name)
|
| return false;
|
| }
|
|
|
| - if (!filter->name_prefix.is_null() && filter->name_prefix.size()) {
|
| + if (filter->name_prefix && filter->name_prefix->size()) {
|
| if (device_name == nullptr)
|
| return false;
|
| - if (!base::StartsWith(*device_name, filter->name_prefix.get(),
|
| + if (!base::StartsWith(*device_name, filter->name_prefix.value(),
|
| base::CompareCase::SENSITIVE))
|
| return false;
|
| }
|
|
|
| - if (!filter->services.is_null()) {
|
| - for (const base::Optional<BluetoothUUID>& service : filter->services) {
|
| - if (!base::ContainsKey(device_uuids, service.value())) {
|
| + if (filter->services) {
|
| + for (const auto& service : filter->services.value()) {
|
| + if (!base::ContainsKey(device_uuids, service))
|
| return false;
|
| - }
|
| }
|
| }
|
|
|
| @@ -140,23 +138,23 @@ bool MatchesFilter(const std::string* device_name,
|
| bool MatchesFilters(
|
| const std::string* device_name,
|
| const UUIDSet& device_uuids,
|
| - const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
|
| + const std::vector<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
|
| DCHECK(!HasEmptyOrInvalidFilter(filters));
|
| for (const auto& filter : filters) {
|
| - if (MatchesFilter(device_name, device_uuids, filter)) {
|
| + if (MatchesFilter(device_name, device_uuids, filter))
|
| return true;
|
| - }
|
| }
|
| return false;
|
| }
|
|
|
| std::unique_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter(
|
| - const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
|
| + const std::vector<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
|
| std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> services;
|
| for (const auto& filter : filters) {
|
| - for (const base::Optional<BluetoothUUID>& service : filter->services) {
|
| - services.insert(service.value());
|
| - }
|
| + if (!filter->services)
|
| + continue;
|
| + for (const auto& service : filter->services.value())
|
| + services.insert(service);
|
| }
|
| // There isn't much support for GATT over BR/EDR from neither platforms nor
|
| // devices so performing a Dual scan will find devices that the API is not
|
| @@ -164,9 +162,8 @@ std::unique_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter(
|
| // devices they are not able to interact with, we only perform an LE Scan.
|
| auto discovery_filter = base::MakeUnique<device::BluetoothDiscoveryFilter>(
|
| device::BLUETOOTH_TRANSPORT_LE);
|
| - for (const BluetoothUUID& service : services) {
|
| + for (const BluetoothUUID& service : services)
|
| discovery_filter->AddUUID(service);
|
| - }
|
| return discovery_filter;
|
| }
|
|
|
| @@ -383,9 +380,8 @@ void BluetoothDeviceChooserController::AddFilteredDevice(
|
| }
|
|
|
| void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) {
|
| - if (!powered && discovery_session_.get()) {
|
| + if (!powered && discovery_session_.get())
|
| StopDiscoverySession(std::move(discovery_session_));
|
| - }
|
|
|
| if (chooser_.get()) {
|
| chooser_->SetAdapterPresence(
|
| @@ -397,9 +393,8 @@ void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) {
|
| }
|
| }
|
|
|
| - if (!powered) {
|
| + if (!powered)
|
| discovery_session_timer_.Stop();
|
| - }
|
| }
|
|
|
| int BluetoothDeviceChooserController::CalculateSignalStrengthLevel(
|
| @@ -432,9 +427,8 @@ void BluetoothDeviceChooserController::SetTestScanDurationForTesting() {
|
|
|
| void BluetoothDeviceChooserController::PopulateConnectedDevices() {
|
| for (const device::BluetoothDevice* device : adapter_->GetDevices()) {
|
| - if (device->IsGattConnected()) {
|
| + if (device->IsGattConnected())
|
| AddFilteredDevice(*device);
|
| - }
|
| }
|
| }
|
|
|
| @@ -470,9 +464,8 @@ void BluetoothDeviceChooserController::StopDeviceDiscovery() {
|
| }
|
|
|
| StopDiscoverySession(std::move(discovery_session_));
|
| - if (chooser_) {
|
| + if (chooser_)
|
| chooser_->ShowDiscoveryState(BluetoothChooser::DiscoveryState::IDLE);
|
| - }
|
| }
|
|
|
| void BluetoothDeviceChooserController::OnStartDiscoverySessionSuccess(
|
|
|