Index: chromeos/dbus/biod/fake_biod_client.cc |
diff --git a/chromeos/dbus/biod/fake_biod_client.cc b/chromeos/dbus/biod/fake_biod_client.cc |
index 0ff6ab5d9cf9732bdd43d4da22f608e819f405e0..54df736c0a1f3ce9b31e6765af17c23851f2ba35 100644 |
--- a/chromeos/dbus/biod/fake_biod_client.cc |
+++ b/chromeos/dbus/biod/fake_biod_client.cc |
@@ -5,6 +5,7 @@ |
#include "chromeos/dbus/biod/fake_biod_client.h" |
#include "base/bind.h" |
+#include "base/memory/ptr_util.h" |
#include "base/single_thread_task_runner.h" |
#include "base/threading/thread_task_runner_handle.h" |
#include "dbus/object_path.h" |
@@ -12,23 +13,75 @@ |
namespace chromeos { |
+namespace { |
+ |
+// Path of an enroll session. There should only be one enroll session at a |
+// given time. |
+const char kEnrollSessionObjectPath[] = "/EnrollSession/"; |
+// Header of the path of an record. A unique number will be appended when an |
+// record is created. |
+const char RecordObjectPathPrefix[] = "/Record/"; |
+// Path of an auth session. There should only be one auth sesion at a given |
+// time. |
+const char kAuthSessionObjectPath[] = "/AuthSession/"; |
+ |
+} // namespace |
+ |
FakeBiodClient::FakeBiodClient() {} |
FakeBiodClient::~FakeBiodClient() {} |
-void FakeBiodClient::SendEnrollScanDone(biod::ScanResult type_result, |
+void FakeBiodClient::SendEnrollScanDone(const std::string& fingerprint, |
+ biod::ScanResult type_result, |
bool is_complete) { |
+ // Enroll scan signals do nothing if an enroll session is not happening. |
+ if (current_session_ != FingerprintSession::ENROLL) |
+ return; |
+ |
+ DCHECK(current_record_); |
+ // The fake fingerprint gets appended to the current fake fingerprints. |
+ current_record_->fake_fingerprint.push_back(fingerprint); |
+ |
+ // If the enroll is complete, save the record and exit enroll mode. |
+ if (is_complete) { |
+ records_[current_record_path_] = std::move(current_record_); |
+ current_record_path_ = dbus::ObjectPath(); |
+ current_record_.reset(); |
+ current_session_ = FingerprintSession::NONE; |
+ } |
+ |
for (auto& observer : observers_) |
observer.BiodEnrollScanDoneReceived(type_result, is_complete); |
} |
-void FakeBiodClient::SendAuthScanDone(biod::ScanResult type_result, |
- const AuthScanMatches& matches) { |
+void FakeBiodClient::SendAuthScanDone(const std::string& fingerprint, |
+ biod::ScanResult type_result) { |
+ // Auth scan signals do nothing if an auth session is not happening. |
+ if (current_session_ != FingerprintSession::AUTH) |
+ return; |
+ |
+ AuthScanMatches matches; |
+ // Iterate through all the records to check if fingerprint is a match and |
+ // populate |matches| accordingly. This searches through all the records and |
+ // then each record's fake fingerprint, but neither of these should ever have |
+ // more than five entries. |
+ for (const auto& record : records_) { |
+ if (std::find(record.second->fake_fingerprint.begin(), |
+ record.second->fake_fingerprint.end(), |
+ fingerprint) != record.second->fake_fingerprint.end()) { |
+ std::string user_id = record.second->user_id; |
Daniel Erat
2017/04/07 23:40:56
const std::string& ?
sammiequon
2017/04/08 00:43:32
Done.
|
+ matches[user_id].push_back(record.second->label); |
+ } |
+ } |
+ |
for (auto& observer : observers_) |
observer.BiodAuthScanDoneReceived(type_result, matches); |
} |
void FakeBiodClient::SendSessionFailed() { |
+ if (current_session_ == FingerprintSession::NONE) |
+ return; |
+ |
for (auto& observer : observers_) |
observer.BiodSessionFailedReceived(); |
} |
@@ -47,48 +100,102 @@ bool FakeBiodClient::HasObserver(const Observer* observer) const { |
return observers_.HasObserver(observer); |
} |
-void FakeBiodClient::StartEnrollSession(const std::string& /* user_id */, |
- const std::string& /* label */, |
+void FakeBiodClient::StartEnrollSession(const std::string& user_id, |
+ const std::string& label, |
const ObjectPathCallback& callback) { |
+ DCHECK_EQ(current_session_, FingerprintSession::NONE); |
+ |
+ // Create the enrollment with |user_id|, |label| and a empty fake fingerprint. |
+ current_record_path_ = dbus::ObjectPath( |
+ RecordObjectPathPrefix + std::to_string(next_record_unique_id_++)); |
+ current_record_ = base::MakeUnique<FakeRecord>(); |
+ current_record_->user_id = user_id; |
+ current_record_->label = label; |
+ current_session_ = FingerprintSession::ENROLL; |
+ |
base::ThreadTaskRunnerHandle::Get()->PostTask( |
- FROM_HERE, base::Bind(callback, dbus::ObjectPath())); |
+ FROM_HERE, |
+ base::Bind(callback, dbus::ObjectPath(kEnrollSessionObjectPath))); |
} |
-void FakeBiodClient::GetRecordsForUser(const std::string& /* user_id */, |
+void FakeBiodClient::GetRecordsForUser(const std::string& user_id, |
const UserRecordsCallback& callback) { |
+ std::vector<dbus::ObjectPath> records_object_paths; |
+ for (const auto& record : records_) { |
+ if (record.second->user_id == user_id) |
+ records_object_paths.push_back(record.first); |
+ } |
+ |
base::ThreadTaskRunnerHandle::Get()->PostTask( |
- FROM_HERE, base::Bind(callback, std::vector<dbus::ObjectPath>())); |
+ FROM_HERE, base::Bind(callback, records_object_paths)); |
} |
-void FakeBiodClient::DestroyAllRecords() {} |
+void FakeBiodClient::DestroyAllRecords() { |
+ records_.clear(); |
+} |
void FakeBiodClient::StartAuthSession(const ObjectPathCallback& callback) { |
+ DCHECK_EQ(current_session_, FingerprintSession::NONE); |
+ |
+ current_session_ = FingerprintSession::AUTH; |
base::ThreadTaskRunnerHandle::Get()->PostTask( |
- FROM_HERE, base::Bind(callback, dbus::ObjectPath())); |
+ FROM_HERE, |
+ base::Bind(callback, dbus::ObjectPath(kAuthSessionObjectPath))); |
} |
void FakeBiodClient::RequestType(const BiometricTypeCallback& callback) { |
base::ThreadTaskRunnerHandle::Get()->PostTask( |
FROM_HERE, |
- base::Bind(callback, biod::BiometricType::BIOMETRIC_TYPE_UNKNOWN)); |
+ base::Bind(callback, biod::BiometricType::BIOMETRIC_TYPE_FINGERPRINT)); |
} |
void FakeBiodClient::CancelEnrollSession( |
- const dbus::ObjectPath& /* enroll_session_path */) {} |
+ const dbus::ObjectPath& enroll_session_path) { |
+ DCHECK_EQ(current_session_, FingerprintSession::ENROLL); |
+ DCHECK_EQ(enroll_session_path.value(), kEnrollSessionObjectPath); |
+ |
+ // Clean up the in progress enrollment. |
+ current_record_.reset(); |
+ current_record_path_ = dbus::ObjectPath(); |
+ current_session_ = FingerprintSession::NONE; |
+} |
+ |
+void FakeBiodClient::EndAuthSession(const dbus::ObjectPath& auth_session_path) { |
+ DCHECK_EQ(current_session_, FingerprintSession::AUTH); |
+ DCHECK_EQ(auth_session_path.value(), kAuthSessionObjectPath); |
+ |
+ current_session_ = FingerprintSession::NONE; |
+} |
+ |
+void FakeBiodClient::SetRecordLabel(const dbus::ObjectPath& record_path, |
+ const std::string& label) { |
+ if (records_.find(record_path) != records_.end()) |
+ records_[record_path]->label = label; |
+} |
-void FakeBiodClient::EndAuthSession( |
- const dbus::ObjectPath& /* auth_session_path */) {} |
+void FakeBiodClient::RemoveRecord(const dbus::ObjectPath& record_path) { |
+ records_.erase(record_path); |
+} |
-void FakeBiodClient::SetRecordLabel(const dbus::ObjectPath& /* record_path */, |
- const std::string& /* label */) {} |
+void FakeBiodClient::RequestRecordLabel(const dbus::ObjectPath& record_path, |
+ const LabelCallback& callback) { |
+ std::string record_label; |
+ if (records_.find(record_path) != records_.end()) |
+ record_label = records_[record_path]->label; |
-void FakeBiodClient::RemoveRecord(const dbus::ObjectPath& /* record_path */) {} |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, base::Bind(callback, record_label)); |
+} |
-void FakeBiodClient::RequestRecordLabel( |
- const dbus::ObjectPath& /* record_path */, |
- const LabelCallback& callback) { |
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
- base::Bind(callback, "")); |
+void FakeBiodClient::Reset() { |
+ records_.clear(); |
+ current_record_.reset(); |
+ current_record_path_ = dbus::ObjectPath(); |
+ current_session_ = FingerprintSession::NONE; |
} |
+FakeBiodClient::FakeRecord::FakeRecord() {} |
+ |
+FakeBiodClient::FakeRecord::~FakeRecord() {} |
+ |
} // namespace chromeos |