| 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" |
| 11 #include "chromeos/dbus/biod/fake_biod_client.h" | 11 #include "chromeos/dbus/biod/fake_biod_client.h" |
| 12 #include "dbus/bus.h" | 12 #include "dbus/bus.h" |
| 13 #include "dbus/message.h" | 13 #include "dbus/message.h" |
| 14 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
| 15 #include "dbus/object_proxy.h" | 15 #include "dbus/object_proxy.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 | 18 |
| 19 namespace { |
| 20 |
| 21 // D-Bus response handler for methods that use void callbacks. |
| 22 void OnVoidResponse(const VoidDBusMethodCallback& callback, |
| 23 dbus::Response* response) { |
| 24 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE); |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
| 19 // The BiodClient implementation used in production. | 29 // The BiodClient implementation used in production. |
| 20 class BiodClientImpl : public BiodClient { | 30 class BiodClientImpl : public BiodClient { |
| 21 public: | 31 public: |
| 22 BiodClientImpl() : weak_ptr_factory_(this) {} | 32 BiodClientImpl() : weak_ptr_factory_(this) {} |
| 23 | 33 |
| 24 ~BiodClientImpl() override {} | 34 ~BiodClientImpl() override {} |
| 25 | 35 |
| 26 // BiodClient overrides: | 36 // BiodClient overrides: |
| 27 void AddObserver(Observer* observer) override { | 37 void AddObserver(Observer* observer) override { |
| 28 observers_.AddObserver(observer); | 38 observers_.AddObserver(observer); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 59 biod::kBiometricsManagerGetRecordsForUserMethod); | 69 biod::kBiometricsManagerGetRecordsForUserMethod); |
| 60 dbus::MessageWriter writer(&method_call); | 70 dbus::MessageWriter writer(&method_call); |
| 61 writer.AppendString(user_id); | 71 writer.AppendString(user_id); |
| 62 | 72 |
| 63 biod_proxy_->CallMethod( | 73 biod_proxy_->CallMethod( |
| 64 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 74 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 65 base::Bind(&BiodClientImpl::OnGetRecordsForUser, | 75 base::Bind(&BiodClientImpl::OnGetRecordsForUser, |
| 66 weak_ptr_factory_.GetWeakPtr(), callback)); | 76 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 67 } | 77 } |
| 68 | 78 |
| 69 void DestroyAllRecords() override { | 79 void DestroyAllRecords(const VoidDBusMethodCallback& callback) override { |
| 70 dbus::MethodCall method_call( | 80 dbus::MethodCall method_call( |
| 71 biod::kBiometricsManagerInterface, | 81 biod::kBiometricsManagerInterface, |
| 72 biod::kBiometricsManagerDestroyAllRecordsMethod); | 82 biod::kBiometricsManagerDestroyAllRecordsMethod); |
| 73 | 83 |
| 74 biod_proxy_->CallMethod(&method_call, | 84 biod_proxy_->CallMethod(&method_call, |
| 75 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 85 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 76 dbus::ObjectProxy::EmptyResponseCallback()); | 86 base::Bind(&OnVoidResponse, callback)); |
| 77 } | 87 } |
| 78 | 88 |
| 79 void StartAuthSession(const ObjectPathCallback& callback) override { | 89 void StartAuthSession(const ObjectPathCallback& callback) override { |
| 80 dbus::MethodCall method_call( | 90 dbus::MethodCall method_call( |
| 81 biod::kBiometricsManagerInterface, | 91 biod::kBiometricsManagerInterface, |
| 82 biod::kBiometricsManagerStartAuthSessionMethod); | 92 biod::kBiometricsManagerStartAuthSessionMethod); |
| 83 | 93 |
| 84 biod_proxy_->CallMethod( | 94 biod_proxy_->CallMethod( |
| 85 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 95 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 86 base::Bind(&BiodClientImpl::OnStartAuthSession, | 96 base::Bind(&BiodClientImpl::OnStartAuthSession, |
| 87 weak_ptr_factory_.GetWeakPtr(), callback)); | 97 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 88 } | 98 } |
| 89 | 99 |
| 90 void RequestType(const BiometricTypeCallback& callback) override { | 100 void RequestType(const BiometricTypeCallback& callback) override { |
| 91 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface, | 101 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface, |
| 92 dbus::kDBusPropertiesGet); | 102 dbus::kDBusPropertiesGet); |
| 93 dbus::MessageWriter writer(&method_call); | 103 dbus::MessageWriter writer(&method_call); |
| 94 writer.AppendString(biod::kBiometricsManagerInterface); | 104 writer.AppendString(biod::kBiometricsManagerInterface); |
| 95 writer.AppendString(biod::kBiometricsManagerBiometricTypeProperty); | 105 writer.AppendString(biod::kBiometricsManagerBiometricTypeProperty); |
| 96 | 106 |
| 97 biod_proxy_->CallMethod( | 107 biod_proxy_->CallMethod( |
| 98 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 108 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 99 base::Bind(&BiodClientImpl::OnRequestType, | 109 base::Bind(&BiodClientImpl::OnRequestType, |
| 100 weak_ptr_factory_.GetWeakPtr(), callback)); | 110 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 101 } | 111 } |
| 102 | 112 |
| 103 void CancelEnrollSession( | 113 void CancelEnrollSession(const dbus::ObjectPath& enroll_session_path, |
| 104 const dbus::ObjectPath& enroll_session_path) override { | 114 const VoidDBusMethodCallback& callback) override { |
| 105 dbus::MethodCall method_call(biod::kEnrollSessionInterface, | 115 dbus::MethodCall method_call(biod::kEnrollSessionInterface, |
| 106 biod::kEnrollSessionCancelMethod); | 116 biod::kEnrollSessionCancelMethod); |
| 107 | 117 |
| 108 dbus::ObjectProxy* enroll_session_proxy = | 118 dbus::ObjectProxy* enroll_session_proxy = |
| 109 bus_->GetObjectProxy(biod::kBiodServiceName, enroll_session_path); | 119 bus_->GetObjectProxy(biod::kBiodServiceName, enroll_session_path); |
| 110 enroll_session_proxy->CallMethod( | 120 enroll_session_proxy->CallMethod(&method_call, |
| 111 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 121 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 112 dbus::ObjectProxy::EmptyResponseCallback()); | 122 base::Bind(&OnVoidResponse, callback)); |
| 113 } | 123 } |
| 114 | 124 |
| 115 void EndAuthSession(const dbus::ObjectPath& auth_session_path) override { | 125 void EndAuthSession(const dbus::ObjectPath& auth_session_path, |
| 126 const VoidDBusMethodCallback& callback) override { |
| 116 dbus::MethodCall method_call(biod::kAuthSessionInterface, | 127 dbus::MethodCall method_call(biod::kAuthSessionInterface, |
| 117 biod::kAuthSessionEndMethod); | 128 biod::kAuthSessionEndMethod); |
| 118 | 129 |
| 119 dbus::ObjectProxy* auth_session_proxy = | 130 dbus::ObjectProxy* auth_session_proxy = |
| 120 bus_->GetObjectProxy(biod::kBiodServiceName, auth_session_path); | 131 bus_->GetObjectProxy(biod::kBiodServiceName, auth_session_path); |
| 121 auth_session_proxy->CallMethod(&method_call, | 132 auth_session_proxy->CallMethod(&method_call, |
| 122 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 133 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 123 dbus::ObjectProxy::EmptyResponseCallback()); | 134 base::Bind(&OnVoidResponse, callback)); |
| 124 } | 135 } |
| 125 | 136 |
| 126 void SetRecordLabel(const dbus::ObjectPath& record_path, | 137 void SetRecordLabel(const dbus::ObjectPath& record_path, |
| 127 const std::string& label) override { | 138 const std::string& label, |
| 139 const VoidDBusMethodCallback& callback) override { |
| 128 dbus::MethodCall method_call(biod::kRecordInterface, | 140 dbus::MethodCall method_call(biod::kRecordInterface, |
| 129 biod::kRecordSetLabelMethod); | 141 biod::kRecordSetLabelMethod); |
| 130 dbus::MessageWriter writer(&method_call); | 142 dbus::MessageWriter writer(&method_call); |
| 131 writer.AppendString(label); | 143 writer.AppendString(label); |
| 132 | 144 |
| 133 dbus::ObjectProxy* record_proxy = | 145 dbus::ObjectProxy* record_proxy = |
| 134 bus_->GetObjectProxy(biod::kBiodServiceName, record_path); | 146 bus_->GetObjectProxy(biod::kBiodServiceName, record_path); |
| 135 record_proxy->CallMethod(&method_call, | 147 record_proxy->CallMethod(&method_call, |
| 136 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 148 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 137 dbus::ObjectProxy::EmptyResponseCallback()); | 149 base::Bind(&OnVoidResponse, callback)); |
| 138 } | 150 } |
| 139 | 151 |
| 140 void RemoveRecord(const dbus::ObjectPath& record_path) override { | 152 void RemoveRecord(const dbus::ObjectPath& record_path, |
| 153 const VoidDBusMethodCallback& callback) override { |
| 141 dbus::MethodCall method_call(biod::kRecordInterface, | 154 dbus::MethodCall method_call(biod::kRecordInterface, |
| 142 biod::kRecordRemoveMethod); | 155 biod::kRecordRemoveMethod); |
| 143 | 156 |
| 144 dbus::ObjectProxy* record_proxy = | 157 dbus::ObjectProxy* record_proxy = |
| 145 bus_->GetObjectProxy(biod::kBiodServiceName, record_path); | 158 bus_->GetObjectProxy(biod::kBiodServiceName, record_path); |
| 146 record_proxy->CallMethod(&method_call, | 159 record_proxy->CallMethod(&method_call, |
| 147 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 160 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 148 dbus::ObjectProxy::EmptyResponseCallback()); | 161 base::Bind(&OnVoidResponse, callback)); |
| 149 } | 162 } |
| 150 | 163 |
| 151 void RequestRecordLabel(const dbus::ObjectPath& record_path, | 164 void RequestRecordLabel(const dbus::ObjectPath& record_path, |
| 152 const LabelCallback& callback) override { | 165 const LabelCallback& callback) override { |
| 153 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface, | 166 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface, |
| 154 dbus::kDBusPropertiesGet); | 167 dbus::kDBusPropertiesGet); |
| 155 dbus::MessageWriter writer(&method_call); | 168 dbus::MessageWriter writer(&method_call); |
| 156 writer.AppendString(biod::kRecordInterface); | 169 writer.AppendString(biod::kRecordInterface); |
| 157 writer.AppendString(biod::kRecordLabelProperty); | 170 writer.AppendString(biod::kRecordLabelProperty); |
| 158 | 171 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 371 |
| 359 // static | 372 // static |
| 360 BiodClient* BiodClient::Create(DBusClientImplementationType type) { | 373 BiodClient* BiodClient::Create(DBusClientImplementationType type) { |
| 361 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 374 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 362 return new BiodClientImpl(); | 375 return new BiodClientImpl(); |
| 363 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 376 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
| 364 return new FakeBiodClient(); | 377 return new FakeBiodClient(); |
| 365 } | 378 } |
| 366 | 379 |
| 367 } // namespace chromeos | 380 } // namespace chromeos |
| OLD | NEW |