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

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: moving 'return' 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 cf33939b61c4902c156f616a9e554e1fbabc6469..d7c6c41a54e99855d7e406f6f6f3ac4f717de335 100644
--- a/device/bluetooth/bluetooth_adapter_mac.mm
+++ b/device/bluetooth/bluetooth_adapter_mac.mm
@@ -402,11 +402,39 @@ void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) {
DeviceAdded(this, devices_[device_address]));
}
-// TODO(krstnmnlsn): Implement method. http://crbug.com/496987.
void BluetoothAdapterMac::LowEnergyDeviceUpdated(
CBPeripheral* peripheral,
NSDictionary* advertisementData,
int rssi) {
+ std::string device_address =
+ BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
+ BluetoothDevice*& device_reference = devices_[device_address];
+
+ if (!device_reference) {
+ // A new device has been found.
+ device_reference =
+ new BluetoothLowEnergyDeviceMac(peripheral, advertisementData, rssi);
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
+ DeviceAdded(this, device_reference));
+ return;
+
+ } else {
scheib 2015/07/13 20:47:21 OK, if you're going with early returns then we don
krstnmnlsn 2015/07/13 20:54:34 Done.
+ 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, advertisementData, rssi);
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
+ DeviceChanged(this, device_reference));
+ }
}
void BluetoothAdapterMac::RemoveTimedOutDevices() {
« 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