| 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 #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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 PollAdapter(); | 245 PollAdapter(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void BluetoothAdapterMac::PollAdapter() { | 248 void BluetoothAdapterMac::PollAdapter() { |
| 249 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 | 249 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 |
| 250 // is fixed. | 250 // is fixed. |
| 251 tracked_objects::ScopedTracker tracking_profile1( | 251 tracked_objects::ScopedTracker tracking_profile1( |
| 252 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 252 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 253 "461181 BluetoothAdapterMac::PollAdapter::Start")); | 253 "461181 BluetoothAdapterMac::PollAdapter::Start")); |
| 254 bool was_present = IsPresent(); | 254 bool was_present = IsPresent(); |
| 255 std::string name; | |
| 256 std::string address; | 255 std::string address; |
| 257 bool powered = false; | 256 bool powered = false; |
| 258 IOBluetoothHostController* controller = | 257 IOBluetoothHostController* controller = |
| 259 [IOBluetoothHostController defaultController]; | 258 [IOBluetoothHostController defaultController]; |
| 260 | 259 |
| 261 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 | 260 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 |
| 262 // is fixed. | 261 // is fixed. |
| 263 tracked_objects::ScopedTracker tracking_profile2( | 262 tracked_objects::ScopedTracker tracking_profile2( |
| 264 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 263 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 265 "461181 BluetoothAdapterMac::PollAdapter::GetControllerStats")); | 264 "461181 BluetoothAdapterMac::PollAdapter::GetControllerStats")); |
| 266 if (controller != nil) { | 265 if (controller != nil) { |
| 267 name = base::SysNSStringToUTF8([controller nameAsString]); | |
| 268 address = BluetoothDevice::CanonicalizeAddress( | 266 address = BluetoothDevice::CanonicalizeAddress( |
| 269 base::SysNSStringToUTF8([controller addressAsString])); | 267 base::SysNSStringToUTF8([controller addressAsString])); |
| 270 powered = ([controller powerState] == kBluetoothHCIPowerStateON); | 268 powered = ([controller powerState] == kBluetoothHCIPowerStateON); |
| 269 |
| 270 // For performance reasons, cache the adapter's name. It's not uncommon for |
| 271 // a call to [controller nameAsString] to take tens of milliseconds. Note |
| 272 // that this caching strategy might result in clients receiving a stale |
| 273 // name. If this is a significant issue, then some more sophisticated |
| 274 // workaround for the performance bottleneck will be needed. For additional |
| 275 // context, see http://crbug.com/461181 and http://crbug.com/467316 |
| 276 if (address != address_ || (!address.empty() && name_.empty())) |
| 277 name_ = base::SysNSStringToUTF8([controller nameAsString]); |
| 271 } | 278 } |
| 272 | 279 |
| 273 bool is_present = !address.empty(); | 280 bool is_present = !address.empty(); |
| 274 name_ = name; | |
| 275 address_ = address; | 281 address_ = address; |
| 276 | 282 |
| 277 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 | 283 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 |
| 278 // is fixed. | 284 // is fixed. |
| 279 tracked_objects::ScopedTracker tracking_profile3( | 285 tracked_objects::ScopedTracker tracking_profile3( |
| 280 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 286 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 281 "461181 BluetoothAdapterMac::PollAdapter::AdapterPresentChanged")); | 287 "461181 BluetoothAdapterMac::PollAdapter::AdapterPresentChanged")); |
| 282 if (was_present != is_present) { | 288 if (was_present != is_present) { |
| 283 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 289 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 284 AdapterPresentChanged(this, is_present)); | 290 AdapterPresentChanged(this, is_present)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 DCHECK_EQ(num_removed, 1U); | 355 DCHECK_EQ(num_removed, 1U); |
| 350 } | 356 } |
| 351 | 357 |
| 352 // Add any new paired devices. | 358 // Add any new paired devices. |
| 353 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { | 359 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { |
| 354 DeviceAdded(device); | 360 DeviceAdded(device); |
| 355 } | 361 } |
| 356 } | 362 } |
| 357 | 363 |
| 358 } // namespace device | 364 } // namespace device |
| OLD | NEW |