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" |
| 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 |
|
Daniel Erat
2017/05/03 20:47:34
nit: delete this blank line
xiaoyinh(OOO Sep 11-29)
2017/05/04 00:29:51
Done.
| |
| 343 if (!reader.PopUint32(&scan_result) || | 341 if (!reader.PopArrayOfBytesAsProto(&protobuf)) { |
| 344 !reader.PopBool(&enroll_session_complete)) { | 342 LOG(ERROR) << "Unable to decode protocol buffer from " |
| 345 LOG(ERROR) << "Error reading signal from biometrics: " | 343 << biod::kBiometricsManagerEnrollScanDoneSignal << " signal."; |
| 346 << signal->ToString(); | |
| 347 return; | 344 return; |
| 348 } | 345 } |
| 349 | 346 |
| 350 if (enroll_session_complete) | 347 biod::ScanResult scan_result = protobuf.scan_result(); |
| 351 current_enroll_session_path_.reset(); | 348 bool enroll_session_complete = protobuf.done(); |
| 349 int32_t percent_complete = | |
| 350 protobuf.has_percent_complete() ? protobuf.percent_complete() : -1; | |
|
Daniel Erat
2017/05/03 20:47:34
i can understand caching percent_complete in a loc
xiaoyinh(OOO Sep 11-29)
2017/05/04 00:29:51
Thanks, changed.
| |
| 352 | 351 |
| 353 for (auto& observer : observers_) { | 352 for (auto& observer : observers_) { |
| 354 observer.BiodEnrollScanDoneReceived( | 353 observer.BiodEnrollScanDoneReceived(scan_result, enroll_session_complete, |
| 355 static_cast<biod::ScanResult>(scan_result), enroll_session_complete); | 354 percent_complete); |
| 356 } | 355 } |
| 357 } | 356 } |
| 358 | 357 |
| 359 void AuthScanDoneReceived(dbus::Signal* signal) { | 358 void AuthScanDoneReceived(dbus::Signal* signal) { |
| 360 dbus::MessageReader signal_reader(signal); | 359 dbus::MessageReader signal_reader(signal); |
| 361 dbus::MessageReader array_reader(nullptr); | 360 dbus::MessageReader array_reader(nullptr); |
| 362 uint32_t scan_result; | 361 uint32_t scan_result; |
| 363 AuthScanMatches matches; | 362 AuthScanMatches matches; |
| 364 if (!signal_reader.PopUint32(&scan_result) || | 363 if (!signal_reader.PopUint32(&scan_result) || |
| 365 !signal_reader.PopArray(&array_reader)) { | 364 !signal_reader.PopArray(&array_reader)) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 | 412 |
| 414 // static | 413 // static |
| 415 BiodClient* BiodClient::Create(DBusClientImplementationType type) { | 414 BiodClient* BiodClient::Create(DBusClientImplementationType type) { |
| 416 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 415 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 417 return new BiodClientImpl(); | 416 return new BiodClientImpl(); |
| 418 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 417 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
| 419 return new FakeBiodClient(); | 418 return new FakeBiodClient(); |
| 420 } | 419 } |
| 421 | 420 |
| 422 } // namespace chromeos | 421 } // namespace chromeos |
| OLD | NEW |