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/quick_unlock_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 QuickUnlockStorage::QuickUnlockStorage(PrefService* pref_service) |
| 15 : pref_service_(pref_service) { |
| 16 fingerprint_storage_ = base::MakeUnique<FingerprintStorage>(pref_service); |
| 17 pin_storage_ = base::MakeUnique<PinStorage>(pref_service); |
| 18 } |
| 19 |
| 20 QuickUnlockStorage::~QuickUnlockStorage() {} |
| 21 |
| 22 void QuickUnlockStorage::MarkStrongAuth() { |
| 23 last_strong_auth_ = base::Time::Now(); |
| 24 fingerprint_storage()->ResetUnlockAttemptCount(); |
| 25 pin_storage()->ResetUnlockAttemptCount(); |
| 26 } |
| 27 |
| 28 bool QuickUnlockStorage::HasStrongAuth() const { |
| 29 if (last_strong_auth_.is_null()) |
| 30 return false; |
| 31 |
| 32 // PIN and fingerprint share the same timeout policy. |
| 33 PasswordConfirmationFrequency strong_auth_interval = |
| 34 static_cast<PasswordConfirmationFrequency>( |
| 35 pref_service_->GetInteger(prefs::kQuickUnlockTimeout)); |
| 36 base::TimeDelta strong_auth_timeout = |
| 37 PasswordConfirmationFrequencyToTimeDelta(strong_auth_interval); |
| 38 |
| 39 return TimeSinceLastStrongAuth() < strong_auth_timeout; |
| 40 } |
| 41 |
| 42 base::TimeDelta QuickUnlockStorage::TimeSinceLastStrongAuth() const { |
| 43 DCHECK(!last_strong_auth_.is_null()); |
| 44 return base::Time::Now() - last_strong_auth_; |
| 45 } |
| 46 |
| 47 bool QuickUnlockStorage::IsFingerprintAuthenticationAvailable() const { |
| 48 return HasStrongAuth() && |
| 49 fingerprint_storage_->IsFingerprintAuthenticationAvailable(); |
| 50 } |
| 51 |
| 52 bool QuickUnlockStorage::IsPinAuthenticationAvailable() const { |
| 53 return HasStrongAuth() && pin_storage_->IsPinAuthenticationAvailable(); |
| 54 } |
| 55 |
| 56 bool QuickUnlockStorage::TryAuthenticatePin(const std::string& pin) { |
| 57 return HasStrongAuth() && pin_storage()->TryAuthenticatePin(pin); |
| 58 } |
| 59 |
| 60 FingerprintStorage* QuickUnlockStorage::fingerprint_storage() { |
| 61 return fingerprint_storage_.get(); |
| 62 } |
| 63 |
| 64 PinStorage* QuickUnlockStorage::pin_storage() { |
| 65 return pin_storage_.get(); |
| 66 } |
| 67 |
| 68 void QuickUnlockStorage::Shutdown() { |
| 69 fingerprint_storage_.reset(); |
| 70 pin_storage_.reset(); |
| 71 } |
| 72 |
| 73 } // namespace quick_unlock |
| 74 } // namespace chromeos |
OLD | NEW |