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

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

Issue 2282763004: bluetooth: mac: Improve classic device discovery and update (Closed)
Patch Set: Store a TimeDelta instead of int Created 4 years, 3 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 FROM_HERE, 462 FROM_HERE,
463 base::Bind(&BluetoothAdapterMac::PollAdapter, 463 base::Bind(&BluetoothAdapterMac::PollAdapter,
464 weak_ptr_factory_.GetWeakPtr()), 464 weak_ptr_factory_.GetWeakPtr()),
465 base::TimeDelta::FromMilliseconds(kPollIntervalMs)); 465 base::TimeDelta::FromMilliseconds(kPollIntervalMs));
466 } 466 }
467 467
468 void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) { 468 void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) {
469 std::string device_address = 469 std::string device_address =
470 BluetoothClassicDeviceMac::GetDeviceAddress(device); 470 BluetoothClassicDeviceMac::GetDeviceAddress(device);
471 471
472 BluetoothDevice* device_classic = GetDevice(device_address);
473
472 // Only notify observers once per device. 474 // Only notify observers once per device.
473 if (devices_.count(device_address)) 475 if (device_classic != nullptr) {
476 VLOG(3) << "Updating classic device: " << device_classic->GetAddress();
477 device_classic->UpdateTimestamp();
474 return; 478 return;
479 }
475 480
476 BluetoothDevice* device_classic = new BluetoothClassicDeviceMac(this, device); 481 device_classic = new BluetoothClassicDeviceMac(this, device);
477 devices_.set(device_address, base::WrapUnique(device_classic)); 482 devices_.set(device_address, base::WrapUnique(device_classic));
483 VLOG(1) << "Adding new classic device: " << device_classic->GetAddress();
484
478 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 485 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
479 DeviceAdded(this, device_classic)); 486 DeviceAdded(this, device_classic));
480 } 487 }
481 488
482 void BluetoothAdapterMac::LowEnergyDeviceUpdated( 489 void BluetoothAdapterMac::LowEnergyDeviceUpdated(
483 CBPeripheral* peripheral, 490 CBPeripheral* peripheral,
484 NSDictionary* advertisement_data, 491 NSDictionary* advertisement_data,
485 int rssi) { 492 int rssi) {
486 BluetoothLowEnergyDeviceMac* device_mac = 493 BluetoothLowEnergyDeviceMac* device_mac =
487 GetBluetoothLowEnergyDeviceMac(peripheral); 494 GetBluetoothLowEnergyDeviceMac(peripheral);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 DeviceChanged(this, device_mac)); 567 DeviceChanged(this, device_mac));
561 } 568 }
562 } 569 }
563 570
564 // TODO(krstnmnlsn): Implement. crbug.com/511025 571 // TODO(krstnmnlsn): Implement. crbug.com/511025
565 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {} 572 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {}
566 573
567 void BluetoothAdapterMac::AddPairedDevices() { 574 void BluetoothAdapterMac::AddPairedDevices() {
568 // Add any new paired devices. 575 // Add any new paired devices.
569 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { 576 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) {
570 ClassicDeviceAdded(device); 577 if ([device isPaired]) {
Jeffrey Yasskin 2016/09/14 20:35:57 Could you comment why this is needed, with any rad
ortuno 2016/09/20 04:31:32 Done. For some reason pairedDevices returns an un
578 ClassicDeviceAdded(device);
579 }
571 } 580 }
572 } 581 }
573 582
574 void BluetoothAdapterMac::CreateGattConnection( 583 void BluetoothAdapterMac::CreateGattConnection(
575 BluetoothLowEnergyDeviceMac* device_mac) { 584 BluetoothLowEnergyDeviceMac* device_mac) {
576 [low_energy_central_manager_ connectPeripheral:device_mac->peripheral_ 585 [low_energy_central_manager_ connectPeripheral:device_mac->peripheral_
577 options:nil]; 586 options:nil];
578 } 587 }
579 588
580 void BluetoothAdapterMac::DisconnectGatt( 589 void BluetoothAdapterMac::DisconnectGatt(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 std::string device_address = 644 std::string device_address =
636 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 645 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
637 DevicesMap::const_iterator iter = devices_.find(device_address); 646 DevicesMap::const_iterator iter = devices_.find(device_address);
638 if (iter == devices_.end()) { 647 if (iter == devices_.end()) {
639 return nil; 648 return nil;
640 } 649 }
641 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 650 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
642 } 651 }
643 652
644 } // namespace device 653 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698