| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h" | 5 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/login/quick_unlock/fingerprint_storage.h" |
| 8 #include "chrome/browser/chromeos/login/quick_unlock/pin_storage_prefs.h" |
| 7 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h" | 9 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 9 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
| 10 | 13 |
| 11 namespace chromeos { | 14 namespace chromeos { |
| 12 namespace quick_unlock { | 15 namespace quick_unlock { |
| 13 | 16 |
| 14 QuickUnlockStorage::QuickUnlockStorage(PrefService* pref_service) | 17 QuickUnlockStorage::QuickUnlockStorage(Profile* profile) |
| 15 : pref_service_(pref_service) { | 18 : pref_service_(profile->GetPrefs()) { |
| 16 fingerprint_storage_ = base::MakeUnique<FingerprintStorage>(pref_service); | 19 fingerprint_storage_ = base::MakeUnique<FingerprintStorage>(pref_service_); |
| 17 pin_storage_ = base::MakeUnique<PinStorage>(pref_service); | 20 pin_storage_ = base::MakeUnique<PinStoragePrefs>(profile); |
| 18 } | 21 } |
| 19 | 22 |
| 20 QuickUnlockStorage::~QuickUnlockStorage() {} | 23 QuickUnlockStorage::~QuickUnlockStorage() {} |
| 21 | 24 |
| 22 void QuickUnlockStorage::MarkStrongAuth() { | 25 void QuickUnlockStorage::MarkStrongAuth() { |
| 23 last_strong_auth_ = base::Time::Now(); | 26 last_strong_auth_ = base::Time::Now(); |
| 24 fingerprint_storage()->ResetUnlockAttemptCount(); | 27 fingerprint_storage()->ResetUnlockAttemptCount(); |
| 25 pin_storage()->ResetUnlockAttemptCount(); | 28 pin_storage_->ResetUnlockAttemptCount(); |
| 26 } | 29 } |
| 27 | 30 |
| 28 bool QuickUnlockStorage::HasStrongAuth() const { | 31 bool QuickUnlockStorage::HasStrongAuth() const { |
| 29 if (last_strong_auth_.is_null()) | 32 if (last_strong_auth_.is_null()) |
| 30 return false; | 33 return false; |
| 31 | 34 |
| 32 // PIN and fingerprint share the same timeout policy. | 35 // PIN and fingerprint share the same timeout policy. |
| 33 PasswordConfirmationFrequency strong_auth_interval = | 36 PasswordConfirmationFrequency strong_auth_interval = |
| 34 static_cast<PasswordConfirmationFrequency>( | 37 static_cast<PasswordConfirmationFrequency>( |
| 35 pref_service_->GetInteger(prefs::kQuickUnlockTimeout)); | 38 pref_service_->GetInteger(prefs::kQuickUnlockTimeout)); |
| 36 base::TimeDelta strong_auth_timeout = | 39 base::TimeDelta strong_auth_timeout = |
| 37 PasswordConfirmationFrequencyToTimeDelta(strong_auth_interval); | 40 PasswordConfirmationFrequencyToTimeDelta(strong_auth_interval); |
| 38 | 41 |
| 39 return TimeSinceLastStrongAuth() < strong_auth_timeout; | 42 return TimeSinceLastStrongAuth() < strong_auth_timeout; |
| 40 } | 43 } |
| 41 | 44 |
| 42 base::TimeDelta QuickUnlockStorage::TimeSinceLastStrongAuth() const { | 45 base::TimeDelta QuickUnlockStorage::TimeSinceLastStrongAuth() const { |
| 43 DCHECK(!last_strong_auth_.is_null()); | 46 DCHECK(!last_strong_auth_.is_null()); |
| 44 return base::Time::Now() - last_strong_auth_; | 47 return base::Time::Now() - last_strong_auth_; |
| 45 } | 48 } |
| 46 | 49 |
| 47 bool QuickUnlockStorage::IsFingerprintAuthenticationAvailable() const { | 50 bool QuickUnlockStorage::IsFingerprintAuthenticationAvailable() const { |
| 48 return HasStrongAuth() && | 51 return HasStrongAuth() && |
| 49 fingerprint_storage_->IsFingerprintAuthenticationAvailable(); | 52 fingerprint_storage_->IsFingerprintAuthenticationAvailable(); |
| 50 } | 53 } |
| 51 | 54 |
| 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() { | 55 void QuickUnlockStorage::Shutdown() { |
| 69 fingerprint_storage_.reset(); | 56 fingerprint_storage_.reset(); |
| 70 pin_storage_.reset(); | 57 pin_storage_.reset(); |
| 71 } | 58 } |
| 72 | 59 |
| 73 } // namespace quick_unlock | 60 } // namespace quick_unlock |
| 74 } // namespace chromeos | 61 } // namespace chromeos |
| OLD | NEW |