summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_discovery_session.cc
diff options
context:
space:
mode:
Diffstat (limited to 'device/bluetooth/bluetooth_discovery_session.cc')
-rw-r--r--device/bluetooth/bluetooth_discovery_session.cc34
1 files changed, 24 insertions, 10 deletions
diff --git a/device/bluetooth/bluetooth_discovery_session.cc b/device/bluetooth/bluetooth_discovery_session.cc
index e30f86c..c80012e 100644
--- a/device/bluetooth/bluetooth_discovery_session.cc
+++ b/device/bluetooth/bluetooth_discovery_session.cc
@@ -197,26 +197,40 @@ bool BluetoothDiscoverySession::IsActive() const {
return active_;
}
-void BluetoothDiscoverySession::Stop(
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
+void BluetoothDiscoverySession::Stop(const base::Closure& success_callback,
+ const ErrorCallback& error_callback) {
if (!active_) {
LOG(WARNING) << "Discovery session not active. Cannot stop.";
error_callback.Run();
return;
}
VLOG(1) << "Stopping device discovery session.";
- adapter_->RemoveDiscoverySession(
- discovery_filter_.get(),
- base::Bind(&BluetoothDiscoverySession::OnStop,
- weak_ptr_factory_.GetWeakPtr(), callback),
- error_callback);
+ base::Closure deactive_discovery_session =
+ base::Bind(&BluetoothDiscoverySession::DeactivateDiscoverySession,
+ weak_ptr_factory_.GetWeakPtr());
+
+ // Create a callback that runs
+ // BluetoothDiscoverySession::DeactivateDiscoverySession if the session still
+ // exists, but always runs success_callback.
+ base::Closure discovery_session_removed_callback =
+ base::Bind(&BluetoothDiscoverySession::OnDiscoverySessionRemoved,
+ deactive_discovery_session, success_callback);
+ adapter_->RemoveDiscoverySession(discovery_filter_.get(),
+ discovery_session_removed_callback,
+ error_callback);
+}
+
+// static
+void BluetoothDiscoverySession::OnDiscoverySessionRemoved(
+ const base::Closure& deactivate_discovery_session,
+ const base::Closure& success_callback) {
+ deactivate_discovery_session.Run();
+ success_callback.Run();
}
-void BluetoothDiscoverySession::OnStop(const base::Closure& callback) {
+void BluetoothDiscoverySession::DeactivateDiscoverySession() {
MarkAsInactive();
discovery_filter_.reset();
- callback.Run();
}
void BluetoothDiscoverySession::MarkAsInactive() {