Index: device/bluetooth/bluetooth_adapter_mac.mm |
diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm |
index a528bd7229bee3d5f7a8b037c38614d050f336af..84ca76b4b6b07455398a024e3d925a721c5bb90e 100644 |
--- a/device/bluetooth/bluetooth_adapter_mac.mm |
+++ b/device/bluetooth/bluetooth_adapter_mac.mm |
@@ -252,7 +252,6 @@ void BluetoothAdapterMac::PollAdapter() { |
FROM_HERE_WITH_EXPLICIT_FUNCTION( |
"461181 BluetoothAdapterMac::PollAdapter::Start")); |
bool was_present = IsPresent(); |
- std::string name; |
std::string address; |
bool powered = false; |
IOBluetoothHostController* controller = |
@@ -264,14 +263,21 @@ void BluetoothAdapterMac::PollAdapter() { |
FROM_HERE_WITH_EXPLICIT_FUNCTION( |
"461181 BluetoothAdapterMac::PollAdapter::GetControllerStats")); |
if (controller != nil) { |
- name = base::SysNSStringToUTF8([controller nameAsString]); |
address = BluetoothDevice::CanonicalizeAddress( |
base::SysNSStringToUTF8([controller addressAsString])); |
powered = ([controller powerState] == kBluetoothHCIPowerStateON); |
+ |
+ // For performance reasons, cache the adapter's name. It's not uncommon for |
+ // a call to [controller nameAsString] to take tens of milliseconds. Note |
+ // that this caching strategy might result in clients receiving a stale |
+ // name. If this is a significant issue, then some more sophisticated |
+ // workaround for the performance bottleneck will be needed. For additional |
+ // context, see http://crbug.com/461181 and http://crbug.com/467316 |
+ if (name_.empty()) |
scheib
2015/04/28 17:55:39
" || address_ != address" will at least catch adap
Ilya Sherman
2015/04/28 23:42:26
Good idea. Done.
|
+ name_ = base::SysNSStringToUTF8([controller nameAsString]); |
} |
bool is_present = !address.empty(); |
- name_ = name; |
address_ = address; |
// TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 |