Commit 9d517b8e authored by Phillis Tang's avatar Phillis Tang Committed by Commit Bot

Make BluetoothDiscoverySession::Stop callback params optional

This patch makes the callback params optional for
BluetoothDiscoverySession::Stop and removes all the passed callbacks
from the callers. Further changes will be made to completely removes
the callback params.

Bug: 991682
Change-Id: I6c7a3b1a8bd7a06a5d724618609cad8d8dbba898
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2068886Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Commit-Queue: Phillis Tang <phillis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744757}
parent 88941a9c
...@@ -79,7 +79,7 @@ HIDDetectionScreen::~HIDDetectionScreen() { ...@@ -79,7 +79,7 @@ HIDDetectionScreen::~HIDDetectionScreen() {
if (view_) if (view_)
view_->Unbind(); view_->Unbind();
if (discovery_session_.get()) if (discovery_session_.get())
discovery_session_->Stop(base::DoNothing(), base::DoNothing()); discovery_session_->Stop();
if (adapter_.get()) if (adapter_.get())
adapter_->RemoveObserver(this); adapter_->RemoveObserver(this);
} }
...@@ -149,9 +149,9 @@ void HIDDetectionScreen::HideImpl() { ...@@ -149,9 +149,9 @@ void HIDDetectionScreen::HideImpl() {
if (is_hidden()) if (is_hidden())
return; return;
if (discovery_session_.get()) { if (discovery_session_.get())
discovery_session_->Stop(base::DoNothing(), base::DoNothing()); discovery_session_->Stop();
}
if (view_) if (view_)
view_->Hide(); view_->Hide();
} }
......
...@@ -136,11 +136,8 @@ void BleSynchronizer::ProcessQueue() { ...@@ -136,11 +136,8 @@ void BleSynchronizer::ProcessQueue() {
break; break;
} }
stop_discovery_args->discovery_session->Stop( stop_discovery_args->discovery_session->Stop();
base::Bind(&BleSynchronizer::OnDiscoverySessionStopped, OnDiscoverySessionStopped();
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&BleSynchronizer::OnErrorStoppingDiscoverySession,
weak_ptr_factory_.GetWeakPtr()));
break; break;
} }
default: default:
...@@ -234,15 +231,6 @@ void BleSynchronizer::OnDiscoverySessionStopped() { ...@@ -234,15 +231,6 @@ void BleSynchronizer::OnDiscoverySessionStopped() {
stop_discovery_args->callback.Run(); stop_discovery_args->callback.Run();
} }
void BleSynchronizer::OnErrorStoppingDiscoverySession() {
RecordDiscoverySessionStopped(false /* success */);
ScheduleCommandCompletion();
StopDiscoveryArgs* stop_discovery_args =
current_command_->stop_discovery_args.get();
DCHECK(stop_discovery_args);
stop_discovery_args->error_callback.Run();
}
void BleSynchronizer::ScheduleCommandCompletion() { void BleSynchronizer::ScheduleCommandCompletion() {
// Schedule the task to run after the current task has completed. This is // Schedule the task to run after the current task has completed. This is
// necessary because the completion of a Bluetooth task may cause the Tether // necessary because the completion of a Bluetooth task may cause the Tether
......
...@@ -82,7 +82,6 @@ class BleSynchronizer : public BleSynchronizerBase { ...@@ -82,7 +82,6 @@ class BleSynchronizer : public BleSynchronizerBase {
std::unique_ptr<device::BluetoothDiscoverySession> discovery_session); std::unique_ptr<device::BluetoothDiscoverySession> discovery_session);
void OnErrorStartingDiscoverySession(); void OnErrorStartingDiscoverySession();
void OnDiscoverySessionStopped(); void OnDiscoverySessionStopped();
void OnErrorStoppingDiscoverySession();
void ScheduleCommandCompletion(); void ScheduleCommandCompletion();
void CompleteCurrentCommand(); void CompleteCurrentCommand();
......
...@@ -194,7 +194,7 @@ void StopDiscoverySession( ...@@ -194,7 +194,7 @@ void StopDiscoverySession(
// Nothing goes wrong if the discovery session fails to stop, and we don't // Nothing goes wrong if the discovery session fails to stop, and we don't
// need to wait for it before letting the user's script proceed, so we ignore // need to wait for it before letting the user's script proceed, so we ignore
// the results here. // the results here.
discovery_session->Stop(base::DoNothing(), base::DoNothing()); discovery_session->Stop();
} }
UMARequestDeviceOutcome OutcomeFromChooserEvent(BluetoothChooser::Event event) { UMARequestDeviceOutcome OutcomeFromChooserEvent(BluetoothChooser::Event event) {
......
...@@ -591,7 +591,7 @@ void WebBluetoothServiceImpl::DeviceAdvertisementReceived( ...@@ -591,7 +591,7 @@ void WebBluetoothServiceImpl::DeviceAdvertisementReceived(
// If we don't have any bound clients, clean things up. // If we don't have any bound clients, clean things up.
if (scanning_clients_.empty()) { if (scanning_clients_.empty()) {
discovery_session_->Stop(base::DoNothing(), base::DoNothing()); discovery_session_->Stop();
discovery_session_ = nullptr; discovery_session_ = nullptr;
return; return;
} }
......
...@@ -25,7 +25,7 @@ BluetoothDiscoverySession::BluetoothDiscoverySession( ...@@ -25,7 +25,7 @@ BluetoothDiscoverySession::BluetoothDiscoverySession(
BluetoothDiscoverySession::~BluetoothDiscoverySession() { BluetoothDiscoverySession::~BluetoothDiscoverySession() {
if (IsActive()) if (IsActive())
Stop(base::DoNothing(), base::DoNothing()); Stop();
} }
bool BluetoothDiscoverySession::IsActive() const { bool BluetoothDiscoverySession::IsActive() const {
...@@ -42,8 +42,8 @@ void BluetoothDiscoverySession::StartingSessionsScanning() { ...@@ -42,8 +42,8 @@ void BluetoothDiscoverySession::StartingSessionsScanning() {
status_ = SessionStatus::SCANNING; status_ = SessionStatus::SCANNING;
} }
void BluetoothDiscoverySession::Stop(const base::Closure& success_callback, void BluetoothDiscoverySession::Stop(base::Closure success_callback,
const ErrorCallback& error_callback) { ErrorCallback error_callback) {
if (!IsActive()) { if (!IsActive()) {
DVLOG(1) << "Discovery session not active. Cannot stop."; DVLOG(1) << "Discovery session not active. Cannot stop.";
BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome( BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome(
...@@ -75,11 +75,11 @@ void BluetoothDiscoverySession::Stop(const base::Closure& success_callback, ...@@ -75,11 +75,11 @@ void BluetoothDiscoverySession::Stop(const base::Closure& success_callback,
base::Closure discovery_session_removed_callback = base::Closure discovery_session_removed_callback =
base::Bind(&BluetoothDiscoverySession::OnDiscoverySessionRemoved, base::Bind(&BluetoothDiscoverySession::OnDiscoverySessionRemoved,
weak_ptr_factory_.GetWeakPtr(), deactive_discovery_session, weak_ptr_factory_.GetWeakPtr(), deactive_discovery_session,
success_callback); std::move(success_callback));
adapter_->RemoveDiscoverySession( adapter_->RemoveDiscoverySession(
this, discovery_session_removed_callback, this, discovery_session_removed_callback,
base::Bind(&BluetoothDiscoverySession::OnDiscoverySessionRemovalFailed, base::Bind(&BluetoothDiscoverySession::OnDiscoverySessionRemovalFailed,
weak_ptr_factory_.GetWeakPtr(), error_callback)); weak_ptr_factory_.GetWeakPtr(), std::move(error_callback)));
} }
// static // static
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "base/bind_helpers.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
...@@ -70,8 +71,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDiscoverySession { ...@@ -70,8 +71,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDiscoverySession {
// to call this method to end a discovery session, instead of relying on the // to call this method to end a discovery session, instead of relying on the
// destructor, so that they can be notified of the result via the callback // destructor, so that they can be notified of the result via the callback
// arguments. // arguments.
virtual void Stop(const base::Closure& callback, virtual void Stop(base::Closure callback = base::DoNothing(),
const ErrorCallback& error_callback); ErrorCallback error_callback = base::DoNothing());
virtual const BluetoothDiscoveryFilter* GetDiscoveryFilter() const; virtual const BluetoothDiscoveryFilter* GetDiscoveryFilter() const;
......
...@@ -20,20 +20,8 @@ void DiscoverySession::IsActive(IsActiveCallback callback) { ...@@ -20,20 +20,8 @@ void DiscoverySession::IsActive(IsActiveCallback callback) {
} }
void DiscoverySession::Stop(StopCallback callback) { void DiscoverySession::Stop(StopCallback callback) {
auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback)); discovery_session_->Stop();
discovery_session_->Stop(
base::Bind(&DiscoverySession::OnStop, weak_ptr_factory_.GetWeakPtr(),
copyable_callback),
base::Bind(&DiscoverySession::OnStopError, weak_ptr_factory_.GetWeakPtr(),
copyable_callback));
}
void DiscoverySession::OnStop(StopCallback callback) {
std::move(callback).Run(true /* success */); std::move(callback).Run(true /* success */);
} }
void DiscoverySession::OnStopError(StopCallback callback) {
std::move(callback).Run(false /* success */);
}
} // namespace bluetooth } // namespace bluetooth
...@@ -31,9 +31,6 @@ class DiscoverySession : public mojom::DiscoverySession { ...@@ -31,9 +31,6 @@ class DiscoverySession : public mojom::DiscoverySession {
void Stop(StopCallback callback) override; void Stop(StopCallback callback) override;
private: private:
void OnStop(StopCallback callback);
void OnStopError(StopCallback callback);
// The underlying discovery session. // The underlying discovery session.
std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_;
......
...@@ -173,7 +173,8 @@ void BluetoothEventRouter::StopDiscoverySession( ...@@ -173,7 +173,8 @@ void BluetoothEventRouter::StopDiscoverySession(
} }
BLUETOOTH_LOG(USER) << "StopDiscoverySession: " << extension_id; BLUETOOTH_LOG(USER) << "StopDiscoverySession: " << extension_id;
device::BluetoothDiscoverySession* session = iter->second; device::BluetoothDiscoverySession* session = iter->second;
session->Stop(callback, error_callback); session->Stop();
callback.Run();
} }
void BluetoothEventRouter::SetDiscoveryFilter( void BluetoothEventRouter::SetDiscoveryFilter(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment