Commit dfb46ce9 authored by Vincent Scheib's avatar Vincent Scheib Committed by Commit Bot

Convert base::Callback to base::OnceCallback in...

Convert base::Callback to base::OnceCallback in device/bluetooth/dbus/bluetooth_agent_manager_client.h

This changes BluetoothAgentManagerClient::ErrorCallback to a OnceCallback,
and updates calls in bluetooth_adapter_bluez.cc to be base::BindOnce.

Bug: 1007780
Change-Id: I32af4f619b5cfeccc70bb1b33e6d3b61fbdeea3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1982243Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Vincent Scheib <scheib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728033}
parent 26df275d
...@@ -251,7 +251,7 @@ void BluetoothAdapterBlueZ::Shutdown() { ...@@ -251,7 +251,7 @@ void BluetoothAdapterBlueZ::Shutdown() {
bluez::BluezDBusManager::Get() bluez::BluezDBusManager::Get()
->GetBluetoothAgentManagerClient() ->GetBluetoothAgentManagerClient()
->UnregisterAgent(dbus::ObjectPath(kAgentPath), base::DoNothing(), ->UnregisterAgent(dbus::ObjectPath(kAgentPath), base::DoNothing(),
base::Bind(&OnUnregisterAgentError)); base::BindOnce(&OnUnregisterAgentError));
agent_.reset(); agent_.reset();
...@@ -775,12 +775,13 @@ void BluetoothAdapterBlueZ::AgentManagerAdded( ...@@ -775,12 +775,13 @@ void BluetoothAdapterBlueZ::AgentManagerAdded(
BLUETOOTH_LOG(DEBUG) << "Registering pairing agent"; BLUETOOTH_LOG(DEBUG) << "Registering pairing agent";
bluez::BluezDBusManager::Get() bluez::BluezDBusManager::Get()
->GetBluetoothAgentManagerClient() ->GetBluetoothAgentManagerClient()
->RegisterAgent(dbus::ObjectPath(kAgentPath), ->RegisterAgent(
bluetooth_agent_manager::kKeyboardDisplayCapability, dbus::ObjectPath(kAgentPath),
base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgent, bluetooth_agent_manager::kKeyboardDisplayCapability,
weak_ptr_factory_.GetWeakPtr()), base::BindOnce(&BluetoothAdapterBlueZ::OnRegisterAgent,
base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgentError, weak_ptr_factory_.GetWeakPtr()),
weak_ptr_factory_.GetWeakPtr())); base::BindOnce(&BluetoothAdapterBlueZ::OnRegisterAgentError,
weak_ptr_factory_.GetWeakPtr()));
} }
void BluetoothAdapterBlueZ::AgentManagerRemoved( void BluetoothAdapterBlueZ::AgentManagerRemoved(
...@@ -936,10 +937,10 @@ void BluetoothAdapterBlueZ::OnRegisterAgent() { ...@@ -936,10 +937,10 @@ void BluetoothAdapterBlueZ::OnRegisterAgent() {
->GetBluetoothAgentManagerClient() ->GetBluetoothAgentManagerClient()
->RequestDefaultAgent( ->RequestDefaultAgent(
dbus::ObjectPath(kAgentPath), dbus::ObjectPath(kAgentPath),
base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgent, base::BindOnce(&BluetoothAdapterBlueZ::OnRequestDefaultAgent,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgentError, base::BindOnce(&BluetoothAdapterBlueZ::OnRequestDefaultAgentError,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
void BluetoothAdapterBlueZ::OnRegisterAgentError( void BluetoothAdapterBlueZ::OnRegisterAgentError(
......
...@@ -44,8 +44,8 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient, ...@@ -44,8 +44,8 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient,
// BluetoothAgentManagerClient override. // BluetoothAgentManagerClient override.
void RegisterAgent(const dbus::ObjectPath& agent_path, void RegisterAgent(const dbus::ObjectPath& agent_path,
const std::string& capability, const std::string& capability,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call( dbus::MethodCall method_call(
bluetooth_agent_manager::kBluetoothAgentManagerInterface, bluetooth_agent_manager::kBluetoothAgentManagerInterface,
bluetooth_agent_manager::kRegisterAgent); bluetooth_agent_manager::kRegisterAgent);
...@@ -57,15 +57,16 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient, ...@@ -57,15 +57,16 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient,
object_proxy_->CallMethodWithErrorCallback( object_proxy_->CallMethodWithErrorCallback(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&BluetoothAgentManagerClientImpl::OnSuccess, base::BindOnce(&BluetoothAgentManagerClientImpl::OnSuccess,
weak_ptr_factory_.GetWeakPtr(), callback), weak_ptr_factory_.GetWeakPtr(), std::move(callback)),
base::BindOnce(&BluetoothAgentManagerClientImpl::OnError, base::BindOnce(&BluetoothAgentManagerClientImpl::OnError,
weak_ptr_factory_.GetWeakPtr(), error_callback)); weak_ptr_factory_.GetWeakPtr(),
std::move(error_callback)));
} }
// BluetoothAgentManagerClient override. // BluetoothAgentManagerClient override.
void UnregisterAgent(const dbus::ObjectPath& agent_path, void UnregisterAgent(const dbus::ObjectPath& agent_path,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call( dbus::MethodCall method_call(
bluetooth_agent_manager::kBluetoothAgentManagerInterface, bluetooth_agent_manager::kBluetoothAgentManagerInterface,
bluetooth_agent_manager::kUnregisterAgent); bluetooth_agent_manager::kUnregisterAgent);
...@@ -76,15 +77,16 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient, ...@@ -76,15 +77,16 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient,
object_proxy_->CallMethodWithErrorCallback( object_proxy_->CallMethodWithErrorCallback(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&BluetoothAgentManagerClientImpl::OnSuccess, base::BindOnce(&BluetoothAgentManagerClientImpl::OnSuccess,
weak_ptr_factory_.GetWeakPtr(), callback), weak_ptr_factory_.GetWeakPtr(), std::move(callback)),
base::BindOnce(&BluetoothAgentManagerClientImpl::OnError, base::BindOnce(&BluetoothAgentManagerClientImpl::OnError,
weak_ptr_factory_.GetWeakPtr(), error_callback)); weak_ptr_factory_.GetWeakPtr(),
std::move(error_callback)));
} }
// BluetoothAgentManagerClient override. // BluetoothAgentManagerClient override.
void RequestDefaultAgent(const dbus::ObjectPath& agent_path, void RequestDefaultAgent(const dbus::ObjectPath& agent_path,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) override { ErrorCallback error_callback) override {
dbus::MethodCall method_call( dbus::MethodCall method_call(
bluetooth_agent_manager::kBluetoothAgentManagerInterface, bluetooth_agent_manager::kBluetoothAgentManagerInterface,
bluetooth_agent_manager::kRequestDefaultAgent); bluetooth_agent_manager::kRequestDefaultAgent);
...@@ -95,9 +97,10 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient, ...@@ -95,9 +97,10 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient,
object_proxy_->CallMethodWithErrorCallback( object_proxy_->CallMethodWithErrorCallback(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&BluetoothAgentManagerClientImpl::OnSuccess, base::BindOnce(&BluetoothAgentManagerClientImpl::OnSuccess,
weak_ptr_factory_.GetWeakPtr(), callback), weak_ptr_factory_.GetWeakPtr(), std::move(callback)),
base::BindOnce(&BluetoothAgentManagerClientImpl::OnError, base::BindOnce(&BluetoothAgentManagerClientImpl::OnError,
weak_ptr_factory_.GetWeakPtr(), error_callback)); weak_ptr_factory_.GetWeakPtr(),
std::move(error_callback)));
} }
protected: protected:
...@@ -144,14 +147,13 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient, ...@@ -144,14 +147,13 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient,
} }
// Called when a response for successful method call is received. // Called when a response for successful method call is received.
void OnSuccess(const base::Closure& callback, dbus::Response* response) { void OnSuccess(base::OnceClosure callback, dbus::Response* response) {
DCHECK(response); DCHECK(response);
callback.Run(); std::move(callback).Run();
} }
// Called when a response for a failed method call is received. // Called when a response for a failed method call is received.
void OnError(const ErrorCallback& error_callback, void OnError(ErrorCallback error_callback, dbus::ErrorResponse* response) {
dbus::ErrorResponse* response) {
// Error response has optional error message argument. // Error response has optional error message argument.
std::string error_name; std::string error_name;
std::string error_message; std::string error_message;
...@@ -163,7 +165,7 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient, ...@@ -163,7 +165,7 @@ class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient,
error_name = kNoResponseError; error_name = kNoResponseError;
error_message = ""; error_message = "";
} }
error_callback.Run(error_name, error_message); std::move(error_callback).Run(error_name, error_message);
} }
dbus::ObjectProxy* object_proxy_; dbus::ObjectProxy* object_proxy_;
......
...@@ -46,8 +46,9 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAgentManagerClient ...@@ -46,8 +46,9 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAgentManagerClient
// The ErrorCallback is used by agent manager methods to indicate failure. // The ErrorCallback is used by agent manager methods to indicate failure.
// It receives two arguments: the name of the error in |error_name| and // It receives two arguments: the name of the error in |error_name| and
// an optional message in |error_message|. // an optional message in |error_message|.
typedef base::Callback<void(const std::string& error_name, typedef base::OnceCallback<void(const std::string& error_name,
const std::string& error_message)> ErrorCallback; const std::string& error_message)>
ErrorCallback;
// Registers an agent within the local process at the D-bus object path // Registers an agent within the local process at the D-bus object path
// |agent_path| with the remote agent manager. The agent is used for pairing // |agent_path| with the remote agent manager. The agent is used for pairing
...@@ -56,20 +57,20 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAgentManagerClient ...@@ -56,20 +57,20 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAgentManagerClient
// one of the constants declared in the bluetooth_agent_manager:: namespace. // one of the constants declared in the bluetooth_agent_manager:: namespace.
virtual void RegisterAgent(const dbus::ObjectPath& agent_path, virtual void RegisterAgent(const dbus::ObjectPath& agent_path,
const std::string& capability, const std::string& capability,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Unregisters the agent with the D-Bus object path |agent_path| from the // Unregisters the agent with the D-Bus object path |agent_path| from the
// remote agent manager. // remote agent manager.
virtual void UnregisterAgent(const dbus::ObjectPath& agent_path, virtual void UnregisterAgent(const dbus::ObjectPath& agent_path,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Requests that the agent with the D-Bus object path |agent_path| be made // Requests that the agent with the D-Bus object path |agent_path| be made
// the default. // the default.
virtual void RequestDefaultAgent(const dbus::ObjectPath& agent_path, virtual void RequestDefaultAgent(const dbus::ObjectPath& agent_path,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) = 0; ErrorCallback error_callback) = 0;
// Creates the instance. // Creates the instance.
static BluetoothAgentManagerClient* Create(); static BluetoothAgentManagerClient* Create();
......
...@@ -30,43 +30,47 @@ void FakeBluetoothAgentManagerClient::RemoveObserver(Observer* observer) { ...@@ -30,43 +30,47 @@ void FakeBluetoothAgentManagerClient::RemoveObserver(Observer* observer) {
void FakeBluetoothAgentManagerClient::RegisterAgent( void FakeBluetoothAgentManagerClient::RegisterAgent(
const dbus::ObjectPath& agent_path, const dbus::ObjectPath& agent_path,
const std::string& capability, const std::string& capability,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) { ErrorCallback error_callback) {
VLOG(1) << "RegisterAgent: " << agent_path.value(); VLOG(1) << "RegisterAgent: " << agent_path.value();
if (service_provider_ == NULL) { if (service_provider_ == NULL) {
error_callback.Run(bluetooth_agent_manager::kErrorInvalidArguments, std::move(error_callback)
"No agent created"); .Run(bluetooth_agent_manager::kErrorInvalidArguments,
"No agent created");
} else if (service_provider_->object_path_ != agent_path) { } else if (service_provider_->object_path_ != agent_path) {
error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists, std::move(error_callback)
"Agent already registered"); .Run(bluetooth_agent_manager::kErrorAlreadyExists,
"Agent already registered");
} else { } else {
callback.Run(); std::move(callback).Run();
} }
} }
void FakeBluetoothAgentManagerClient::UnregisterAgent( void FakeBluetoothAgentManagerClient::UnregisterAgent(
const dbus::ObjectPath& agent_path, const dbus::ObjectPath& agent_path,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) { ErrorCallback error_callback) {
VLOG(1) << "UnregisterAgent: " << agent_path.value(); VLOG(1) << "UnregisterAgent: " << agent_path.value();
if (service_provider_ == NULL) { if (service_provider_ == NULL) {
error_callback.Run(bluetooth_agent_manager::kErrorDoesNotExist, std::move(error_callback)
"No agent registered"); .Run(bluetooth_agent_manager::kErrorDoesNotExist,
"No agent registered");
} else if (service_provider_->object_path_ != agent_path) { } else if (service_provider_->object_path_ != agent_path) {
error_callback.Run(bluetooth_agent_manager::kErrorDoesNotExist, std::move(error_callback)
"Agent still registered"); .Run(bluetooth_agent_manager::kErrorDoesNotExist,
"Agent still registered");
} else { } else {
callback.Run(); std::move(callback).Run();
} }
} }
void FakeBluetoothAgentManagerClient::RequestDefaultAgent( void FakeBluetoothAgentManagerClient::RequestDefaultAgent(
const dbus::ObjectPath& agent_path, const dbus::ObjectPath& agent_path,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) { ErrorCallback error_callback) {
VLOG(1) << "RequestDefaultAgent: " << agent_path.value(); VLOG(1) << "RequestDefaultAgent: " << agent_path.value();
callback.Run(); std::move(callback).Run();
} }
void FakeBluetoothAgentManagerClient::RegisterAgentServiceProvider( void FakeBluetoothAgentManagerClient::RegisterAgentServiceProvider(
......
...@@ -32,14 +32,14 @@ class DEVICE_BLUETOOTH_EXPORT FakeBluetoothAgentManagerClient ...@@ -32,14 +32,14 @@ class DEVICE_BLUETOOTH_EXPORT FakeBluetoothAgentManagerClient
void RemoveObserver(Observer* observer) override; void RemoveObserver(Observer* observer) override;
void RegisterAgent(const dbus::ObjectPath& agent_path, void RegisterAgent(const dbus::ObjectPath& agent_path,
const std::string& capability, const std::string& capability,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) override; ErrorCallback error_callback) override;
void UnregisterAgent(const dbus::ObjectPath& agent_path, void UnregisterAgent(const dbus::ObjectPath& agent_path,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) override; ErrorCallback error_callback) override;
void RequestDefaultAgent(const dbus::ObjectPath& agent_path, void RequestDefaultAgent(const dbus::ObjectPath& agent_path,
const base::Closure& callback, base::OnceClosure callback,
const ErrorCallback& error_callback) override; ErrorCallback error_callback) override;
// Register, unregister and retrieve pointers to agent service providers. // Register, unregister and retrieve pointers to agent service providers.
void RegisterAgentServiceProvider( void RegisterAgentServiceProvider(
......
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