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

Unified Diff: device/bluetooth/bluetooth_adapter_mac.mm

Issue 1229473005: BluetoothAdapterMac::LowEnergyDeviceUpdated() Implemented (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hash
Patch Set: s/advertisementData/advertisement_data Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_adapter_mac.mm
diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
index d91c579cb496dc522942aabb5b2209508f552f41..b4b2720a616b0f1dab4c23435d5157a8763b6655 100644
--- a/device/bluetooth/bluetooth_adapter_mac.mm
+++ b/device/bluetooth/bluetooth_adapter_mac.mm
@@ -402,11 +402,42 @@ void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) {
DeviceAdded(this, devices_[device_address]));
}
-// TODO(krstnmnlsn): Implement method. http://crbug.com/496987.
void BluetoothAdapterMac::LowEnergyDeviceUpdated(
CBPeripheral* peripheral,
NSDictionary* advertisement_data,
- int rssi) {}
+ int rssi) {
+ std::string device_address =
+ BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
+ // Get a reference to the actual device pointer held by |devices_| (if
+ // |device_address| has no entry in the map a NULL pointer is created by the
+ // std::map [] operator).
+ BluetoothDevice*& device_reference = devices_[device_address];
+ if (!device_reference) {
+ // A new device has been found.
+ device_reference =
+ new BluetoothLowEnergyDeviceMac(peripheral, advertisement_data, rssi);
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
+ DeviceAdded(this, device_reference));
+ return;
+ }
+
+ if (static_cast<BluetoothLowEnergyDeviceMac*>(device_reference)
+ ->GetIdentifier() !=
+ BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(peripheral)) {
+ // Collision, two identifiers map to the same hash address. With a 48 bit
+ // hash the probability of this occuring with 10,000 devices
+ // simultaneously present is 1e-6 (see
+ // https://en.wikipedia.org/wiki/Birthday_problem#Probability_table). We
+ // ignore the second device by returning.
+ return;
+ }
+
+ // A device has an update.
+ static_cast<BluetoothLowEnergyDeviceMac*>(device_reference)
+ ->Update(peripheral, advertisement_data, rssi);
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
+ DeviceChanged(this, device_reference));
+}
void BluetoothAdapterMac::RemoveTimedOutDevices() {
// Notify observers if any previously seen devices are no longer available,
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698