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 OnVoidMethod(const VoidDBusMethodCallback& callback, | |
Daniel Erat
2017/04/08 01:13:32
nit: OnVoidResponse?
sammiequon
2017/04/08 01:31:47
Done.
| |
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(&OnVoidMethod, 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(&OnVoidMethod, 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(&OnVoidMethod, 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(&OnVoidMethod, 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(&OnVoidMethod, 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 dbus::MessageReader reader(response); | 264 dbus::MessageReader reader(response); |
252 if (!reader.PopVariantOfUint32(&result)) { | 265 if (!reader.PopVariantOfUint32(&result)) { |
253 LOG(ERROR) << biod::kBiometricsManagerBiometricTypeProperty | 266 LOG(ERROR) << biod::kBiometricsManagerBiometricTypeProperty |
254 << " had incorrect response."; | 267 << " had incorrect response."; |
255 } | 268 } |
256 } | 269 } |
257 | 270 |
258 callback.Run(static_cast<biod::BiometricType>(result)); | 271 callback.Run(static_cast<biod::BiometricType>(result)); |
259 } | 272 } |
260 | 273 |
261 void OnRequestRecordLabel(const LabelCallback& callback, | |
Daniel Erat
2017/04/08 01:13:32
did you re-run the tests? this looks like it was d
sammiequon
2017/04/08 01:31:47
Oh no, oops. Good thing you caught it..
| |
262 dbus::Response* response) { | |
263 std::string result; | |
264 if (response) { | |
265 dbus::MessageReader reader(response); | |
266 if (!reader.PopString(&result)) | |
267 LOG(ERROR) << biod::kRecordLabelProperty << " had incorrect response."; | |
268 } | |
269 | |
270 callback.Run(result); | |
271 } | |
272 | |
273 // Called when the biometrics signal is initially connected. | 274 // Called when the biometrics signal is initially connected. |
274 void OnSignalConnected(const std::string& interface_name, | 275 void OnSignalConnected(const std::string& interface_name, |
275 const std::string& signal_name, | 276 const std::string& signal_name, |
276 bool success) { | 277 bool success) { |
277 LOG_IF(ERROR, !success) | 278 LOG_IF(ERROR, !success) |
278 << "Failed to connect to biometrics signal: " << signal_name; | 279 << "Failed to connect to biometrics signal: " << signal_name; |
279 } | 280 } |
280 | 281 |
281 void NameOwnerChangedReceived(const std::string& /* old_owner */, | 282 void NameOwnerChangedReceived(const std::string& /* old_owner */, |
282 const std::string& new_owner) { | 283 const std::string& new_owner) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 | 359 |
359 // static | 360 // static |
360 BiodClient* BiodClient::Create(DBusClientImplementationType type) { | 361 BiodClient* BiodClient::Create(DBusClientImplementationType type) { |
361 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 362 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
362 return new BiodClientImpl(); | 363 return new BiodClientImpl(); |
363 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 364 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
364 return new FakeBiodClient(); | 365 return new FakeBiodClient(); |
365 } | 366 } |
366 | 367 |
367 } // namespace chromeos | 368 } // namespace chromeos |
OLD | NEW |