Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1812)

Unified Diff: device/bluetooth/bluez/bluetooth_adapter_bluez.cc

Issue 1908253005: Bluez: Move released profiles to a separate map. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluez/bluetooth_adapter_bluez.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluez/bluetooth_adapter_bluez.cc
diff --git a/device/bluetooth/bluez/bluetooth_adapter_bluez.cc b/device/bluetooth/bluez/bluetooth_adapter_bluez.cc
index 4742310d33c8f41246ca7bd73d7dc3140fa4e1dd..758e6b6f3d96176c88d10dfd5e0f096f25d2eb79 100644
--- a/device/bluetooth/bluez/bluetooth_adapter_bluez.cc
+++ b/device/bluetooth/bluez/bluetooth_adapter_bluez.cc
@@ -123,10 +123,17 @@ void BluetoothAdapterBlueZ::Shutdown() {
if (IsPresent())
RemoveAdapter(); // Also deletes devices_.
DCHECK(devices_.empty());
- // profiles_ is empty because all BluetoothSockets have been notified
+
+ // profiles_ must be empty because all BluetoothSockets have been notified
// that this adapter is disappearing.
DCHECK(profiles_.empty());
+ // Some profiles may have been released but not yet removed; it is safe to
+ // delete them.
+ for (auto& it : released_profiles_)
+ delete it.second;
+ released_profiles_.clear();
+
for (auto& it : profile_queues_)
delete it.second;
profile_queues_.clear();
@@ -1009,18 +1016,29 @@ void BluetoothAdapterBlueZ::ReleaseProfile(
BluetoothAdapterProfileBlueZ* profile) {
VLOG(2) << "Releasing Profile: " << profile->uuid().canonical_value()
<< " from " << device_path.value();
- profile->RemoveDelegate(
- device_path, base::Bind(&BluetoothAdapterBlueZ::RemoveProfile,
- weak_ptr_factory_.GetWeakPtr(), profile->uuid()));
+ BluetoothUUID uuid = profile->uuid();
+ auto iter = profiles_.find(uuid);
+ if (iter == profiles_.end()) {
+ LOG(ERROR) << "Profile not found for: " << uuid.canonical_value();
+ return;
+ }
+ released_profiles_[uuid] = iter->second;
+ profiles_.erase(iter);
+ profile->RemoveDelegate(device_path,
+ base::Bind(&BluetoothAdapterBlueZ::RemoveProfile,
+ weak_ptr_factory_.GetWeakPtr(), uuid));
}
void BluetoothAdapterBlueZ::RemoveProfile(const BluetoothUUID& uuid) {
VLOG(2) << "Remove Profile: " << uuid.canonical_value();
- if (profiles_.find(uuid) != profiles_.end()) {
- delete profiles_[uuid];
- profiles_.erase(uuid);
+ auto iter = released_profiles_.find(uuid);
+ if (iter == released_profiles_.end()) {
+ LOG(ERROR) << "Released Profile not found: " << uuid.canonical_value();
+ return;
}
+ delete iter->second;
+ released_profiles_.erase(iter);
}
void BluetoothAdapterBlueZ::AddLocalGattService(
« no previous file with comments | « device/bluetooth/bluez/bluetooth_adapter_bluez.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698