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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 return filters.empty() | 94 return filters.empty() |
95 ? true | 95 ? true |
96 : filters.end() != std::find_if(filters.begin(), filters.end(), | 96 : filters.end() != std::find_if(filters.begin(), filters.end(), |
97 IsEmptyOrInvalidFilter); | 97 IsEmptyOrInvalidFilter); |
98 } | 98 } |
99 | 99 |
100 bool MatchesFilter(const device::BluetoothDevice& device, | 100 bool MatchesFilter(const device::BluetoothDevice& device, |
101 const blink::mojom::WebBluetoothScanFilterPtr& filter) { | 101 const blink::mojom::WebBluetoothScanFilterPtr& filter) { |
102 DCHECK(!IsEmptyOrInvalidFilter(filter)); | 102 DCHECK(!IsEmptyOrInvalidFilter(filter)); |
103 | 103 |
104 const std::string device_name = base::UTF16ToUTF8(device.GetName()); | 104 // TODO(615720): Use the upcoming GetName (was GetDeviceName). |
| 105 const std::string device_name = base::UTF16ToUTF8(device.GetNameForDisplay()); |
105 | 106 |
106 if (!filter->name.is_null() && (device_name != filter->name)) { | 107 if (!filter->name.is_null() && (device_name != filter->name)) { |
107 return false; | 108 return false; |
108 } | 109 } |
109 | 110 |
110 if (!filter->name_prefix.is_null() && | 111 if (!filter->name_prefix.is_null() && |
111 (!base::StartsWith(device_name, filter->name_prefix.get(), | 112 (!base::StartsWith(device_name, filter->name_prefix.get(), |
112 base::CompareCase::SENSITIVE))) { | 113 base::CompareCase::SENSITIVE))) { |
113 return false; | 114 return false; |
114 } | 115 } |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 return; | 345 return; |
345 } | 346 } |
346 | 347 |
347 StartDeviceDiscovery(); | 348 StartDeviceDiscovery(); |
348 } | 349 } |
349 | 350 |
350 void BluetoothDeviceChooserController::AddFilteredDevice( | 351 void BluetoothDeviceChooserController::AddFilteredDevice( |
351 const device::BluetoothDevice& device) { | 352 const device::BluetoothDevice& device) { |
352 if (chooser_.get() && MatchesFilters(device, options_->filters)) { | 353 if (chooser_.get() && MatchesFilters(device, options_->filters)) { |
353 VLOG(1) << "Adding device to chooser: " << device.GetAddress(); | 354 VLOG(1) << "Adding device to chooser: " << device.GetAddress(); |
354 chooser_->AddDevice(device.GetAddress(), device.GetName()); | 355 chooser_->AddDevice(device.GetAddress(), device.GetNameForDisplay()); |
355 } | 356 } |
356 } | 357 } |
357 | 358 |
358 void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) { | 359 void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) { |
359 if (!powered && discovery_session_.get()) { | 360 if (!powered && discovery_session_.get()) { |
360 StopDiscoverySession(std::move(discovery_session_)); | 361 StopDiscoverySession(std::move(discovery_session_)); |
361 } | 362 } |
362 | 363 |
363 if (chooser_.get()) { | 364 if (chooser_.get()) { |
364 chooser_->SetAdapterPresence( | 365 chooser_->SetAdapterPresence( |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 475 |
475 void BluetoothDeviceChooserController::PostErrorCallback( | 476 void BluetoothDeviceChooserController::PostErrorCallback( |
476 blink::mojom::WebBluetoothError error) { | 477 blink::mojom::WebBluetoothError error) { |
477 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( | 478 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( |
478 FROM_HERE, base::Bind(error_callback_, error))) { | 479 FROM_HERE, base::Bind(error_callback_, error))) { |
479 LOG(WARNING) << "No TaskRunner."; | 480 LOG(WARNING) << "No TaskRunner."; |
480 } | 481 } |
481 } | 482 } |
482 | 483 |
483 } // namespace content | 484 } // namespace content |
OLD | NEW |