Index: device/bluetooth/bluetooth_adapter_mac.mm |
diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm |
index 5d964ccbf9f31fa7d3a9fe2329d61d9b048aef20..194adb364f2ac3f7a7456df9d82eea165c5b42c8 100644 |
--- a/device/bluetooth/bluetooth_adapter_mac.mm |
+++ b/device/bluetooth/bluetooth_adapter_mac.mm |
@@ -4,18 +4,21 @@ |
#include "device/bluetooth/bluetooth_adapter_mac.h" |
-#include <IOBluetooth/objc/IOBluetoothHostController.h> |
+#import <IObluetooth/objc/IOBluetoothDevice.h> |
Mark Mentovai
2013/03/19 16:04:35
Fix capitalization. This only works because you’re
youngki
2013/03/19 19:04:55
Sorry about this; done.
|
+#import <IOBluetooth/objc/IOBluetoothHostController.h> |
#include <string> |
#include "base/bind.h" |
#include "base/compiler_specific.h" |
+#include "base/hash_tables.h" |
#include "base/location.h" |
#include "base/sequenced_task_runner.h" |
#include "base/single_thread_task_runner.h" |
#include "base/thread_task_runner_handle.h" |
#include "base/time.h" |
#include "base/strings/sys_string_conversions.h" |
+#include "device/bluetooth/bluetooth_device_mac.h" |
// Replicate specific 10.7 SDK declarations for building with prior SDKs. |
#if !defined(MAC_OS_X_VERSION_10_7) || \ |
@@ -133,6 +136,8 @@ void BluetoothAdapterMac::PollAdapter() { |
AdapterPoweredChanged(this, powered_)); |
} |
+ UpdateDevices([IOBluetoothDevice recentDevices:0]); |
+ |
ui_task_runner_->PostDelayedTask( |
FROM_HERE, |
base::Bind(&BluetoothAdapterMac::PollAdapter, |
@@ -140,4 +145,54 @@ void BluetoothAdapterMac::PollAdapter() { |
base::TimeDelta::FromMilliseconds(kPollIntervalMs)); |
} |
+void BluetoothAdapterMac::UpdateDevices(NSArray* devices) { |
+ base::hash_set<std::string> device_address_list; |
+ // Check if |devices| contains new or updated devices. |
+ for (IOBluetoothDevice* device in devices) { |
+ std::string device_address = |
+ base::SysNSStringToUTF8([device addressString]); |
+ device_address_list.insert(device_address); |
+ DevicesMap::iterator found_device_iter = devices_.find(device_address); |
+ |
+ if (found_device_iter == devices_.end()) { |
+ devices_[device_address] = new BluetoothDeviceMac(device); |
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
+ DeviceAdded(this, devices_[device_address])); |
+ continue; |
+ } |
+ BluetoothDeviceMac* device_mac = |
+ static_cast<BluetoothDeviceMac*>(found_device_iter->second); |
+ if (device_mac->device_fingerprint() != |
+ BluetoothDeviceMac::ComputeDeviceFingerprint(device)) { |
+ devices_[device_address] = new BluetoothDeviceMac(device); |
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
+ DeviceChanged(this, devices_[device_address])); |
+ delete device_mac; |
+ } |
+ } |
+ |
+ // Remove devices that are no longer known by the system. |
Mark Mentovai
2013/03/19 16:04:35
How does something become unknown by the system? T
youngki
2013/03/19 19:04:55
So.. the documentation didn't say that since when
Mark Mentovai
2013/03/19 19:14:20
I don’t know if it’s right to remove it. I wasn’t
youngki
2013/03/20 18:48:26
I actually reviewed the documentations about Bluet
|
+ DevicesMap::iterator device_iter = devices_.begin(); |
+ while (device_iter != devices_.end()) { |
+ DevicesMap::iterator temp = device_iter; |
Mark Mentovai
2013/03/19 16:04:35
This isn’t really temporary at all, you use it thr
youngki
2013/03/19 19:04:55
I removed the code because this is no longer neces
|
+ ++device_iter; |
+ |
+ if (device_address_list.find(temp->first) != device_address_list.end()) |
+ continue; |
+ |
+ if (temp->second->IsConnected() || temp->second->IsPaired()) { |
+ BluetoothDeviceMac* device_mac = |
Mark Mentovai
2013/03/19 16:04:35
Pull this out of the enclosing conditional, so tha
youngki
2013/03/19 19:04:55
I removed the code because this is no longer neces
|
+ static_cast<BluetoothDeviceMac*>(temp->second); |
+ device_mac->SetVisible(false); |
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
+ DeviceChanged(this, device_mac)); |
Mark Mentovai
2013/03/19 16:04:35
…but it’s not in “devices,” so will it ever be cle
youngki
2013/03/19 19:04:55
I removed the code because this is no longer neces
|
+ continue; |
+ } |
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
+ DeviceRemoved(this, temp->second)); |
+ delete temp->second; |
+ devices_.erase(temp); |
+ } |
+} |
+ |
} // namespace device |