OLD | NEW |
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 #include <IOBluetooth/objc/IOBluetoothHostController.h> | 7 #import <IOBluetooth/objc/IOBluetoothDevice.h> |
| 8 #import <IOBluetooth/objc/IOBluetoothHostController.h> |
8 | 9 |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
13 #include "base/location.h" | 14 #include "base/location.h" |
14 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
17 #include "base/time.h" | 18 #include "base/time.h" |
18 #include "base/strings/sys_string_conversions.h" | 19 #include "base/strings/sys_string_conversions.h" |
| 20 #include "device/bluetooth/bluetooth_device_mac.h" |
19 | 21 |
20 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | 22 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
21 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 23 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
22 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 24 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
23 | 25 |
24 @interface IOBluetoothHostController (LionSDKDeclarations) | 26 @interface IOBluetoothHostController (LionSDKDeclarations) |
25 - (NSString *)nameAsString; | 27 - (NSString *)nameAsString; |
26 - (BluetoothHCIPowerState)powerState; | 28 - (BluetoothHCIPowerState)powerState; |
27 @end | 29 @end |
28 | 30 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 if (was_present != is_present) { | 128 if (was_present != is_present) { |
127 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 129 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
128 AdapterPresentChanged(this, is_present)); | 130 AdapterPresentChanged(this, is_present)); |
129 } | 131 } |
130 if (powered_ != powered) { | 132 if (powered_ != powered) { |
131 powered_ = powered; | 133 powered_ = powered; |
132 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 134 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
133 AdapterPoweredChanged(this, powered_)); | 135 AdapterPoweredChanged(this, powered_)); |
134 } | 136 } |
135 | 137 |
| 138 UpdateDevices([IOBluetoothDevice recentDevices:0]); |
| 139 |
136 ui_task_runner_->PostDelayedTask( | 140 ui_task_runner_->PostDelayedTask( |
137 FROM_HERE, | 141 FROM_HERE, |
138 base::Bind(&BluetoothAdapterMac::PollAdapter, | 142 base::Bind(&BluetoothAdapterMac::PollAdapter, |
139 weak_ptr_factory_.GetWeakPtr()), | 143 weak_ptr_factory_.GetWeakPtr()), |
140 base::TimeDelta::FromMilliseconds(kPollIntervalMs)); | 144 base::TimeDelta::FromMilliseconds(kPollIntervalMs)); |
141 } | 145 } |
142 | 146 |
| 147 void BluetoothAdapterMac::UpdateDevices(NSArray* devices) { |
| 148 for (IOBluetoothDevice* device in devices) { |
| 149 std::string device_address = |
| 150 base::SysNSStringToUTF8([device addressString]); |
| 151 DevicesMap::iterator found_device_iter = devices_.find(device_address); |
| 152 |
| 153 if (found_device_iter == devices_.end()) { |
| 154 devices_[device_address] = new BluetoothDeviceMac(device); |
| 155 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 156 DeviceAdded(this, devices_[device_address])); |
| 157 continue; |
| 158 } |
| 159 BluetoothDeviceMac* device_mac = |
| 160 static_cast<BluetoothDeviceMac*>(found_device_iter->second); |
| 161 if (device_mac->device_fingerprint() != |
| 162 BluetoothDeviceMac::ComputeDeviceFingerprint(device)) { |
| 163 devices_[device_address] = new BluetoothDeviceMac(device); |
| 164 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 165 DeviceChanged(this, devices_[device_address])); |
| 166 delete device_mac; |
| 167 } |
| 168 } |
| 169 } |
| 170 |
143 } // namespace device | 171 } // namespace device |
OLD | NEW |