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

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac.mm

Issue 2253223002: bluetooth: Implement hardware filtering on macOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Created 4 years, 4 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "device/bluetooth/bluetooth_adapter_mac.h" 5 #include "device/bluetooth/bluetooth_adapter_mac.h"
6 6
7 #import <IOBluetooth/objc/IOBluetoothDevice.h> 7 #import <IOBluetooth/objc/IOBluetoothDevice.h>
8 #import <IOBluetooth/objc/IOBluetoothHostController.h> 8 #import <IOBluetooth/objc/IOBluetoothHostController.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 290
291 DVLOG(1) << "Added a discovery session"; 291 DVLOG(1) << "Added a discovery session";
292 num_discovery_sessions_++; 292 num_discovery_sessions_++;
293 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, 293 FOR_EACH_OBSERVER(BluetoothAdapter::Observer,
294 observers_, 294 observers_,
295 AdapterDiscoveringChanged(this, true)); 295 AdapterDiscoveringChanged(this, true));
296 callback.Run(); 296 callback.Run();
297 } 297 }
298 298
299 void BluetoothAdapterMac::RemoveDiscoverySession( 299 void BluetoothAdapterMac::RemoveDiscoverySession(
300 BluetoothDiscoveryFilter* discovery_filter, 300 BluetoothDiscoveryFilter* discovery_filter,
Jeffrey Yasskin 2016/08/23 21:37:04 If we're guaranteed this is never null, can this b
ortuno 2016/08/25 17:58:31 Ah my bad. BluetoothDiscoveryFilter is not guarant
301 const base::Closure& callback, 301 const base::Closure& callback,
302 const DiscoverySessionErrorCallback& error_callback) { 302 const DiscoverySessionErrorCallback& error_callback) {
303 DVLOG(1) << __func__; 303 DVLOG(1) << __func__;
304 304
305 DCHECK(discovery_filter);
306
307 BluetoothTransport transport = discovery_filter->GetTransport();
308
305 if (num_discovery_sessions_ > 1) { 309 if (num_discovery_sessions_ > 1) {
306 // There are active sessions other than the one currently being removed. 310 // There are active sessions other than the one currently being removed.
307 DCHECK(IsDiscovering()); 311 DCHECK(IsDiscovering());
308 num_discovery_sessions_--; 312 num_discovery_sessions_--;
313
314 std::set<BluetoothUUID> filter_uuids;
315 discovery_filter->GetUUIDs(filter_uuids);
316
317 if (IsLowEnergyAvailable() && (transport & BLUETOOTH_TRANSPORT_LE)) {
318 low_energy_discovery_manager_->RemoveDiscoveryUUIDs(
319 std::move(filter_uuids));
320 }
321
309 callback.Run(); 322 callback.Run();
310 return; 323 return;
311 } 324 }
312 325
313 if (num_discovery_sessions_ == 0) { 326 if (num_discovery_sessions_ == 0) {
314 DVLOG(1) << "No active discovery sessions. Returning error."; 327 DVLOG(1) << "No active discovery sessions. Returning error.";
315 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_ACTIVE); 328 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_ACTIVE);
316 return; 329 return;
317 } 330 }
318 331
319 // Default to dual discovery if |discovery_filter| is NULL.
320 BluetoothTransport transport = BLUETOOTH_TRANSPORT_DUAL;
321 if (discovery_filter)
322 transport = discovery_filter->GetTransport();
323
324 if (transport & BLUETOOTH_TRANSPORT_CLASSIC) { 332 if (transport & BLUETOOTH_TRANSPORT_CLASSIC) {
325 if (!classic_discovery_manager_->StopDiscovery()) { 333 if (!classic_discovery_manager_->StopDiscovery()) {
326 DVLOG(1) << "Failed to stop classic discovery"; 334 DVLOG(1) << "Failed to stop classic discovery";
327 // TODO: Provide a more precise error here. 335 // TODO: Provide a more precise error here.
328 error_callback.Run(UMABluetoothDiscoverySessionOutcome::UNKNOWN); 336 error_callback.Run(UMABluetoothDiscoverySessionOutcome::UNKNOWN);
329 return; 337 return;
330 } 338 }
331 } 339 }
340
332 if (transport & BLUETOOTH_TRANSPORT_LE) { 341 if (transport & BLUETOOTH_TRANSPORT_LE) {
333 if (IsLowEnergyAvailable()) 342 if (IsLowEnergyAvailable())
334 low_energy_discovery_manager_->StopDiscovery(); 343 low_energy_discovery_manager_->StopDiscovery();
335 } 344 }
336 345
337 DVLOG(1) << "Discovery stopped"; 346 DVLOG(1) << "Discovery stopped";
338 num_discovery_sessions_--; 347 num_discovery_sessions_--;
339 callback.Run(); 348 callback.Run();
340 } 349 }
341 350
342 void BluetoothAdapterMac::SetDiscoveryFilter( 351 void BluetoothAdapterMac::SetDiscoveryFilter(
343 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter, 352 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
344 const base::Closure& callback, 353 const base::Closure& callback,
345 const DiscoverySessionErrorCallback& error_callback) { 354 const DiscoverySessionErrorCallback& error_callback) {
346 NOTIMPLEMENTED(); 355 NOTIMPLEMENTED();
347 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED); 356 error_callback.Run(UMABluetoothDiscoverySessionOutcome::NOT_IMPLEMENTED);
348 } 357 }
349 358
350 bool BluetoothAdapterMac::StartDiscovery( 359 bool BluetoothAdapterMac::StartDiscovery(
351 BluetoothDiscoveryFilter* discovery_filter) { 360 BluetoothDiscoveryFilter* discovery_filter) {
Jeffrey Yasskin 2016/08/23 21:37:04 Similarly here, change the interface's signature i
352 // Default to dual discovery if |discovery_filter| is NULL. IOBluetooth seems 361 DCHECK(discovery_filter);
353 // allow starting low energy and classic discovery at once. 362 BluetoothTransport transport = discovery_filter->GetTransport();
354 BluetoothTransport transport = BLUETOOTH_TRANSPORT_DUAL;
355 if (discovery_filter)
356 transport = discovery_filter->GetTransport();
357 363
358 if ((transport & BLUETOOTH_TRANSPORT_CLASSIC) && 364 if ((transport & BLUETOOTH_TRANSPORT_CLASSIC) &&
359 !classic_discovery_manager_->IsDiscovering()) { 365 !classic_discovery_manager_->IsDiscovering()) {
360 // TODO(krstnmnlsn): If a classic discovery session is already running then 366 // TODO(krstnmnlsn): If a classic discovery session is already running then
361 // we should update its filter. crbug.com/498056 367 // we should update its filter. crbug.com/498056
362 if (!classic_discovery_manager_->StartDiscovery()) { 368 if (!classic_discovery_manager_->StartDiscovery()) {
363 DVLOG(1) << "Failed to add a classic discovery session"; 369 DVLOG(1) << "Failed to add a classic discovery session";
364 return false; 370 return false;
365 } 371 }
366 } 372 }
367 if (transport & BLUETOOTH_TRANSPORT_LE) { 373 if (transport & BLUETOOTH_TRANSPORT_LE) {
368 // Begin a low energy discovery session or update it if one is already 374 // Begin a low energy discovery session or update it if one is already
369 // running. 375 // running.
370 if (IsLowEnergyAvailable()) 376 if (IsLowEnergyAvailable()) {
371 low_energy_discovery_manager_->StartDiscovery( 377 std::set<BluetoothUUID> filter_uuids;
372 BluetoothDevice::UUIDList()); 378 discovery_filter->GetUUIDs(filter_uuids);
379 low_energy_discovery_manager_->StartDiscovery(std::move(filter_uuids));
380 }
373 } 381 }
374 return true; 382 return true;
375 } 383 }
376 384
377 void BluetoothAdapterMac::Init() { 385 void BluetoothAdapterMac::Init() {
378 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 386 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get();
379 PollAdapter(); 387 PollAdapter();
380 } 388 }
381 389
382 void BluetoothAdapterMac::InitForTest( 390 void BluetoothAdapterMac::InitForTest(
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 std::string device_address = 599 std::string device_address =
592 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 600 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
593 DevicesMap::const_iterator iter = devices_.find(device_address); 601 DevicesMap::const_iterator iter = devices_.find(device_address);
594 if (iter == devices_.end()) { 602 if (iter == devices_.end()) {
595 return nil; 603 return nil;
596 } 604 }
597 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 605 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
598 } 606 }
599 607
600 } // namespace device 608 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_mac_unittest.mm » ('j') | device/bluetooth/bluetooth_adapter_mac_unittest.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698