Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1014)

Unified Diff: content/browser/bluetooth/bluetooth_device_chooser_controller.cc

Issue 2510323002: bluetooth: Implement acceptAllDevices (Closed)
Patch Set: Clean up Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 082d1e8b42f0aad21f6cd7546f85663df1f7df26..ce41262b6b64e4abd9eb12fa922cc4ac5ee971fb 100644
--- a/content/browser/bluetooth/bluetooth_device_chooser_controller.cc
+++ b/content/browser/bluetooth/bluetooth_device_chooser_controller.cc
@@ -61,6 +61,11 @@ void LogRequestDeviceOptions(
const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) {
VLOG(1) << "requestDevice called with the following filters: ";
int i = 0;
+ VLOG(1) << "acceptAllDevices: " << options->accept_all_devices;
+
+ if (options->filters.is_null())
+ return;
+
for (const auto& filter : options->filters) {
VLOG(1) << "Filter #" << ++i;
if (!filter->name.is_null())
@@ -101,12 +106,28 @@ bool IsEmptyOrInvalidFilter(
bool HasEmptyOrInvalidFilter(
const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
+ if (filters.is_null()) {
+ return true;
+ }
+
return filters.empty()
? true
: filters.end() != std::find_if(filters.begin(), filters.end(),
IsEmptyOrInvalidFilter);
}
+bool IsOptionsInvalid(
+ const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) {
+ if ((!options->filters.is_null() && options->accept_all_devices) ||
+ (options->filters.is_null() && !options->accept_all_devices)) {
scheib 2016/11/22 21:22:44 122 is redundant with 125,126 I think. Would this
ortuno 2016/11/23 06:03:08 Nice. Done.
+ return true;
+ }
+ if (!options->accept_all_devices) {
+ return HasEmptyOrInvalidFilter(options->filters);
+ }
+ return false;
+}
+
bool MatchesFilter(const std::string* device_name,
const UUIDSet& device_uuids,
const blink::mojom::WebBluetoothScanFilterPtr& filter) {
@@ -152,11 +173,14 @@ bool MatchesFilters(
std::unique_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter(
const mojo::Array<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 (!filters.is_null()) {
+ for (const auto& filter : filters) {
+ for (const base::Optional<BluetoothUUID>& service : filter->services) {
+ services.insert(service.value());
+ }
}
}
+
// 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
// able to interact with. To avoid wasting power and confusing users with
@@ -251,17 +275,18 @@ void BluetoothDeviceChooserController::GetDevice(
success_callback_ = success_callback;
error_callback_ = error_callback;
- // The renderer should never send empty filters.
- if (HasEmptyOrInvalidFilter(options->filters)) {
+ // The renderer should never send invalid options.
+ if (IsOptionsInvalid(options)) {
web_bluetooth_service_->CrashRendererAndClosePipe(
- bad_message::BDH_EMPTY_OR_INVALID_FILTERS);
+ bad_message::BDH_INVALID_OPTIONS);
return;
}
options_ = std::move(options);
LogRequestDeviceOptions(options_);
// Check blacklist to reject invalid filters and adjust optional_services.
- if (BluetoothBlacklist::Get().IsExcluded(options_->filters)) {
+ if (!options_->filters.is_null() &&
+ BluetoothBlacklist::Get().IsExcluded(options_->filters)) {
RecordRequestDeviceOutcome(
UMARequestDeviceOutcome::BLACKLISTED_SERVICE_IN_FILTER);
PostErrorCallback(
@@ -362,15 +387,17 @@ void BluetoothDeviceChooserController::GetDevice(
void BluetoothDeviceChooserController::AddFilteredDevice(
const device::BluetoothDevice& device) {
base::Optional<std::string> device_name = device.GetName();
- if (chooser_.get() &&
- MatchesFilters(device_name ? &device_name.value() : nullptr,
- device.GetUUIDs(), options_->filters)) {
- base::Optional<int8_t> rssi = device.GetInquiryRSSI();
- chooser_->AddOrUpdateDevice(
- device.GetAddress(), !!device.GetName() /* should_update_name */,
- device.GetNameForDisplay(), device.IsGattConnected(),
- web_bluetooth_service_->IsDevicePaired(device.GetAddress()),
- rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1);
+ if (chooser_.get()) {
+ if (options_->accept_all_devices ||
+ MatchesFilters(device_name ? &device_name.value() : nullptr,
+ device.GetUUIDs(), options_->filters)) {
+ base::Optional<int8_t> rssi = device.GetInquiryRSSI();
+ chooser_->AddOrUpdateDevice(
+ device.GetAddress(), !!device.GetName() /* should_update_name */,
+ device.GetNameForDisplay(), device.IsGattConnected(),
+ web_bluetooth_service_->IsDevicePaired(device.GetAddress()),
+ rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1);
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698