Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(955)

Unified Diff: chromeos/dbus/biod/fake_biod_client.cc

Issue 2644233002: cros: Added a fake fingerprint storage class. (Closed)
Patch Set: Fixed patch set 11 errors. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/dbus/biod/fake_biod_client.h ('k') | chromeos/dbus/biod/fake_biod_client_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6eab8cea92a14e7dc369363ed6381d6671315edd..7ab9ccd930d2b4291966ced8df38de057b79a50a 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,27 +13,98 @@
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 kRecordObjectPathPrefix[] = "/Record/";
+
+// Path of an auth session. There should only be one auth sesion at a given
+// time.
+const char kAuthSessionObjectPath[] = "/AuthSession/";
+
+} // namespace
+
+// FakeRecord is the definition of a fake stored fingerprint template.
+struct FakeBiodClient::FakeRecord {
+ 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;
+};
+
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& entry : records_) {
+ const std::unique_ptr<FakeRecord>& record = entry.second;
+ if (std::find(record->fake_fingerprint.begin(),
+ record->fake_fingerprint.end(),
+ fingerprint) != record->fake_fingerprint.end()) {
+ const std::string& user_id = record->user_id;
+ matches[user_id].push_back(record->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();
}
+void FakeBiodClient::Reset() {
+ records_.clear();
+ current_record_.reset();
+ current_record_path_ = dbus::ObjectPath();
+ current_session_ = FingerprintSession::NONE;
+}
+
void FakeBiodClient::Init(dbus::Bus* bus) {}
void FakeBiodClient::AddObserver(Observer* observer) {
@@ -47,67 +119,109 @@ 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(
+ kRecordObjectPathPrefix + 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(const VoidDBusMethodCallback& callback) {
+ records_.clear();
+
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
}
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,
const VoidDBusMethodCallback& callback) {
+ 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;
+
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
}
-void FakeBiodClient::EndAuthSession(
- const dbus::ObjectPath& /* auth_session_path */,
- const VoidDBusMethodCallback& callback) {
+void FakeBiodClient::EndAuthSession(const dbus::ObjectPath& auth_session_path,
+ const VoidDBusMethodCallback& callback) {
+ DCHECK_EQ(current_session_, FingerprintSession::AUTH);
+ DCHECK_EQ(auth_session_path.value(), kAuthSessionObjectPath);
+
+ current_session_ = FingerprintSession::NONE;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
}
-void FakeBiodClient::SetRecordLabel(const dbus::ObjectPath& /* record_path */,
- const std::string& /* label */,
+void FakeBiodClient::SetRecordLabel(const dbus::ObjectPath& record_path,
+ const std::string& label,
const VoidDBusMethodCallback& callback) {
+ if (records_.find(record_path) != records_.end())
+ records_[record_path]->label = label;
+
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
}
-void FakeBiodClient::RemoveRecord(const dbus::ObjectPath& /* record_path */,
+void FakeBiodClient::RemoveRecord(const dbus::ObjectPath& record_path,
const VoidDBusMethodCallback& callback) {
+ records_.erase(record_path);
+
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS));
}
-void FakeBiodClient::RequestRecordLabel(
- const dbus::ObjectPath& /* record_path */,
- const LabelCallback& callback) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback, ""));
+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;
+
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, record_label));
}
} // namespace chromeos
« no previous file with comments | « chromeos/dbus/biod/fake_biod_client.h ('k') | chromeos/dbus/biod/fake_biod_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698