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() {
if (view_)
view_->Unbind();
if (discovery_session_.get())
discovery_session_->Stop(base::DoNothing(), base::DoNothing());
discovery_session_->Stop();
if (adapter_.get())
adapter_->RemoveObserver(this);
}
......@@ -149,9 +149,9 @@ void HIDDetectionScreen::HideImpl() {
if (is_hidden())
return;
if (discovery_session_.get()) {
discovery_session_->Stop(base::DoNothing(), base::DoNothing());
}
if (discovery_session_.get())
discovery_session_->Stop();
if (view_)
view_->Hide();
}
......
......@@ -136,11 +136,8 @@ void BleSynchronizer::ProcessQueue() {
break;
}
stop_discovery_args->discovery_session->Stop(
base::Bind(&BleSynchronizer::OnDiscoverySessionStopped,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&BleSynchronizer::OnErrorStoppingDiscoverySession,
weak_ptr_factory_.GetWeakPtr()));
stop_discovery_args->discovery_session->Stop();
OnDiscoverySessionStopped();
break;
}
default:
......@@ -234,15 +231,6 @@ void BleSynchronizer::OnDiscoverySessionStopped() {
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() {
// 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
......
......@@ -82,7 +82,6 @@ class BleSynchronizer : public BleSynchronizerBase {
std::unique_ptr<device::BluetoothDiscoverySession> discovery_session);
void OnErrorStartingDiscoverySession();
void OnDiscoverySessionStopped();
void OnErrorStoppingDiscoverySession();
void ScheduleCommandCompletion();
void CompleteCurrentCommand();
......
......@@ -194,7 +194,7 @@ void StopDiscoverySession(
// 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
// the results here.
discovery_session->Stop(base::DoNothing(), base::DoNothing());
discovery_session->Stop();
}
UMARequestDeviceOutcome OutcomeFromChooserEvent(BluetoothChooser::Event event) {
......
......@@ -591,7 +591,7 @@ void WebBluetoothServiceImpl::DeviceAdvertisementReceived(
// If we don't have any bound clients, clean things up.
if (scanning_clients_.empty()) {
discovery_session_->Stop(base::DoNothing(), base::DoNothing());
discovery_session_->Stop();
discovery_session_ = nullptr;
return;
}
......
......@@ -25,7 +25,7 @@ BluetoothDiscoverySession::BluetoothDiscoverySession(
BluetoothDiscoverySession::~BluetoothDiscoverySession() {
if (IsActive())
Stop(base::DoNothing(), base::DoNothing());
Stop();
}
bool BluetoothDiscoverySession::IsActive() const {
......@@ -42,8 +42,8 @@ void BluetoothDiscoverySession::StartingSessionsScanning() {
status_ = SessionStatus::SCANNING;
}
void BluetoothDiscoverySession::Stop(const base::Closure& success_callback,
const ErrorCallback& error_callback) {
void BluetoothDiscoverySession::Stop(base::Closure success_callback,
ErrorCallback error_callback) {
if (!IsActive()) {
DVLOG(1) << "Discovery session not active. Cannot stop.";
BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome(
......@@ -75,11 +75,11 @@ void BluetoothDiscoverySession::Stop(const base::Closure& success_callback,
base::Closure discovery_session_removed_callback =
base::Bind(&BluetoothDiscoverySession::OnDiscoverySessionRemoved,
weak_ptr_factory_.GetWeakPtr(), deactive_discovery_session,
success_callback);
std::move(success_callback));
adapter_->RemoveDiscoverySession(
this, discovery_session_removed_callback,
base::Bind(&BluetoothDiscoverySession::OnDiscoverySessionRemovalFailed,
weak_ptr_factory_.GetWeakPtr(), error_callback));
weak_ptr_factory_.GetWeakPtr(), std::move(error_callback)));
}
// static
......
......@@ -7,6 +7,7 @@
#include <memory>
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
......@@ -70,8 +71,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDiscoverySession {
// 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
// arguments.
virtual void Stop(const base::Closure& callback,
const ErrorCallback& error_callback);
virtual void Stop(base::Closure callback = base::DoNothing(),
ErrorCallback error_callback = base::DoNothing());
virtual const BluetoothDiscoveryFilter* GetDiscoveryFilter() const;
......
......@@ -20,20 +20,8 @@ void DiscoverySession::IsActive(IsActiveCallback callback) {
}
void DiscoverySession::Stop(StopCallback callback) {
auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback));
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) {
discovery_session_->Stop();
std::move(callback).Run(true /* success */);
}
void DiscoverySession::OnStopError(StopCallback callback) {
std::move(callback).Run(false /* success */);
}
} // namespace bluetooth
......@@ -31,9 +31,6 @@ class DiscoverySession : public mojom::DiscoverySession {
void Stop(StopCallback callback) override;
private:
void OnStop(StopCallback callback);
void OnStopError(StopCallback callback);
// The underlying discovery session.
std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_;
......
......@@ -173,7 +173,8 @@ void BluetoothEventRouter::StopDiscoverySession(
}
BLUETOOTH_LOG(USER) << "StopDiscoverySession: " << extension_id;
device::BluetoothDiscoverySession* session = iter->second;
session->Stop(callback, error_callback);
session->Stop();
callback.Run();
}
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