Commit 6bb329d3 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Convert chromeos/dbus/debug_daemon to base::Bind and base::Callback to Once/Repeating

Bug: 1007656
Change-Id: I9fad1474439514365fd44065e5175e546fc920c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1925466
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717260}
parent de5df376
......@@ -53,35 +53,32 @@ class TestDebugDaemonClient : public FakeDebugDaemonClient {
FakeDebugDaemonClient::SetDebuggingFeaturesStatus(featues_mask);
}
void EnableDebuggingFeatures(
const std::string& password,
const EnableDebuggingCallback& callback) override {
void EnableDebuggingFeatures(const std::string& password,
EnableDebuggingCallback callback) override {
FakeDebugDaemonClient::EnableDebuggingFeatures(
password, base::Bind(&TestDebugDaemonClient::OnEnableDebuggingFeatures,
base::Unretained(this), callback));
password,
base::BindOnce(&TestDebugDaemonClient::OnEnableDebuggingFeatures,
base::Unretained(this), std::move(callback)));
}
void RemoveRootfsVerification(
const DebugDaemonClient::EnableDebuggingCallback& callback) override {
void RemoveRootfsVerification(EnableDebuggingCallback callback) override {
FakeDebugDaemonClient::RemoveRootfsVerification(
base::Bind(&TestDebugDaemonClient::OnRemoveRootfsVerification,
base::Unretained(this), callback));
base::BindOnce(&TestDebugDaemonClient::OnRemoveRootfsVerification,
base::Unretained(this), std::move(callback)));
}
void QueryDebuggingFeatures(
const DebugDaemonClient::QueryDevFeaturesCallback& callback) override {
void QueryDebuggingFeatures(QueryDevFeaturesCallback callback) override {
LOG(WARNING) << "QueryDebuggingFeatures";
FakeDebugDaemonClient::QueryDebuggingFeatures(
base::Bind(&TestDebugDaemonClient::OnQueryDebuggingFeatures,
base::Unretained(this), callback));
base::BindOnce(&TestDebugDaemonClient::OnQueryDebuggingFeatures,
base::Unretained(this), std::move(callback)));
}
void OnRemoveRootfsVerification(
const DebugDaemonClient::EnableDebuggingCallback& original_callback,
bool succeeded) {
void OnRemoveRootfsVerification(EnableDebuggingCallback original_callback,
bool succeeded) {
LOG(WARNING) << "OnRemoveRootfsVerification: succeeded = " << succeeded;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(original_callback, succeeded));
FROM_HERE, base::BindOnce(std::move(original_callback), succeeded));
if (runner_.get())
runner_->Quit();
else
......@@ -90,14 +87,14 @@ class TestDebugDaemonClient : public FakeDebugDaemonClient {
num_remove_protection_++;
}
void OnQueryDebuggingFeatures(
const DebugDaemonClient::QueryDevFeaturesCallback& original_callback,
bool succeeded,
int feature_mask) {
void OnQueryDebuggingFeatures(QueryDevFeaturesCallback original_callback,
bool succeeded,
int feature_mask) {
LOG(WARNING) << "OnQueryDebuggingFeatures: succeeded = " << succeeded
<< ", feature_mask = " << feature_mask;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(original_callback, succeeded, feature_mask));
FROM_HERE,
base::BindOnce(std::move(original_callback), succeeded, feature_mask));
if (runner_.get())
runner_->Quit();
else
......@@ -106,13 +103,12 @@ class TestDebugDaemonClient : public FakeDebugDaemonClient {
num_query_debugging_features_++;
}
void OnEnableDebuggingFeatures(
const DebugDaemonClient::EnableDebuggingCallback& original_callback,
bool succeeded) {
void OnEnableDebuggingFeatures(EnableDebuggingCallback original_callback,
bool succeeded) {
LOG(WARNING) << "OnEnableDebuggingFeatures: succeeded = " << succeeded
<< ", feature_mask = ";
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(original_callback, succeeded));
FROM_HERE, base::BindOnce(std::move(original_callback), succeeded));
if (runner_.get())
runner_->Quit();
else
......
......@@ -386,9 +386,8 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
weak_ptr_factory_.GetWeakPtr()));
}
void EnableDebuggingFeatures(
const std::string& password,
const EnableDebuggingCallback& callback) override {
void EnableDebuggingFeatures(const std::string& password,
EnableDebuggingCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kEnableChromeDevFeatures);
dbus::MessageWriter writer(&method_call);
......@@ -396,29 +395,27 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnEnableDebuggingFeatures,
weak_ptr_factory_.GetWeakPtr(), callback));
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void QueryDebuggingFeatures(
const QueryDevFeaturesCallback& callback) override {
void QueryDebuggingFeatures(QueryDevFeaturesCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kQueryDevFeatures);
dbus::MessageWriter writer(&method_call);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnQueryDebuggingFeatures,
weak_ptr_factory_.GetWeakPtr(), callback));
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void RemoveRootfsVerification(
const EnableDebuggingCallback& callback) override {
void RemoveRootfsVerification(EnableDebuggingCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kRemoveRootfsVerification);
dbus::MessageWriter writer(&method_call);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnRemoveRootfsVerification,
weak_ptr_factory_.GetWeakPtr(), callback));
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void WaitForServiceToBeAvailable(
......@@ -427,7 +424,7 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
}
void SetOomScoreAdj(const std::map<pid_t, int32_t>& pid_to_oom_score_adj,
const SetOomScoreAdjCallback& callback) override {
SetOomScoreAdjCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kSetOomScoreAdj);
dbus::MessageWriter writer(&method_call);
......@@ -447,7 +444,7 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnSetOomScoreAdj,
weak_ptr_factory_.GetWeakPtr(), callback));
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void CupsAddManuallyConfiguredPrinter(
......@@ -488,7 +485,7 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
void CupsRemovePrinter(const std::string& name,
DebugDaemonClient::CupsRemovePrinterCallback callback,
const base::Closure& error_callback) override {
base::OnceClosure error_callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kCupsRemovePrinter);
dbus::MessageWriter writer(&method_call);
......@@ -498,7 +495,7 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnPrinterRemoved,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
error_callback));
std::move(error_callback)));
}
void StartConcierge(ConciergeCallback callback) override {
......@@ -739,34 +736,35 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
std::move(callback).Run(std::move(result));
}
void OnEnableDebuggingFeatures(const EnableDebuggingCallback& callback,
void OnEnableDebuggingFeatures(EnableDebuggingCallback callback,
dbus::Response* response) {
if (callback.is_null())
return;
callback.Run(response != NULL);
std::move(callback).Run(response != nullptr);
}
void OnQueryDebuggingFeatures(const QueryDevFeaturesCallback& callback,
void OnQueryDebuggingFeatures(QueryDevFeaturesCallback callback,
dbus::Response* response) {
if (callback.is_null())
return;
int32_t feature_mask = DEV_FEATURE_NONE;
if (!response || !dbus::MessageReader(response).PopInt32(&feature_mask)) {
callback.Run(false, debugd::DevFeatureFlag::DEV_FEATURES_DISABLED);
std::move(callback).Run(false,
debugd::DevFeatureFlag::DEV_FEATURES_DISABLED);
return;
}
callback.Run(true, feature_mask);
std::move(callback).Run(true, feature_mask);
}
void OnRemoveRootfsVerification(const EnableDebuggingCallback& callback,
void OnRemoveRootfsVerification(EnableDebuggingCallback callback,
dbus::Response* response) {
if (callback.is_null())
return;
callback.Run(response != NULL);
std::move(callback).Run(response != nullptr);
}
// Called when a response for StopAgentTracing() is received.
......@@ -804,13 +802,13 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
base::RefCountedString::TakeString(&pipe_data));
}
void OnSetOomScoreAdj(const SetOomScoreAdjCallback& callback,
void OnSetOomScoreAdj(SetOomScoreAdjCallback callback,
dbus::Response* response) {
std::string output;
if (response && dbus::MessageReader(response).PopString(&output))
callback.Run(true, output);
std::move(callback).Run(true, output);
else
callback.Run(false, "");
std::move(callback).Run(false, "");
}
void OnPrinterAdded(CupsAddPrinterCallback callback,
......@@ -837,13 +835,13 @@ class DebugDaemonClientImpl : public DebugDaemonClient {
}
void OnPrinterRemoved(CupsRemovePrinterCallback callback,
const base::Closure& error_callback,
base::OnceClosure error_callback,
dbus::Response* response) {
bool result = false;
if (response && dbus::MessageReader(response).PopBool(&result))
std::move(callback).Run(result);
else
error_callback.Run();
std::move(error_callback).Run();
}
void OnStartConcierge(ConciergeCallback callback, dbus::Response* response) {
......
......@@ -137,13 +137,12 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) DebugDaemonClient
// Called once EnableDebuggingFeatures() is complete. |succeeded| will be true
// if debugging features have been successfully enabled.
typedef base::Callback<void(bool succeeded)> EnableDebuggingCallback;
using EnableDebuggingCallback = base::OnceCallback<void(bool succeeded)>;
// Enables debugging features (sshd, boot from USB). |password| is a new
// password for root user. Can be only called in dev mode.
virtual void EnableDebuggingFeatures(
const std::string& password,
const EnableDebuggingCallback& callback) = 0;
virtual void EnableDebuggingFeatures(const std::string& password,
EnableDebuggingCallback callback) = 0;
static const int DEV_FEATURE_NONE = 0;
static const int DEV_FEATURE_ALL_ENABLED =
......@@ -155,16 +154,14 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) DebugDaemonClient
// Called once QueryDebuggingFeatures() is complete. |succeeded| will be true
// if debugging features have been successfully enabled. |feature_mask| is a
// bitmask made out of DebuggingFeature enum values.
typedef base::Callback<void(bool succeeded, int feature_mask)>
QueryDevFeaturesCallback;
using QueryDevFeaturesCallback =
base::OnceCallback<void(bool succeeded, int feature_mask)>;
// Checks which debugging features have been already enabled.
virtual void QueryDebuggingFeatures(
const QueryDevFeaturesCallback& callback) = 0;
virtual void QueryDebuggingFeatures(QueryDevFeaturesCallback callback) = 0;
// Removes rootfs verification from the file system. Can be only called in
// dev mode.
virtual void RemoveRootfsVerification(
const EnableDebuggingCallback& callback) = 0;
virtual void RemoveRootfsVerification(EnableDebuggingCallback callback) = 0;
// Trigger uploading of crashes.
virtual void UploadCrashes() = 0;
......@@ -174,8 +171,8 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) DebugDaemonClient
WaitForServiceToBeAvailableCallback callback) = 0;
// A callback for SetOomScoreAdj().
typedef base::Callback<void(bool success, const std::string& output)>
SetOomScoreAdjCallback;
using SetOomScoreAdjCallback =
base::OnceCallback<void(bool success, const std::string& output)>;
// Set OOM score oom_score_adj for some process.
// Note that the corresponding DBus configuration of the debugd method
......@@ -183,7 +180,7 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) DebugDaemonClient
// user chronos or Android apps.
virtual void SetOomScoreAdj(
const std::map<pid_t, int32_t>& pid_to_oom_score_adj,
const SetOomScoreAdjCallback& callback) = 0;
SetOomScoreAdjCallback callback) = 0;
// A callback to handle the result of CupsAdd[Auto|Manually]ConfiguredPrinter.
// A negative value denotes a D-Bus library error while non-negative values
......@@ -221,7 +218,7 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) DebugDaemonClient
// called if there was an error in communicating with debugd.
virtual void CupsRemovePrinter(const std::string& name,
CupsRemovePrinterCallback callback,
const base::Closure& error_callback) = 0;
base::OnceClosure error_callback) = 0;
// A callback to handle the result of StartConcierge/StopConcierge.
using ConciergeCallback = base::OnceCallback<void(bool success)>;
......
......@@ -157,28 +157,28 @@ void FakeDebugDaemonClient::UploadCrashes() {}
void FakeDebugDaemonClient::EnableDebuggingFeatures(
const std::string& password,
const DebugDaemonClient::EnableDebuggingCallback& callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
base::BindOnce(callback, true));
EnableDebuggingCallback callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), true));
}
void FakeDebugDaemonClient::QueryDebuggingFeatures(
const DebugDaemonClient::QueryDevFeaturesCallback& callback) {
QueryDevFeaturesCallback callback) {
bool supported = base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kSystemDevMode);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(
callback, true,
std::move(callback), true,
static_cast<int>(
supported ? features_mask_
: debugd::DevFeatureFlag::DEV_FEATURES_DISABLED)));
}
void FakeDebugDaemonClient::RemoveRootfsVerification(
const DebugDaemonClient::EnableDebuggingCallback& callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
base::BindOnce(callback, true));
EnableDebuggingCallback callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), true));
}
void FakeDebugDaemonClient::WaitForServiceToBeAvailable(
......@@ -194,9 +194,9 @@ void FakeDebugDaemonClient::WaitForServiceToBeAvailable(
void FakeDebugDaemonClient::SetOomScoreAdj(
const std::map<pid_t, int32_t>& pid_to_oom_score_adj,
const SetOomScoreAdjCallback& callback) {
SetOomScoreAdjCallback callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, true, ""));
FROM_HERE, base::BindOnce(std::move(callback), true, ""));
}
void FakeDebugDaemonClient::SetDebuggingFeaturesStatus(int features_mask) {
......@@ -218,7 +218,7 @@ void FakeDebugDaemonClient::CupsAddManuallyConfiguredPrinter(
const std::string& name,
const std::string& uri,
const std::string& ppd_contents,
DebugDaemonClient::CupsAddPrinterCallback callback) {
CupsAddPrinterCallback callback) {
printers_.insert(name);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), 0));
......@@ -227,7 +227,7 @@ void FakeDebugDaemonClient::CupsAddManuallyConfiguredPrinter(
void FakeDebugDaemonClient::CupsAddAutoConfiguredPrinter(
const std::string& name,
const std::string& uri,
DebugDaemonClient::CupsAddPrinterCallback callback) {
CupsAddPrinterCallback callback) {
printers_.insert(name);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), 0));
......@@ -235,8 +235,8 @@ void FakeDebugDaemonClient::CupsAddAutoConfiguredPrinter(
void FakeDebugDaemonClient::CupsRemovePrinter(
const std::string& name,
DebugDaemonClient::CupsRemovePrinterCallback callback,
const base::Closure& error_callback) {
CupsRemovePrinterCallback callback,
base::OnceClosure error_callback) {
const bool has_printer = base::Contains(printers_, name);
if (has_printer)
printers_.erase(name);
......
......@@ -66,17 +66,14 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) FakeDebugDaemonClient
const std::map<std::string, std::string>& options,
TestICMPCallback callback) override;
void UploadCrashes() override;
void EnableDebuggingFeatures(
const std::string& password,
const EnableDebuggingCallback& callback) override;
void QueryDebuggingFeatures(
const QueryDevFeaturesCallback& callback) override;
void RemoveRootfsVerification(
const EnableDebuggingCallback& callback) override;
void EnableDebuggingFeatures(const std::string& password,
EnableDebuggingCallback callback) override;
void QueryDebuggingFeatures(QueryDevFeaturesCallback callback) override;
void RemoveRootfsVerification(EnableDebuggingCallback callback) override;
void WaitForServiceToBeAvailable(
WaitForServiceToBeAvailableCallback callback) override;
void SetOomScoreAdj(const std::map<pid_t, int32_t>& pid_to_oom_score_adj,
const SetOomScoreAdjCallback& callback) override;
SetOomScoreAdjCallback callback) override;
void CupsAddManuallyConfiguredPrinter(
const std::string& name,
const std::string& uri,
......@@ -87,7 +84,7 @@ class COMPONENT_EXPORT(DEBUG_DAEMON) FakeDebugDaemonClient
CupsAddPrinterCallback callback) override;
void CupsRemovePrinter(const std::string& name,
CupsRemovePrinterCallback callback,
const base::Closure& error_callback) override;
base::OnceClosure error_callback) override;
void StartConcierge(ConciergeCallback callback) override;
void StopConcierge(ConciergeCallback callback) override;
void StartPluginVmDispatcher(const std::string& owner_id,
......
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