Commit e2891284 authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

cros fingerprint: Keep prefs::kQuickUnlockFingerprintRecord fresh

Update the value on the session start.

Fixed: 893938
Change-Id: I949ecfcaba81c6d53d78853d0d4576ac5ae003c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414209
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarRenato Silva <rrsilva@google.com>
Cr-Commit-Position: refs/heads/master@{#807851}
parent e94517af
......@@ -230,4 +230,19 @@ IN_PROC_BROWSER_TEST_F(FingerprintUnlockTest, TimeoutIncludesSuspendedTime) {
->notify_lock_screen_dismissed_call_count());
}
IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, PRE_FingerprintRecordsGone) {
// Pretend that user has a fingerprint enrolled. Number of enrolled
// fingerprints is cached in the prefs. But the actual fingerprint records
// are gone.
Profile* profile = browser()->profile();
profile->GetPrefs()->SetInteger(prefs::kQuickUnlockFingerprintRecord, 1);
}
IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, FingerprintRecordsGone) {
base::RunLoop().RunUntilIdle();
Profile* profile = browser()->profile();
EXPECT_EQ(
profile->GetPrefs()->GetInteger(prefs::kQuickUnlockFingerprintRecord), 0);
}
} // namespace chromeos
......@@ -5,10 +5,13 @@
#include "chrome/browser/chromeos/login/quick_unlock/fingerprint_storage.h"
#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "chromeos/dbus/biod/biod_client.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/device_service.h"
namespace chromeos {
namespace quick_unlock {
......@@ -18,7 +21,19 @@ void FingerprintStorage::RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(prefs::kQuickUnlockFingerprintRecord, 0);
}
FingerprintStorage::FingerprintStorage(Profile* profile) : profile_(profile) {}
FingerprintStorage::FingerprintStorage(Profile* profile) : profile_(profile) {
if (!chromeos::BiodClient::Get())
return;
content::GetDeviceService().BindFingerprint(
fp_service_.BindNewPipeAndPassReceiver());
const std::string user_id =
ProfileHelper::Get()->GetUserIdHashFromProfile(profile);
// Get actual records to update cached prefs::kQuickUnlockFingerprintRecord.
fp_service_->GetRecordsForUser(
user_id, base::BindOnce(&FingerprintStorage::OnGetRecords,
weak_factory_.GetWeakPtr()));
}
FingerprintStorage::~FingerprintStorage() {}
......@@ -44,5 +59,11 @@ bool FingerprintStorage::ExceededUnlockAttempts() const {
return unlock_attempt_count() >= kMaximumUnlockAttempts;
}
void FingerprintStorage::OnGetRecords(
const base::flat_map<std::string, std::string>& fingerprints_list_mapping) {
profile_->GetPrefs()->SetInteger(prefs::kQuickUnlockFingerprintRecord,
fingerprints_list_mapping.size());
}
} // namespace quick_unlock
} // namespace chromeos
......@@ -7,6 +7,9 @@
#include "base/macros.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/fingerprint.mojom.h"
class PrefRegistrySimple;
class Profile;
......@@ -48,6 +51,9 @@ class FingerprintStorage {
int unlock_attempt_count() const { return unlock_attempt_count_; }
private:
void OnGetRecords(const base::flat_map<std::string, std::string>&
fingerprints_list_mapping);
friend class chromeos::FingerprintStorageTestApi;
friend class QuickUnlockStorage;
......@@ -55,6 +61,10 @@ class FingerprintStorage {
// Number of fingerprint unlock attempt.
int unlock_attempt_count_ = 0;
mojo::Remote<device::mojom::Fingerprint> fp_service_;
base::WeakPtrFactory<FingerprintStorage> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(FingerprintStorage);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment