summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_adapter_android.cc
diff options
context:
space:
mode:
authorleon.han <leon.han@intel.com>2015-10-07 08:51:33 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-07 15:52:30 +0000
commit8685e05b627bb2e7ab0d4b3593272c71c375feb5 (patch)
treece020061a0b7090b26b12c26ddcb8075438295ed /device/bluetooth/bluetooth_adapter_android.cc
parent1ad34057f05597b29de0f3231afd2419eddad1dd (diff)
downloadchromium_src-8685e05b627bb2e7ab0d4b3593272c71c375feb5.zip
chromium_src-8685e05b627bb2e7ab0d4b3593272c71c375feb5.tar.gz
chromium_src-8685e05b627bb2e7ab0d4b3593272c71c375feb5.tar.bz2
Bluetooth: Store devices_ in BluetoothAdapter with scoped pointers.
This CL uses ScopedPtrMap to store devices_ in BluetoothAdapter. Currently raw pointers are stored and require manual deletion. BUG=506416 Review URL: https://codereview.chromium.org/1343933004 Cr-Commit-Position: refs/heads/master@{#352848}
Diffstat (limited to 'device/bluetooth/bluetooth_adapter_android.cc')
-rw-r--r--device/bluetooth/bluetooth_adapter_android.cc24
1 files changed, 15 insertions, 9 deletions
diff --git a/device/bluetooth/bluetooth_adapter_android.cc b/device/bluetooth/bluetooth_adapter_android.cc
index 9f39e4c..c0a972ba 100644
--- a/device/bluetooth/bluetooth_adapter_android.cc
+++ b/device/bluetooth/bluetooth_adapter_android.cc
@@ -139,18 +139,24 @@ void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan(
const jstring& address,
jobject bluetooth_device_wrapper, // Java Type: bluetoothDeviceWrapper
jobject advertised_uuids) { // Java Type: List<ParcelUuid>
- BluetoothDevice*& device = devices_[ConvertJavaStringToUTF8(env, address)];
- if (!device) {
- device = BluetoothDeviceAndroid::Create(this, bluetooth_device_wrapper);
- static_cast<BluetoothDeviceAndroid*>(device)
- ->UpdateAdvertisedUUIDs(advertised_uuids);
+ std::string device_address = ConvertJavaStringToUTF8(env, address);
+ DevicesMap::const_iterator iter = devices_.find(device_address);
+
+ if (iter == devices_.end()) {
+ // New device.
+ BluetoothDeviceAndroid* device_android =
+ BluetoothDeviceAndroid::Create(this, bluetooth_device_wrapper);
+ device_android->UpdateAdvertisedUUIDs(advertised_uuids);
+ devices_.add(device_address, scoped_ptr<BluetoothDevice>(device_android));
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceAdded(this, device));
+ DeviceAdded(this, device_android));
} else {
- if (static_cast<BluetoothDeviceAndroid*>(device)
- ->UpdateAdvertisedUUIDs(advertised_uuids)) {
+ // Existing device.
+ BluetoothDeviceAndroid* device_android =
+ static_cast<BluetoothDeviceAndroid*>(iter->second);
+ if (device_android->UpdateAdvertisedUUIDs(advertised_uuids)) {
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceChanged(this, device));
+ DeviceChanged(this, device_android));
}
}
}