Chromium Code Reviews| Index: chromeos/dbus/biod/fake_biod_client.h |
| diff --git a/chromeos/dbus/biod/fake_biod_client.h b/chromeos/dbus/biod/fake_biod_client.h |
| index 171826f8eafac47f4e316a3e3889dd1291f9bdb4..18bf4029fa13f675755945207e9aa011202fb785 100644 |
| --- a/chromeos/dbus/biod/fake_biod_client.h |
| +++ b/chromeos/dbus/biod/fake_biod_client.h |
| @@ -5,19 +5,28 @@ |
| #ifndef CHROMEOS_DBUS_BIOD_FAKE_BIOD_CLIENT_H_ |
| #define CHROMEOS_DBUS_BIOD_FAKE_BIOD_CLIENT_H_ |
| +#include <map> |
| +#include <string> |
| + |
| #include "base/macros.h" |
| #include "base/observer_list.h" |
| #include "chromeos/chromeos_export.h" |
| #include "chromeos/dbus/biod/biod_client.h" |
| +#include "dbus/object_path.h" |
| namespace dbus { |
| class Bus; |
| -class ObjectPath; |
| } // namespace dbus |
| namespace chromeos { |
| -// A fake implementation of BiodClient. |
| +// A fake implementation of BiodClient. It emulates the real Biod daemon by |
| +// providing the same API and storing fingerprints locally. A fingerprint is |
| +// represented by a vector of strings. During enrollment, fake enrollments are |
| +// 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.
|
| +// fingerprint, until a completed enroll scan is sent. An attempt scan is also |
| +// sent with a string. If that string matches any string in the stored |
| +// fingerprint vector, it is considered a match. |
| class CHROMEOS_EXPORT FakeBiodClient : public BiodClient { |
| public: |
| FakeBiodClient(); |
| @@ -25,11 +34,23 @@ class CHROMEOS_EXPORT FakeBiodClient : public BiodClient { |
| // Emulates the biod daemon by sending events which the daemon normally sends. |
| // Notifies |observers_| about various events. These will be used in tests. |
| - void SendEnrollScanDone(biod::ScanResult type_result, bool is_complete); |
| - void SendAuthScanDone(biod::ScanResult type_result, |
| - const AuthScanMatches& matches); |
| + |
| + // Emulates a scan that occurs during enrolling a new fingerprint. |
| + // |fingerprint| is the fake data of the finger as a string. If |is_complete| |
| + // is true the enroll session is finished, and the record is stored. |
| + void SendEnrollScanDone(const std::string& fingerprint, |
| + biod::ScanResult type_result, |
| + bool is_complete); |
| + // Emulates a scan that occurs during a authentication session. |fingerprint| |
| + // is a string which represents the finger, and will be compared with all the |
| + // stored fingerprints. |
| + void SendAuthScanDone(const std::string& fingerprint, |
| + biod::ScanResult type_result); |
| void SendSessionFailed(); |
| + // Clears all stored and current records from the fake storage. |
| + void Reset(); |
| + |
| // BiodClient: |
| void Init(dbus::Bus* bus) override; |
| void AddObserver(Observer* observer) override; |
| @@ -56,6 +77,42 @@ class CHROMEOS_EXPORT FakeBiodClient : public BiodClient { |
| const LabelCallback& callback) override; |
| private: |
| + // The current session of fingerprint storage. The session determines which |
| + // events will be sent from user finger touches. |
| + enum class FingerprintSession { |
| + NONE, |
| + ENROLL, |
| + AUTH, |
| + }; |
| + |
| + // FakeRecord is the definition of a fake stored fingerprint template. |
| + 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.
|
| + FakeRecord(); |
| + ~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.
|
| + |
| + std::string user_id; |
| + std::string label; |
| + // A fake fingerprint is a vector which consists of all the strings which |
| + // were "pressed" during the enroll session. |
| + std::vector<std::string> fake_fingerprint; |
| + }; |
| + |
| + // The stored fingerprints. |
| + std::map<dbus::ObjectPath, std::unique_ptr<FakeRecord>> records_; |
| + |
| + // Current record in process of getting enrolled and its path. These are |
| + // assigned at the start of an enroll session and freed when the enroll |
| + // session is finished or cancelled. |
| + dbus::ObjectPath current_record_path_; |
| + std::unique_ptr<FakeRecord> current_record_; |
| + |
| + // Unique indentifier that gets updated each time an enroll session is started |
| + // to ensure each record is stored at a different path. |
| + int next_record_unique_id_ = 1; |
| + |
| + // The current session of the fake storage. |
| + FingerprintSession current_session_ = FingerprintSession::NONE; |
| + |
| base::ObserverList<Observer> observers_; |
| DISALLOW_COPY_AND_ASSIGN(FakeBiodClient); |