OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/login/quick_unlock/fingerprint_storage.h" |
| 6 |
| 7 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h" |
| 8 #include "chrome/common/pref_names.h" |
| 9 #include "components/prefs/pref_service.h" |
| 10 |
| 11 namespace chromeos { |
| 12 namespace quick_unlock { |
| 13 |
| 14 FingerprintStorage::FingerprintStorage(PrefService* pref_service) |
| 15 : pref_service_(pref_service) {} |
| 16 |
| 17 FingerprintStorage::~FingerprintStorage() {} |
| 18 |
| 19 void FingerprintStorage::MarkStrongAuth() { |
| 20 last_strong_auth_ = base::Time::Now(); |
| 21 ResetUnlockAttemptCount(); |
| 22 } |
| 23 |
| 24 bool FingerprintStorage::HasStrongAuth() const { |
| 25 if (last_strong_auth_.is_null()) |
| 26 return false; |
| 27 |
| 28 // PIN and fingerprint share the same timeout policy. |
| 29 PasswordConfirmationFrequency strong_auth_interval = |
| 30 static_cast<PasswordConfirmationFrequency>( |
| 31 pref_service_->GetInteger(prefs::kQuickUnlockTimeout)); |
| 32 base::TimeDelta strong_auth_timeout = |
| 33 PasswordConfirmationFrequencyToTimeDelta(strong_auth_interval); |
| 34 |
| 35 return TimeSinceLastStrongAuth() < strong_auth_timeout; |
| 36 } |
| 37 |
| 38 base::TimeDelta FingerprintStorage::TimeSinceLastStrongAuth() const { |
| 39 DCHECK(!last_strong_auth_.is_null()); |
| 40 return base::Time::Now() - last_strong_auth_; |
| 41 } |
| 42 |
| 43 bool FingerprintStorage::IsFingerprintAuthenticationAvailable() const { |
| 44 const bool exceeded_unlock_attempts = |
| 45 unlock_attempt_count() >= kMaximumUnlockAttempts; |
| 46 |
| 47 return IsFingerprintEnabled() && HasEnrollment() && HasStrongAuth() && |
| 48 !exceeded_unlock_attempts; |
| 49 } |
| 50 |
| 51 bool FingerprintStorage::HasEnrollment() const { |
| 52 return has_enrollments_; |
| 53 } |
| 54 |
| 55 void FingerprintStorage::AddUnlockAttempt() { |
| 56 ++unlock_attempt_count_; |
| 57 } |
| 58 |
| 59 void FingerprintStorage::ResetUnlockAttemptCount() { |
| 60 unlock_attempt_count_ = 0; |
| 61 } |
| 62 |
| 63 } // namespace quick_unlock |
| 64 } // namespace chromeos |
OLD | NEW |