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