biod: Remove factory method and use constructor
We don't need the factory method anymore now that we don't have to call
the Init method when creating a CrosFpBiometricsManager.
BUG=b:76037094
TEST=FEATURES="test" emerge-hatch biod
Change-Id: I8c4e6effad2c0bdd5be4384235c617c61a4433a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2401925
Tested-by: Tom Hughes <tomhughes@chromium.org>
Commit-Queue: Tom Hughes <tomhughes@chromium.org>
Reviewed-by: Yicheng Li <yichengli@chromium.org>
diff --git a/biod/biometrics_daemon.cc b/biod/biometrics_daemon.cc
index 7592f52..637008d 100644
--- a/biod/biometrics_daemon.cc
+++ b/biod/biometrics_daemon.cc
@@ -14,6 +14,7 @@
#include <chromeos/dbus/service_constants.h>
#include "biod/cros_fp_biometrics_manager.h"
+#include "biod/power_button_filter.h"
#include "biod/proto_bindings/constants.pb.h"
#include "biod/proto_bindings/messages.pb.h"
@@ -425,8 +426,8 @@
"%s/%s", kBiodServicePath, kCrosFpBiometricsManagerName));
auto biod_metrics = std::make_unique<BiodMetrics>();
- auto cros_fp_bio = CrosFpBiometricsManager::Create(
- bus_,
+ auto cros_fp_bio = std::make_unique<CrosFpBiometricsManager>(
+ PowerButtonFilter::Create(bus_),
CrosFpDevice::Create(biod_metrics.get(),
std::make_unique<EcCommandFactory>()),
std::move(biod_metrics));
diff --git a/biod/cros_fp_biometrics_manager.cc b/biod/cros_fp_biometrics_manager.cc
index 0d9962d..210e7c9 100644
--- a/biod/cros_fp_biometrics_manager.cc
+++ b/biod/cros_fp_biometrics_manager.cc
@@ -156,22 +156,6 @@
return biod_storage_.ReadRecordsForSingleUser(user_id);
}
-std::unique_ptr<CrosFpBiometricsManager> CrosFpBiometricsManager::Create(
- const scoped_refptr<dbus::Bus>& bus,
- std::unique_ptr<CrosFpDeviceInterface> cros_fp_device,
- std::unique_ptr<BiodMetricsInterface> biod_metrics) {
- if (!cros_fp_device) {
- return nullptr;
- }
-
- std::unique_ptr<CrosFpBiometricsManager> biometrics_manager(
- new CrosFpBiometricsManager(PowerButtonFilter::Create(bus),
- std::move(cros_fp_device),
- std::move(biod_metrics)));
-
- return biometrics_manager;
-}
-
BiometricType CrosFpBiometricsManager::GetType() {
return BIOMETRIC_TYPE_FINGERPRINT;
}
diff --git a/biod/cros_fp_biometrics_manager.h b/biod/cros_fp_biometrics_manager.h
index 9dd7fa2..2704404 100644
--- a/biod/cros_fp_biometrics_manager.h
+++ b/biod/cros_fp_biometrics_manager.h
@@ -26,8 +26,8 @@
class CrosFpBiometricsManager : public BiometricsManager {
public:
- static std::unique_ptr<CrosFpBiometricsManager> Create(
- const scoped_refptr<dbus::Bus>& bus,
+ CrosFpBiometricsManager(
+ std::unique_ptr<PowerButtonFilterInterface> power_button_filter,
std::unique_ptr<CrosFpDeviceInterface> cros_fp_device,
std::unique_ptr<BiodMetricsInterface> biod_metrics);
@@ -59,11 +59,6 @@
bool ResetEntropy(bool factory_init) override;
protected:
- CrosFpBiometricsManager(
- std::unique_ptr<PowerButtonFilterInterface> power_button_filter,
- std::unique_ptr<CrosFpDeviceInterface> cros_fp_device,
- std::unique_ptr<BiodMetricsInterface> biod_metrics);
-
void EndEnrollSession() override;
void EndAuthSession() override;
diff --git a/biod/cros_fp_biometrics_manager_test.cc b/biod/cros_fp_biometrics_manager_test.cc
index 189b596..7466828 100644
--- a/biod/cros_fp_biometrics_manager_test.cc
+++ b/biod/cros_fp_biometrics_manager_test.cc
@@ -108,8 +108,8 @@
// Keep a pointer to the fake device to manipulate it later.
fake_cros_dev_ = fake_cros_dev.get();
- cros_fp_biometrics_manager_ = CrosFpBiometricsManager::Create(
- mock_bus, std::move(fake_cros_dev),
+ cros_fp_biometrics_manager_ = std::make_unique<CrosFpBiometricsManager>(
+ PowerButtonFilter::Create(mock_bus), std::move(fake_cros_dev),
std::make_unique<metrics::MockBiodMetrics>());
}
@@ -353,8 +353,9 @@
auto mock_biod_metrics = std::make_unique<metrics::MockBiodMetrics>();
mock_metrics_ = mock_biod_metrics.get();
- mock_ = MockCrosFpBiometricsManager::Create(
- mock_bus, std::move(mock_cros_fp_dev), std::move(mock_biod_metrics));
+ mock_ = std::make_unique<MockCrosFpBiometricsManager>(
+ PowerButtonFilter::Create(mock_bus), std::move(mock_cros_fp_dev),
+ std::move(mock_biod_metrics));
EXPECT_TRUE(mock_);
}
diff --git a/biod/mock_cros_fp_biometrics_manager.h b/biod/mock_cros_fp_biometrics_manager.h
index 79c8f24..9f59e54 100644
--- a/biod/mock_cros_fp_biometrics_manager.h
+++ b/biod/mock_cros_fp_biometrics_manager.h
@@ -21,24 +21,7 @@
class MockCrosFpBiometricsManager : public CrosFpBiometricsManager {
public:
- /**
- * @param bus DBus Usually a mock bus
- * @param cros_fp_device Usually a mock device
- * @param biod_metrics Usually a mock metrics object
- *
- * @return mock instance on success, nullptr on failure
- */
- static std::unique_ptr<MockCrosFpBiometricsManager> Create(
- const scoped_refptr<dbus::Bus>& bus,
- std::unique_ptr<CrosFpDeviceInterface> cros_fp_device,
- std::unique_ptr<BiodMetricsInterface> biod_metrics) {
- // Using new to access non-public constructor.
- // See https://abseil.io/tips/134.
- return base::WrapUnique(new MockCrosFpBiometricsManager(
- PowerButtonFilter::Create(bus), std::move(cros_fp_device),
- std::move(biod_metrics)));
- }
-
+ using CrosFpBiometricsManager::CrosFpBiometricsManager;
~MockCrosFpBiometricsManager() override = default;
MOCK_METHOD(BiometricType, GetType, (), (override));
@@ -85,9 +68,6 @@
void OnMaintenanceTimerFiredDelegate() {
CrosFpBiometricsManager::OnMaintenanceTimerFired();
}
-
- protected:
- using CrosFpBiometricsManager::CrosFpBiometricsManager;
};
} // namespace biod
diff --git a/biod/tools/bio_wash.cc b/biod/tools/bio_wash.cc
index bf08344..ce51fd5 100644
--- a/biod/tools/bio_wash.cc
+++ b/biod/tools/bio_wash.cc
@@ -20,6 +20,7 @@
#include "biod/biod_version.h"
#include "biod/cros_fp_biometrics_manager.h"
#include "biod/cros_fp_device.h"
+#include "biod/power_button_filter.h"
namespace {
@@ -38,12 +39,11 @@
auto bus = base::MakeRefCounted<dbus::Bus>(options);
auto biod_metrics = std::make_unique<biod::BiodMetrics>();
// Add all the possible BiometricsManagers available.
- std::unique_ptr<biod::BiometricsManager> cros_fp_bio =
- biod::CrosFpBiometricsManager::Create(
- bus,
- biod::CrosFpDevice::Create(
- biod_metrics.get(), std::make_unique<biod::EcCommandFactory>()),
- std::move(biod_metrics));
+ auto cros_fp_bio = std::make_unique<biod::CrosFpBiometricsManager>(
+ biod::PowerButtonFilter::Create(bus),
+ biod::CrosFpDevice::Create(biod_metrics.get(),
+ std::make_unique<biod::EcCommandFactory>()),
+ std::move(biod_metrics));
if (cros_fp_bio) {
managers.emplace_back(std::move(cros_fp_bio));
}