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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « device/bluetooth/bluez/bluetooth_adapter_bluez.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bluez/bluetooth_adapter_bluez.h" 5 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // Since we don't initialize anything if Object Manager is not supported, 116 // Since we don't initialize anything if Object Manager is not supported,
117 // no need to do any clean up. 117 // no need to do any clean up.
118 if (!bluez::BluezDBusManager::Get()->IsObjectManagerSupported()) { 118 if (!bluez::BluezDBusManager::Get()->IsObjectManagerSupported()) {
119 dbus_is_shutdown_ = true; 119 dbus_is_shutdown_ = true;
120 return; 120 return;
121 } 121 }
122 122
123 if (IsPresent()) 123 if (IsPresent())
124 RemoveAdapter(); // Also deletes devices_. 124 RemoveAdapter(); // Also deletes devices_.
125 DCHECK(devices_.empty()); 125 DCHECK(devices_.empty());
126 // profiles_ is empty because all BluetoothSockets have been notified 126
127 // profiles_ must be empty because all BluetoothSockets have been notified
127 // that this adapter is disappearing. 128 // that this adapter is disappearing.
128 DCHECK(profiles_.empty()); 129 DCHECK(profiles_.empty());
129 130
131 // Some profiles may have been released but not yet removed; it is safe to
132 // delete them.
133 for (auto& it : released_profiles_)
134 delete it.second;
135 released_profiles_.clear();
136
130 for (auto& it : profile_queues_) 137 for (auto& it : profile_queues_)
131 delete it.second; 138 delete it.second;
132 profile_queues_.clear(); 139 profile_queues_.clear();
133 140
134 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveObserver( 141 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(
135 this); 142 this);
136 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->RemoveObserver( 143 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(
137 this); 144 this);
138 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->RemoveObserver( 145 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->RemoveObserver(
139 this); 146 this);
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 base::Bind(&BluetoothAdapterBlueZ::SetProfileDelegate, this, uuid, 1009 base::Bind(&BluetoothAdapterBlueZ::SetProfileDelegate, this, uuid,
1003 device_path, delegate, success_callback, error_callback), 1010 device_path, delegate, success_callback, error_callback),
1004 error_callback)); 1011 error_callback));
1005 } 1012 }
1006 1013
1007 void BluetoothAdapterBlueZ::ReleaseProfile( 1014 void BluetoothAdapterBlueZ::ReleaseProfile(
1008 const dbus::ObjectPath& device_path, 1015 const dbus::ObjectPath& device_path,
1009 BluetoothAdapterProfileBlueZ* profile) { 1016 BluetoothAdapterProfileBlueZ* profile) {
1010 VLOG(2) << "Releasing Profile: " << profile->uuid().canonical_value() 1017 VLOG(2) << "Releasing Profile: " << profile->uuid().canonical_value()
1011 << " from " << device_path.value(); 1018 << " from " << device_path.value();
1012 profile->RemoveDelegate( 1019 BluetoothUUID uuid = profile->uuid();
1013 device_path, base::Bind(&BluetoothAdapterBlueZ::RemoveProfile, 1020 auto iter = profiles_.find(uuid);
1014 weak_ptr_factory_.GetWeakPtr(), profile->uuid())); 1021 if (iter == profiles_.end()) {
1022 LOG(ERROR) << "Profile not found for: " << uuid.canonical_value();
1023 return;
1024 }
1025 released_profiles_[uuid] = iter->second;
1026 profiles_.erase(iter);
1027 profile->RemoveDelegate(device_path,
1028 base::Bind(&BluetoothAdapterBlueZ::RemoveProfile,
1029 weak_ptr_factory_.GetWeakPtr(), uuid));
1015 } 1030 }
1016 1031
1017 void BluetoothAdapterBlueZ::RemoveProfile(const BluetoothUUID& uuid) { 1032 void BluetoothAdapterBlueZ::RemoveProfile(const BluetoothUUID& uuid) {
1018 VLOG(2) << "Remove Profile: " << uuid.canonical_value(); 1033 VLOG(2) << "Remove Profile: " << uuid.canonical_value();
1019 1034
1020 if (profiles_.find(uuid) != profiles_.end()) { 1035 auto iter = released_profiles_.find(uuid);
1021 delete profiles_[uuid]; 1036 if (iter == released_profiles_.end()) {
1022 profiles_.erase(uuid); 1037 LOG(ERROR) << "Released Profile not found: " << uuid.canonical_value();
1038 return;
1023 } 1039 }
1040 delete iter->second;
1041 released_profiles_.erase(iter);
1024 } 1042 }
1025 1043
1026 void BluetoothAdapterBlueZ::AddLocalGattService( 1044 void BluetoothAdapterBlueZ::AddLocalGattService(
1027 std::unique_ptr<BluetoothLocalGattServiceBlueZ> service) { 1045 std::unique_ptr<BluetoothLocalGattServiceBlueZ> service) {
1028 owned_gatt_services_.push_back(std::move(service)); 1046 owned_gatt_services_.push_back(std::move(service));
1029 } 1047 }
1030 1048
1031 void BluetoothAdapterBlueZ::OnRegisterProfile( 1049 void BluetoothAdapterBlueZ::OnRegisterProfile(
1032 const BluetoothUUID& uuid, 1050 const BluetoothUUID& uuid,
1033 std::unique_ptr<BluetoothAdapterProfileBlueZ> profile) { 1051 std::unique_ptr<BluetoothAdapterProfileBlueZ> profile) {
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 1474
1457 // If the queued request resulted in a pending call, then let it 1475 // If the queued request resulted in a pending call, then let it
1458 // asynchonously process the remaining queued requests once the pending 1476 // asynchonously process the remaining queued requests once the pending
1459 // call returns. 1477 // call returns.
1460 if (discovery_request_pending_) 1478 if (discovery_request_pending_)
1461 return; 1479 return;
1462 } 1480 }
1463 } 1481 }
1464 1482
1465 } // namespace bluez 1483 } // namespace bluez
OLDNEW
« 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