Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: chromeos/dbus/biod/biod_client.cc

Issue 2799043007: CrOS: Add success/failure indicators for biod methods with no callback. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromeos/dbus/biod/biod_client.cc
diff --git a/chromeos/dbus/biod/biod_client.cc b/chromeos/dbus/biod/biod_client.cc
index 5a77c18fdea6ae424d98a9be688f32859a6cfc43..8ea818dc915e1f1182841e056525edf59cbbf6ef 100644
--- a/chromeos/dbus/biod/biod_client.cc
+++ b/chromeos/dbus/biod/biod_client.cc
@@ -66,14 +66,17 @@ class BiodClientImpl : public BiodClient {
weak_ptr_factory_.GetWeakPtr(), callback));
}
- void DestroyAllRecords() override {
+ void DestroyAllRecords(const VoidDBusMethodCallback& callback) override {
dbus::MethodCall method_call(
biod::kBiometricsManagerInterface,
biod::kBiometricsManagerDestroyAllRecordsMethod);
- biod_proxy_->CallMethod(&method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- dbus::ObjectProxy::EmptyResponseCallback());
+ biod_proxy_->CallMethodWithErrorCallback(
Daniel Erat 2017/04/08 00:12:34 instead of using CallMethodWithErrorCallback, i th
sammiequon 2017/04/08 01:03:30 Hmm, ok. But when would call with error callback b
Daniel Erat 2017/04/08 01:06:03 you mean, when should CallMethodWithErrorCallback
sammiequon 2017/04/08 01:31:47 Acknowledged.
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&BiodClientImpl::OnVoidMethodSuccess,
+ weak_ptr_factory_.GetWeakPtr(), callback),
+ base::Bind(&BiodClientImpl::OnVoidMethodFailure,
+ weak_ptr_factory_.GetWeakPtr(), callback));
}
void StartAuthSession(const ObjectPathCallback& callback) override {
@@ -100,31 +103,39 @@ class BiodClientImpl : public BiodClient {
weak_ptr_factory_.GetWeakPtr(), callback));
}
- void CancelEnrollSession(
- const dbus::ObjectPath& enroll_session_path) override {
+ void CancelEnrollSession(const dbus::ObjectPath& enroll_session_path,
+ const VoidDBusMethodCallback& callback) override {
dbus::MethodCall method_call(biod::kEnrollSessionInterface,
biod::kEnrollSessionCancelMethod);
dbus::ObjectProxy* enroll_session_proxy =
bus_->GetObjectProxy(biod::kBiodServiceName, enroll_session_path);
- enroll_session_proxy->CallMethod(
+ enroll_session_proxy->CallMethodWithErrorCallback(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- dbus::ObjectProxy::EmptyResponseCallback());
+ base::Bind(&BiodClientImpl::OnVoidMethodSuccess,
+ weak_ptr_factory_.GetWeakPtr(), callback),
+ base::Bind(&BiodClientImpl::OnVoidMethodFailure,
+ weak_ptr_factory_.GetWeakPtr(), callback));
}
- void EndAuthSession(const dbus::ObjectPath& auth_session_path) override {
+ void EndAuthSession(const dbus::ObjectPath& auth_session_path,
+ const VoidDBusMethodCallback& callback) override {
dbus::MethodCall method_call(biod::kAuthSessionInterface,
biod::kAuthSessionEndMethod);
dbus::ObjectProxy* auth_session_proxy =
bus_->GetObjectProxy(biod::kBiodServiceName, auth_session_path);
- auth_session_proxy->CallMethod(&method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- dbus::ObjectProxy::EmptyResponseCallback());
+ auth_session_proxy->CallMethodWithErrorCallback(
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&BiodClientImpl::OnVoidMethodSuccess,
+ weak_ptr_factory_.GetWeakPtr(), callback),
+ base::Bind(&BiodClientImpl::OnVoidMethodFailure,
+ weak_ptr_factory_.GetWeakPtr(), callback));
}
void SetRecordLabel(const dbus::ObjectPath& record_path,
- const std::string& label) override {
+ const std::string& label,
+ const VoidDBusMethodCallback& callback) override {
dbus::MethodCall method_call(biod::kRecordInterface,
biod::kRecordSetLabelMethod);
dbus::MessageWriter writer(&method_call);
@@ -137,15 +148,19 @@ class BiodClientImpl : public BiodClient {
dbus::ObjectProxy::EmptyResponseCallback());
}
- void RemoveRecord(const dbus::ObjectPath& record_path) override {
+ void RemoveRecord(const dbus::ObjectPath& record_path,
+ const VoidDBusMethodCallback& callback) override {
dbus::MethodCall method_call(biod::kRecordInterface,
biod::kRecordRemoveMethod);
dbus::ObjectProxy* record_proxy =
bus_->GetObjectProxy(biod::kBiodServiceName, record_path);
- record_proxy->CallMethod(&method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- dbus::ObjectProxy::EmptyResponseCallback());
+ record_proxy->CallMethodWithErrorCallback(
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&BiodClientImpl::OnVoidMethodSuccess,
+ weak_ptr_factory_.GetWeakPtr(), callback),
+ base::Bind(&BiodClientImpl::OnVoidMethodFailure,
+ weak_ptr_factory_.GetWeakPtr(), callback));
}
void RequestRecordLabel(const dbus::ObjectPath& record_path,
@@ -201,6 +216,29 @@ class BiodClientImpl : public BiodClient {
}
private:
+ void OnVoidMethodSuccess(const VoidDBusMethodCallback& callback,
Daniel Erat 2017/04/08 00:12:34 this isn't accessing any of the class's state, so
sammiequon 2017/04/08 01:03:30 Done.
+ dbus::Response* response) {
+ if (!response) {
Daniel Erat 2017/04/08 00:12:34 much simpler: callback.Run(response ? DBUS_METH
sammiequon 2017/04/08 01:03:30 Done.
+ callback.Run(DBUS_METHOD_CALL_FAILURE);
+ return;
+ }
+ callback.Run(DBUS_METHOD_CALL_SUCCESS);
+ }
+
+ void OnVoidMethodFailure(const VoidDBusMethodCallback& callback,
+ dbus::ErrorResponse* response) {
+ std::string error_name;
+ std::string error_message;
+ if (response) {
+ // Error message may contain the error message as string.
+ dbus::MessageReader reader(response);
+ error_name = response->GetErrorName();
+ reader.PopString(&error_message);
+ }
+ LOG(ERROR) << "Failed method call: " << error_name << ": " << error_message;
+ callback.Run(DBUS_METHOD_CALL_FAILURE);
+ }
+
void OnStartEnrollSession(const ObjectPathCallback& callback,
dbus::Response* response) {
dbus::ObjectPath result;

Powered by Google App Engine
This is Rietveld 408576698