Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/biod/biod_client.h" | 5 #include "chromeos/dbus/biod/biod_client.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 biod::kBiometricsManagerGetRecordsForUserMethod); | 59 biod::kBiometricsManagerGetRecordsForUserMethod); |
| 60 dbus::MessageWriter writer(&method_call); | 60 dbus::MessageWriter writer(&method_call); |
| 61 writer.AppendString(user_id); | 61 writer.AppendString(user_id); |
| 62 | 62 |
| 63 biod_proxy_->CallMethod( | 63 biod_proxy_->CallMethod( |
| 64 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 64 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 65 base::Bind(&BiodClientImpl::OnGetRecordsForUser, | 65 base::Bind(&BiodClientImpl::OnGetRecordsForUser, |
| 66 weak_ptr_factory_.GetWeakPtr(), callback)); | 66 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void DestroyAllRecords() override { | 69 void DestroyAllRecords(const VoidDBusMethodCallback& callback) override { |
| 70 dbus::MethodCall method_call( | 70 dbus::MethodCall method_call( |
| 71 biod::kBiometricsManagerInterface, | 71 biod::kBiometricsManagerInterface, |
| 72 biod::kBiometricsManagerDestroyAllRecordsMethod); | 72 biod::kBiometricsManagerDestroyAllRecordsMethod); |
| 73 | 73 |
| 74 biod_proxy_->CallMethod(&method_call, | 74 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.
| |
| 75 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 75 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 76 dbus::ObjectProxy::EmptyResponseCallback()); | 76 base::Bind(&BiodClientImpl::OnVoidMethodSuccess, |
| 77 weak_ptr_factory_.GetWeakPtr(), callback), | |
| 78 base::Bind(&BiodClientImpl::OnVoidMethodFailure, | |
| 79 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 77 } | 80 } |
| 78 | 81 |
| 79 void StartAuthSession(const ObjectPathCallback& callback) override { | 82 void StartAuthSession(const ObjectPathCallback& callback) override { |
| 80 dbus::MethodCall method_call( | 83 dbus::MethodCall method_call( |
| 81 biod::kBiometricsManagerInterface, | 84 biod::kBiometricsManagerInterface, |
| 82 biod::kBiometricsManagerStartAuthSessionMethod); | 85 biod::kBiometricsManagerStartAuthSessionMethod); |
| 83 | 86 |
| 84 biod_proxy_->CallMethod( | 87 biod_proxy_->CallMethod( |
| 85 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 88 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 86 base::Bind(&BiodClientImpl::OnStartAuthSession, | 89 base::Bind(&BiodClientImpl::OnStartAuthSession, |
| 87 weak_ptr_factory_.GetWeakPtr(), callback)); | 90 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 88 } | 91 } |
| 89 | 92 |
| 90 void RequestType(const BiometricTypeCallback& callback) override { | 93 void RequestType(const BiometricTypeCallback& callback) override { |
| 91 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface, | 94 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface, |
| 92 dbus::kDBusPropertiesGet); | 95 dbus::kDBusPropertiesGet); |
| 93 dbus::MessageWriter writer(&method_call); | 96 dbus::MessageWriter writer(&method_call); |
| 94 writer.AppendString(biod::kBiometricsManagerInterface); | 97 writer.AppendString(biod::kBiometricsManagerInterface); |
| 95 writer.AppendString(biod::kBiometricsManagerBiometricTypeProperty); | 98 writer.AppendString(biod::kBiometricsManagerBiometricTypeProperty); |
| 96 | 99 |
| 97 biod_proxy_->CallMethod( | 100 biod_proxy_->CallMethod( |
| 98 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 101 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 99 base::Bind(&BiodClientImpl::OnRequestType, | 102 base::Bind(&BiodClientImpl::OnRequestType, |
| 100 weak_ptr_factory_.GetWeakPtr(), callback)); | 103 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 101 } | 104 } |
| 102 | 105 |
| 103 void CancelEnrollSession( | 106 void CancelEnrollSession(const dbus::ObjectPath& enroll_session_path, |
| 104 const dbus::ObjectPath& enroll_session_path) override { | 107 const VoidDBusMethodCallback& callback) override { |
| 105 dbus::MethodCall method_call(biod::kEnrollSessionInterface, | 108 dbus::MethodCall method_call(biod::kEnrollSessionInterface, |
| 106 biod::kEnrollSessionCancelMethod); | 109 biod::kEnrollSessionCancelMethod); |
| 107 | 110 |
| 108 dbus::ObjectProxy* enroll_session_proxy = | 111 dbus::ObjectProxy* enroll_session_proxy = |
| 109 bus_->GetObjectProxy(biod::kBiodServiceName, enroll_session_path); | 112 bus_->GetObjectProxy(biod::kBiodServiceName, enroll_session_path); |
| 110 enroll_session_proxy->CallMethod( | 113 enroll_session_proxy->CallMethodWithErrorCallback( |
| 111 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 114 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 112 dbus::ObjectProxy::EmptyResponseCallback()); | 115 base::Bind(&BiodClientImpl::OnVoidMethodSuccess, |
| 116 weak_ptr_factory_.GetWeakPtr(), callback), | |
| 117 base::Bind(&BiodClientImpl::OnVoidMethodFailure, | |
| 118 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 113 } | 119 } |
| 114 | 120 |
| 115 void EndAuthSession(const dbus::ObjectPath& auth_session_path) override { | 121 void EndAuthSession(const dbus::ObjectPath& auth_session_path, |
| 122 const VoidDBusMethodCallback& callback) override { | |
| 116 dbus::MethodCall method_call(biod::kAuthSessionInterface, | 123 dbus::MethodCall method_call(biod::kAuthSessionInterface, |
| 117 biod::kAuthSessionEndMethod); | 124 biod::kAuthSessionEndMethod); |
| 118 | 125 |
| 119 dbus::ObjectProxy* auth_session_proxy = | 126 dbus::ObjectProxy* auth_session_proxy = |
| 120 bus_->GetObjectProxy(biod::kBiodServiceName, auth_session_path); | 127 bus_->GetObjectProxy(biod::kBiodServiceName, auth_session_path); |
| 121 auth_session_proxy->CallMethod(&method_call, | 128 auth_session_proxy->CallMethodWithErrorCallback( |
| 122 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 129 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 123 dbus::ObjectProxy::EmptyResponseCallback()); | 130 base::Bind(&BiodClientImpl::OnVoidMethodSuccess, |
| 131 weak_ptr_factory_.GetWeakPtr(), callback), | |
| 132 base::Bind(&BiodClientImpl::OnVoidMethodFailure, | |
| 133 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 124 } | 134 } |
| 125 | 135 |
| 126 void SetRecordLabel(const dbus::ObjectPath& record_path, | 136 void SetRecordLabel(const dbus::ObjectPath& record_path, |
| 127 const std::string& label) override { | 137 const std::string& label, |
| 138 const VoidDBusMethodCallback& callback) override { | |
| 128 dbus::MethodCall method_call(biod::kRecordInterface, | 139 dbus::MethodCall method_call(biod::kRecordInterface, |
| 129 biod::kRecordSetLabelMethod); | 140 biod::kRecordSetLabelMethod); |
| 130 dbus::MessageWriter writer(&method_call); | 141 dbus::MessageWriter writer(&method_call); |
| 131 writer.AppendString(label); | 142 writer.AppendString(label); |
| 132 | 143 |
| 133 dbus::ObjectProxy* record_proxy = | 144 dbus::ObjectProxy* record_proxy = |
| 134 bus_->GetObjectProxy(biod::kBiodServiceName, record_path); | 145 bus_->GetObjectProxy(biod::kBiodServiceName, record_path); |
| 135 record_proxy->CallMethod(&method_call, | 146 record_proxy->CallMethod(&method_call, |
| 136 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 147 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 137 dbus::ObjectProxy::EmptyResponseCallback()); | 148 dbus::ObjectProxy::EmptyResponseCallback()); |
| 138 } | 149 } |
| 139 | 150 |
| 140 void RemoveRecord(const dbus::ObjectPath& record_path) override { | 151 void RemoveRecord(const dbus::ObjectPath& record_path, |
| 152 const VoidDBusMethodCallback& callback) override { | |
| 141 dbus::MethodCall method_call(biod::kRecordInterface, | 153 dbus::MethodCall method_call(biod::kRecordInterface, |
| 142 biod::kRecordRemoveMethod); | 154 biod::kRecordRemoveMethod); |
| 143 | 155 |
| 144 dbus::ObjectProxy* record_proxy = | 156 dbus::ObjectProxy* record_proxy = |
| 145 bus_->GetObjectProxy(biod::kBiodServiceName, record_path); | 157 bus_->GetObjectProxy(biod::kBiodServiceName, record_path); |
| 146 record_proxy->CallMethod(&method_call, | 158 record_proxy->CallMethodWithErrorCallback( |
| 147 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 159 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 148 dbus::ObjectProxy::EmptyResponseCallback()); | 160 base::Bind(&BiodClientImpl::OnVoidMethodSuccess, |
| 161 weak_ptr_factory_.GetWeakPtr(), callback), | |
| 162 base::Bind(&BiodClientImpl::OnVoidMethodFailure, | |
| 163 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 149 } | 164 } |
| 150 | 165 |
| 151 void RequestRecordLabel(const dbus::ObjectPath& record_path, | 166 void RequestRecordLabel(const dbus::ObjectPath& record_path, |
| 152 const LabelCallback& callback) override { | 167 const LabelCallback& callback) override { |
| 153 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface, | 168 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface, |
| 154 dbus::kDBusPropertiesGet); | 169 dbus::kDBusPropertiesGet); |
| 155 dbus::MessageWriter writer(&method_call); | 170 dbus::MessageWriter writer(&method_call); |
| 156 writer.AppendString(biod::kRecordInterface); | 171 writer.AppendString(biod::kRecordInterface); |
| 157 writer.AppendString(biod::kRecordLabelProperty); | 172 writer.AppendString(biod::kRecordLabelProperty); |
| 158 | 173 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 biod_proxy_->ConnectToSignal( | 209 biod_proxy_->ConnectToSignal( |
| 195 biod::kBiometricsManagerInterface, | 210 biod::kBiometricsManagerInterface, |
| 196 biod::kBiometricsManagerSessionFailedSignal, | 211 biod::kBiometricsManagerSessionFailedSignal, |
| 197 base::Bind(&BiodClientImpl::SessionFailedReceived, | 212 base::Bind(&BiodClientImpl::SessionFailedReceived, |
| 198 weak_ptr_factory_.GetWeakPtr()), | 213 weak_ptr_factory_.GetWeakPtr()), |
| 199 base::Bind(&BiodClientImpl::OnSignalConnected, | 214 base::Bind(&BiodClientImpl::OnSignalConnected, |
| 200 weak_ptr_factory_.GetWeakPtr())); | 215 weak_ptr_factory_.GetWeakPtr())); |
| 201 } | 216 } |
| 202 | 217 |
| 203 private: | 218 private: |
| 219 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.
| |
| 220 dbus::Response* response) { | |
| 221 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.
| |
| 222 callback.Run(DBUS_METHOD_CALL_FAILURE); | |
| 223 return; | |
| 224 } | |
| 225 callback.Run(DBUS_METHOD_CALL_SUCCESS); | |
| 226 } | |
| 227 | |
| 228 void OnVoidMethodFailure(const VoidDBusMethodCallback& callback, | |
| 229 dbus::ErrorResponse* response) { | |
| 230 std::string error_name; | |
| 231 std::string error_message; | |
| 232 if (response) { | |
| 233 // Error message may contain the error message as string. | |
| 234 dbus::MessageReader reader(response); | |
| 235 error_name = response->GetErrorName(); | |
| 236 reader.PopString(&error_message); | |
| 237 } | |
| 238 LOG(ERROR) << "Failed method call: " << error_name << ": " << error_message; | |
| 239 callback.Run(DBUS_METHOD_CALL_FAILURE); | |
| 240 } | |
| 241 | |
| 204 void OnStartEnrollSession(const ObjectPathCallback& callback, | 242 void OnStartEnrollSession(const ObjectPathCallback& callback, |
| 205 dbus::Response* response) { | 243 dbus::Response* response) { |
| 206 dbus::ObjectPath result; | 244 dbus::ObjectPath result; |
| 207 if (response) { | 245 if (response) { |
| 208 dbus::MessageReader reader(response); | 246 dbus::MessageReader reader(response); |
| 209 if (!reader.PopObjectPath(&result)) { | 247 if (!reader.PopObjectPath(&result)) { |
| 210 LOG(ERROR) << biod::kBiometricsManagerStartEnrollSessionMethod | 248 LOG(ERROR) << biod::kBiometricsManagerStartEnrollSessionMethod |
| 211 << " had incorrect response."; | 249 << " had incorrect response."; |
| 212 } | 250 } |
| 213 } | 251 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 | 396 |
| 359 // static | 397 // static |
| 360 BiodClient* BiodClient::Create(DBusClientImplementationType type) { | 398 BiodClient* BiodClient::Create(DBusClientImplementationType type) { |
| 361 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 399 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 362 return new BiodClientImpl(); | 400 return new BiodClientImpl(); |
| 363 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 401 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
| 364 return new FakeBiodClient(); | 402 return new FakeBiodClient(); |
| 365 } | 403 } |
| 366 | 404 |
| 367 } // namespace chromeos | 405 } // namespace chromeos |
| OLD | NEW |