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 #ifndef CHROMEOS_DBUS_BIOD_FAKE_BIOD_CLIENT_H_ | 5 #ifndef CHROMEOS_DBUS_BIOD_FAKE_BIOD_CLIENT_H_ |
| 6 #define CHROMEOS_DBUS_BIOD_FAKE_BIOD_CLIENT_H_ | 6 #define CHROMEOS_DBUS_BIOD_FAKE_BIOD_CLIENT_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 8 #include "base/macros.h" | 11 #include "base/macros.h" |
| 9 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 10 #include "chromeos/chromeos_export.h" | 13 #include "chromeos/chromeos_export.h" |
| 11 #include "chromeos/dbus/biod/biod_client.h" | 14 #include "chromeos/dbus/biod/biod_client.h" |
| 15 #include "dbus/object_path.h" | |
| 12 | 16 |
| 13 namespace dbus { | 17 namespace dbus { |
| 14 class Bus; | 18 class Bus; |
| 15 class ObjectPath; | |
| 16 } // namespace dbus | 19 } // namespace dbus |
| 17 | 20 |
| 18 namespace chromeos { | 21 namespace chromeos { |
| 19 | 22 |
| 20 // A fake implementation of BiodClient. | 23 // A fake implementation of BiodClient. It emulates the real Biod daemon by |
| 24 // providing the same API and storing fingerprints locally. A fingerprint is | |
| 25 // represented by a vector of strings. During enrollment, fake enrollments are | |
| 26 // sent as strings. If they are successful they get push backed to the current | |
|
Daniel Erat
2017/04/11 17:50:13
nit: s/push backed/pushed/ or maybe just "added"
sammiequon
2017/04/11 18:37:49
Done.
| |
| 27 // fingerprint, until a completed enroll scan is sent. An attempt scan is also | |
| 28 // sent with a string. If that string matches any string in the stored | |
| 29 // fingerprint vector, it is considered a match. | |
| 21 class CHROMEOS_EXPORT FakeBiodClient : public BiodClient { | 30 class CHROMEOS_EXPORT FakeBiodClient : public BiodClient { |
| 22 public: | 31 public: |
| 23 FakeBiodClient(); | 32 FakeBiodClient(); |
| 24 ~FakeBiodClient() override; | 33 ~FakeBiodClient() override; |
| 25 | 34 |
| 26 // Emulates the biod daemon by sending events which the daemon normally sends. | 35 // Emulates the biod daemon by sending events which the daemon normally sends. |
| 27 // Notifies |observers_| about various events. These will be used in tests. | 36 // Notifies |observers_| about various events. These will be used in tests. |
| 28 void SendEnrollScanDone(biod::ScanResult type_result, bool is_complete); | 37 |
| 29 void SendAuthScanDone(biod::ScanResult type_result, | 38 // Emulates a scan that occurs during enrolling a new fingerprint. |
| 30 const AuthScanMatches& matches); | 39 // |fingerprint| is the fake data of the finger as a string. If |is_complete| |
| 40 // is true the enroll session is finished, and the record is stored. | |
| 41 void SendEnrollScanDone(const std::string& fingerprint, | |
| 42 biod::ScanResult type_result, | |
| 43 bool is_complete); | |
| 44 // Emulates a scan that occurs during a authentication session. |fingerprint| | |
| 45 // is a string which represents the finger, and will be compared with all the | |
| 46 // stored fingerprints. | |
| 47 void SendAuthScanDone(const std::string& fingerprint, | |
| 48 biod::ScanResult type_result); | |
| 31 void SendSessionFailed(); | 49 void SendSessionFailed(); |
| 32 | 50 |
| 51 // Clears all stored and current records from the fake storage. | |
| 52 void Reset(); | |
| 53 | |
| 33 // BiodClient: | 54 // BiodClient: |
| 34 void Init(dbus::Bus* bus) override; | 55 void Init(dbus::Bus* bus) override; |
| 35 void AddObserver(Observer* observer) override; | 56 void AddObserver(Observer* observer) override; |
| 36 void RemoveObserver(Observer* observer) override; | 57 void RemoveObserver(Observer* observer) override; |
| 37 bool HasObserver(const Observer* observer) const override; | 58 bool HasObserver(const Observer* observer) const override; |
| 38 void StartEnrollSession(const std::string& user_id, | 59 void StartEnrollSession(const std::string& user_id, |
| 39 const std::string& label, | 60 const std::string& label, |
| 40 const ObjectPathCallback& callback) override; | 61 const ObjectPathCallback& callback) override; |
| 41 void GetRecordsForUser(const std::string& user_id, | 62 void GetRecordsForUser(const std::string& user_id, |
| 42 const UserRecordsCallback& callback) override; | 63 const UserRecordsCallback& callback) override; |
| 43 void DestroyAllRecords(const VoidDBusMethodCallback& callback) override; | 64 void DestroyAllRecords(const VoidDBusMethodCallback& callback) override; |
| 44 void StartAuthSession(const ObjectPathCallback& callback) override; | 65 void StartAuthSession(const ObjectPathCallback& callback) override; |
| 45 void RequestType(const BiometricTypeCallback& callback) override; | 66 void RequestType(const BiometricTypeCallback& callback) override; |
| 46 void CancelEnrollSession(const dbus::ObjectPath& enroll_session_path, | 67 void CancelEnrollSession(const dbus::ObjectPath& enroll_session_path, |
| 47 const VoidDBusMethodCallback& callback) override; | 68 const VoidDBusMethodCallback& callback) override; |
| 48 void EndAuthSession(const dbus::ObjectPath& auth_session_path, | 69 void EndAuthSession(const dbus::ObjectPath& auth_session_path, |
| 49 const VoidDBusMethodCallback& callback) override; | 70 const VoidDBusMethodCallback& callback) override; |
| 50 void SetRecordLabel(const dbus::ObjectPath& record_path, | 71 void SetRecordLabel(const dbus::ObjectPath& record_path, |
| 51 const std::string& label, | 72 const std::string& label, |
| 52 const VoidDBusMethodCallback& callback) override; | 73 const VoidDBusMethodCallback& callback) override; |
| 53 void RemoveRecord(const dbus::ObjectPath& record_path, | 74 void RemoveRecord(const dbus::ObjectPath& record_path, |
| 54 const VoidDBusMethodCallback& callback) override; | 75 const VoidDBusMethodCallback& callback) override; |
| 55 void RequestRecordLabel(const dbus::ObjectPath& record_path, | 76 void RequestRecordLabel(const dbus::ObjectPath& record_path, |
| 56 const LabelCallback& callback) override; | 77 const LabelCallback& callback) override; |
| 57 | 78 |
| 58 private: | 79 private: |
| 80 // The current session of fingerprint storage. The session determines which | |
| 81 // events will be sent from user finger touches. | |
| 82 enum class FingerprintSession { | |
| 83 NONE, | |
| 84 ENROLL, | |
| 85 AUTH, | |
| 86 }; | |
| 87 | |
| 88 // FakeRecord is the definition of a fake stored fingerprint template. | |
| 89 struct FakeRecord { | |
|
Daniel Erat
2017/04/11 17:50:13
just forward-declare this here and define it in th
sammiequon
2017/04/11 18:37:49
Done.
| |
| 90 FakeRecord(); | |
| 91 ~FakeRecord(); | |
|
Daniel Erat
2017/04/11 17:50:13
nit: i don't think you need this c'tor and d'tor
sammiequon
2017/04/11 18:37:49
Done.
| |
| 92 | |
| 93 std::string user_id; | |
| 94 std::string label; | |
| 95 // A fake fingerprint is a vector which consists of all the strings which | |
| 96 // were "pressed" during the enroll session. | |
| 97 std::vector<std::string> fake_fingerprint; | |
| 98 }; | |
| 99 | |
| 100 // The stored fingerprints. | |
| 101 std::map<dbus::ObjectPath, std::unique_ptr<FakeRecord>> records_; | |
| 102 | |
| 103 // Current record in process of getting enrolled and its path. These are | |
| 104 // assigned at the start of an enroll session and freed when the enroll | |
| 105 // session is finished or cancelled. | |
| 106 dbus::ObjectPath current_record_path_; | |
| 107 std::unique_ptr<FakeRecord> current_record_; | |
| 108 | |
| 109 // Unique indentifier that gets updated each time an enroll session is started | |
| 110 // to ensure each record is stored at a different path. | |
| 111 int next_record_unique_id_ = 1; | |
| 112 | |
| 113 // The current session of the fake storage. | |
| 114 FingerprintSession current_session_ = FingerprintSession::NONE; | |
| 115 | |
| 59 base::ObserverList<Observer> observers_; | 116 base::ObserverList<Observer> observers_; |
| 60 | 117 |
| 61 DISALLOW_COPY_AND_ASSIGN(FakeBiodClient); | 118 DISALLOW_COPY_AND_ASSIGN(FakeBiodClient); |
| 62 }; | 119 }; |
| 63 | 120 |
| 64 } // namespace chromeos | 121 } // namespace chromeos |
| 65 | 122 |
| 66 #endif // CHROMEOS_DBUS_BIOD_FAKE_BIOD_CLIENT_H_ | 123 #endif // CHROMEOS_DBUS_BIOD_FAKE_BIOD_CLIENT_H_ |
| OLD | NEW |