Index: device/bluetooth/bluetooth_adapter_chromeos.cc |
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc |
index e6c628322d349b629b507b17f753d8d541b35955..6fe0a31c921c9ad920c636031321e57cd7452bcc 100644 |
--- a/device/bluetooth/bluetooth_adapter_chromeos.cc |
+++ b/device/bluetooth/bluetooth_adapter_chromeos.cc |
@@ -85,6 +85,9 @@ void BluetoothAdapterChromeOS::Shutdown() { |
if (IsPresent()) |
RemoveAdapter(); // Also deletes devices_. |
DCHECK(devices_.empty()); |
+ // profiles_ should be empty because all BluetoothSockets have been signaled |
+ // that this adapter is disappearing. |
+ DCHECK(profiles_.empty()); |
armansito
2015/02/27 21:04:57
Do you need a DCHECK for |profile_queues_| being e
Marie Janssen
2015/02/27 22:56:06
Done.
|
DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this); |
DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); |
@@ -963,15 +966,33 @@ void BluetoothAdapterChromeOS::UseProfile( |
return; |
} |
- profiles_[uuid] = BluetoothAdapterProfileChromeOS::Register( |
- this, uuid, options, |
- base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfile, this, uuid, |
+ if (profile_queues_.find(uuid) == profile_queues_.end()) { |
+ BluetoothAdapterProfileChromeOS::Register( |
+ uuid, options, |
+ base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfile, this, uuid), |
+ base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfileError, this, |
+ uuid)); |
+ |
+ profile_queues_[uuid] = new std::vector<RegisterProfileCompletionPair>(); |
+ } |
+ |
+ profile_queues_[uuid]->push_back(std::make_pair( |
+ base::Bind(&BluetoothAdapterChromeOS::SetProfileDelegate, this, uuid, |
device_path, delegate, success_callback, error_callback), |
- base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfileError, this, uuid, |
- error_callback)); |
+ error_callback)); |
} |
-void BluetoothAdapterChromeOS::ReleaseProfile(const BluetoothUUID& uuid) { |
+void BluetoothAdapterChromeOS::ReleaseProfile( |
+ const dbus::ObjectPath& device_path, |
+ BluetoothAdapterProfileChromeOS* profile) { |
+ VLOG(2) << "Releasing Profile: " << profile->uuid().canonical_value() |
+ << " from " << device_path.value(); |
+ profile->RemoveDelegate( |
+ device_path, base::Bind(&BluetoothAdapterChromeOS::RemoveProfile, |
+ weak_ptr_factory_.GetWeakPtr(), profile->uuid())); |
+} |
+ |
+void BluetoothAdapterChromeOS::RemoveProfile(const BluetoothUUID& uuid) { |
if (profiles_.find(uuid) != profiles_.end()) { |
delete profiles_[uuid]; |
profiles_.erase(uuid); |
@@ -980,15 +1001,16 @@ void BluetoothAdapterChromeOS::ReleaseProfile(const BluetoothUUID& uuid) { |
void BluetoothAdapterChromeOS::OnRegisterProfile( |
const BluetoothUUID& uuid, |
- const dbus::ObjectPath& device_path, |
- BluetoothProfileServiceProvider::Delegate* delegate, |
- const ProfileRegisteredCallback& success_callback, |
- const ErrorCompletionCallback& error_callback) { |
- SetProfileDelegate(uuid, device_path, delegate, success_callback, |
- error_callback); |
+ BluetoothAdapterProfileChromeOS* profile) { |
+ profiles_[uuid] = profile; |
+ for (auto& it : *profile_queues_[uuid]) { |
+ it.first.Run(); |
+ } |
+ delete profile_queues_[uuid]; |
+ profile_queues_.erase(uuid); |
} |
-bool BluetoothAdapterChromeOS::SetProfileDelegate( |
+void BluetoothAdapterChromeOS::SetProfileDelegate( |
const BluetoothUUID& uuid, |
const dbus::ObjectPath& device_path, |
BluetoothProfileServiceProvider::Delegate* delegate, |
@@ -996,23 +1018,23 @@ bool BluetoothAdapterChromeOS::SetProfileDelegate( |
const ErrorCompletionCallback& error_callback) { |
if (profiles_[uuid]->SetDelegate(device_path, delegate)) { |
success_callback.Run(profiles_[uuid]); |
- return true; |
+ return; |
} |
// Already set |
error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists); |
- return false; |
} |
void BluetoothAdapterChromeOS::OnRegisterProfileError( |
const BluetoothUUID& uuid, |
- const ErrorCompletionCallback& error_callback, |
const std::string& error_name, |
const std::string& error_message) { |
- LOG(WARNING) << object_path_.value() |
- << ": Failed to register profile: " << error_name << ": " |
- << error_message; |
- error_callback.Run(error_message); |
- ReleaseProfile(uuid); |
+ VLOG(2) << object_path_.value() << ": Failed to register profile: " |
+ << error_name << ": " << error_message; |
+ for (auto& it : *profile_queues_[uuid]) { |
+ it.second.Run(error_message); |
+ } |
armansito
2015/02/27 21:04:57
nit: no need for curly braces in single-line if bo
Marie Janssen
2015/02/27 22:56:06
Done.
|
+ delete profile_queues_[uuid]; |
+ profile_queues_.erase(uuid); |
} |
void BluetoothAdapterChromeOS::OnSetDiscoverable( |