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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_mac_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9
10 #include <string> 10 #include <string>
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // Only notify observers once per device. 381 // Only notify observers once per device.
382 if (devices_.count(device_address)) 382 if (devices_.count(device_address))
383 return; 383 return;
384 384
385 devices_[device_address] = new BluetoothClassicDeviceMac(device); 385 devices_[device_address] = new BluetoothClassicDeviceMac(device);
386 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, 386 FOR_EACH_OBSERVER(BluetoothAdapter::Observer,
387 observers_, 387 observers_,
388 DeviceAdded(this, devices_[device_address])); 388 DeviceAdded(this, devices_[device_address]));
389 } 389 }
390 390
391 // TODO(krstnmnlsn): Implement method. http://crbug.com/496987.
392 void BluetoothAdapterMac::LowEnergyDeviceUpdated( 391 void BluetoothAdapterMac::LowEnergyDeviceUpdated(
393 CBPeripheral* peripheral, 392 CBPeripheral* peripheral,
394 NSDictionary* advertisementData, 393 NSDictionary* advertisementData,
395 int rssi) { 394 int rssi) {
395 std::string device_address =
396 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
397
398 if (devices_.count(device_address)) {
scheib 2015/07/08 05:20:36 Push back if you like, but here's my take on testi
krstnmnlsn 2015/07/13 17:26:23 Done.
399 if (devices_[device_address]->GetIdentifier() !=
400 BluetoothLowEnergyDeviceMac::GetPeripheralIdentifier(peripheral)) {
401 // Collision, two identifiers map to the same hash address. With a 48 bit
402 // hash the probability of this occuring with 10,000 devices
403 // simultaneously present is 1e-6, so we simply return.
scheib 2015/07/08 05:20:36 Cite the source for those numbers. Also explain ha
krstnmnlsn 2015/07/13 17:26:23 Done.
404 return;
405 }
406 // A device has an update.
407 BluetoothLowEnergyDeviceMac* old_device =
408 static_cast<BluetoothLowEnergyDeviceMac*>(devices_[device_address]);
409 old_device->Update(peripheral, advertisementData, rssi);
410 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
scheib 2015/07/08 05:20:36 I think only call DeviceChanged if data about the
krstnmnlsn 2015/07/13 17:26:23 (after offline discussion) leaving this for now, a
scheib 2015/07/13 18:24:39 Acknowledged.
411 DeviceChanged(this, old_device));
412 return;
413 }
414
415 // A new device has been found.
416 devices_[device_address] =
417 new BluetoothLowEnergyDeviceMac(peripheral, advertisementData, rssi);
418 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
419 DeviceAdded(this, devices_[device_address]));
396 } 420 }
397 421
398 void BluetoothAdapterMac::RemoveTimedOutDevices() { 422 void BluetoothAdapterMac::RemoveTimedOutDevices() {
399 // Notify observers if any previously seen devices are no longer available, 423 // Notify observers if any previously seen devices are no longer available,
400 // i.e. if they are no longer paired, connected, nor recently discovered via 424 // i.e. if they are no longer paired, connected, nor recently discovered via
401 // an inquiry. 425 // an inquiry.
402 std::set<std::string> removed_devices; 426 std::set<std::string> removed_devices;
403 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end(); ++it) { 427 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end(); ++it) {
404 BluetoothDevice* device = it->second; 428 BluetoothDevice* device = it->second;
405 if (device->IsPaired() || device->IsConnected()) 429 if (device->IsPaired() || device->IsConnected())
(...skipping 18 matching lines...) Expand all
424 } 448 }
425 449
426 void BluetoothAdapterMac::AddPairedDevices() { 450 void BluetoothAdapterMac::AddPairedDevices() {
427 // Add any new paired devices. 451 // Add any new paired devices.
428 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { 452 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) {
429 ClassicDeviceAdded(device); 453 ClassicDeviceAdded(device);
430 } 454 }
431 } 455 }
432 456
433 } // namespace device 457 } // namespace device
OLDNEW
« 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