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 "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/stringprintf.h" |
12 #include "chromeos/dbus/biod/fake_biod_client.h" | 13 #include "chromeos/dbus/biod/fake_biod_client.h" |
| 14 #include "chromeos/dbus/biod/messages.pb.h" |
13 #include "dbus/bus.h" | 15 #include "dbus/bus.h" |
14 #include "dbus/message.h" | 16 #include "dbus/message.h" |
15 #include "dbus/object_path.h" | 17 #include "dbus/object_path.h" |
16 #include "dbus/object_proxy.h" | 18 #include "dbus/object_proxy.h" |
17 | 19 |
18 namespace chromeos { | 20 namespace chromeos { |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 // TODO(xiaoyinh@): Use the constant from service_constants.h | |
23 // crbug.com/713420 | |
24 const char kBiometricsManagerPath[] = | |
25 "/org/chromium/BiometricsDaemon/FpcBiometricsManager"; | |
26 | |
27 // D-Bus response handler for methods that use void callbacks. | 24 // D-Bus response handler for methods that use void callbacks. |
28 void OnVoidResponse(const VoidDBusMethodCallback& callback, | 25 void OnVoidResponse(const VoidDBusMethodCallback& callback, |
29 dbus::Response* response) { | 26 dbus::Response* response) { |
30 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE); | 27 callback.Run(response ? DBUS_METHOD_CALL_SUCCESS : DBUS_METHOD_CALL_FAILURE); |
31 } | 28 } |
32 | 29 |
33 } // namespace | 30 } // namespace |
34 | 31 |
35 // The BiodClient implementation used in production. | 32 // The BiodClient implementation used in production. |
36 class BiodClientImpl : public BiodClient { | 33 class BiodClientImpl : public BiodClient { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 record_proxy->CallMethod( | 201 record_proxy->CallMethod( |
205 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 202 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
206 base::Bind(&BiodClientImpl::OnRequestRecordLabel, | 203 base::Bind(&BiodClientImpl::OnRequestRecordLabel, |
207 weak_ptr_factory_.GetWeakPtr(), callback)); | 204 weak_ptr_factory_.GetWeakPtr(), callback)); |
208 } | 205 } |
209 | 206 |
210 protected: | 207 protected: |
211 void Init(dbus::Bus* bus) override { | 208 void Init(dbus::Bus* bus) override { |
212 bus_ = bus; | 209 bus_ = bus; |
213 | 210 |
214 biod_proxy_ = bus->GetObjectProxy(biod::kBiodServiceName, | 211 dbus::ObjectPath fpc_bio_path = dbus::ObjectPath(base::StringPrintf( |
215 dbus::ObjectPath(kBiometricsManagerPath)); | 212 "%s/%s", biod::kBiodServicePath, biod::kFpcBiometricsManagerName)); |
| 213 biod_proxy_ = bus->GetObjectProxy(biod::kBiodServiceName, fpc_bio_path); |
216 | 214 |
217 biod_proxy_->SetNameOwnerChangedCallback( | 215 biod_proxy_->SetNameOwnerChangedCallback( |
218 base::Bind(&BiodClientImpl::NameOwnerChangedReceived, | 216 base::Bind(&BiodClientImpl::NameOwnerChangedReceived, |
219 weak_ptr_factory_.GetWeakPtr())); | 217 weak_ptr_factory_.GetWeakPtr())); |
220 | 218 |
221 biod_proxy_->ConnectToSignal( | 219 biod_proxy_->ConnectToSignal( |
222 biod::kBiometricsManagerInterface, | 220 biod::kBiometricsManagerInterface, |
223 biod::kBiometricsManagerEnrollScanDoneSignal, | 221 biod::kBiometricsManagerEnrollScanDoneSignal, |
224 base::Bind(&BiodClientImpl::EnrollScanDoneReceived, | 222 base::Bind(&BiodClientImpl::EnrollScanDoneReceived, |
225 weak_ptr_factory_.GetWeakPtr()), | 223 weak_ptr_factory_.GetWeakPtr()), |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 current_auth_session_path_.reset(); | 329 current_auth_session_path_.reset(); |
332 | 330 |
333 if (!new_owner.empty()) { | 331 if (!new_owner.empty()) { |
334 for (auto& observer : observers_) | 332 for (auto& observer : observers_) |
335 observer.BiodServiceRestarted(); | 333 observer.BiodServiceRestarted(); |
336 } | 334 } |
337 } | 335 } |
338 | 336 |
339 void EnrollScanDoneReceived(dbus::Signal* signal) { | 337 void EnrollScanDoneReceived(dbus::Signal* signal) { |
340 dbus::MessageReader reader(signal); | 338 dbus::MessageReader reader(signal); |
341 uint32_t scan_result; | 339 biod::EnrollScanDone protobuf; |
342 bool enroll_session_complete; | 340 if (!reader.PopArrayOfBytesAsProto(&protobuf)) { |
343 if (!reader.PopUint32(&scan_result) || | 341 LOG(ERROR) << "Unable to decode protocol buffer from " |
344 !reader.PopBool(&enroll_session_complete)) { | 342 << biod::kBiometricsManagerEnrollScanDoneSignal << " signal."; |
345 LOG(ERROR) << "Error reading signal from biometrics: " | |
346 << signal->ToString(); | |
347 return; | 343 return; |
348 } | 344 } |
349 | 345 |
350 if (enroll_session_complete) | 346 int percent_complete = |
351 current_enroll_session_path_.reset(); | 347 protobuf.has_percent_complete() ? protobuf.percent_complete() : -1; |
352 | 348 |
353 for (auto& observer : observers_) { | 349 for (auto& observer : observers_) { |
354 observer.BiodEnrollScanDoneReceived( | 350 observer.BiodEnrollScanDoneReceived(protobuf.scan_result(), |
355 static_cast<biod::ScanResult>(scan_result), enroll_session_complete); | 351 protobuf.done(), percent_complete); |
356 } | 352 } |
357 } | 353 } |
358 | 354 |
359 void AuthScanDoneReceived(dbus::Signal* signal) { | 355 void AuthScanDoneReceived(dbus::Signal* signal) { |
360 dbus::MessageReader signal_reader(signal); | 356 dbus::MessageReader signal_reader(signal); |
361 dbus::MessageReader array_reader(nullptr); | 357 dbus::MessageReader array_reader(nullptr); |
362 uint32_t scan_result; | 358 uint32_t scan_result; |
363 AuthScanMatches matches; | 359 AuthScanMatches matches; |
364 if (!signal_reader.PopUint32(&scan_result) || | 360 if (!signal_reader.PopUint32(&scan_result) || |
365 !signal_reader.PopArray(&array_reader)) { | 361 !signal_reader.PopArray(&array_reader)) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 409 |
414 // static | 410 // static |
415 BiodClient* BiodClient::Create(DBusClientImplementationType type) { | 411 BiodClient* BiodClient::Create(DBusClientImplementationType type) { |
416 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 412 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
417 return new BiodClientImpl(); | 413 return new BiodClientImpl(); |
418 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 414 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
419 return new FakeBiodClient(); | 415 return new FakeBiodClient(); |
420 } | 416 } |
421 | 417 |
422 } // namespace chromeos | 418 } // namespace chromeos |
OLD | NEW |