Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6454)

Unified Diff: chrome/browser/chromeos/login/quick_unlock/pin_storage.cc

Issue 2387253002: cros: Added policies for screen unlock. (Closed)
Patch Set: Fixed patch set 1 errors. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/quick_unlock/pin_storage.cc
diff --git a/chrome/browser/chromeos/login/quick_unlock/pin_storage.cc b/chrome/browser/chromeos/login/quick_unlock/pin_storage.cc
index 25abdaf2417994b33e3be641a5eedb34f7f25441..bafc2f97ad1f7f85c80d17fa80110d17b90b38b1 100644
--- a/chrome/browser/chromeos/login/quick_unlock/pin_storage.cc
+++ b/chrome/browser/chromeos/login/quick_unlock/pin_storage.cc
@@ -37,11 +37,29 @@ std::string ComputeSecret(const std::string& pin, const std::string& salt) {
return key.GetSecret();
}
-} // namespace
+base::TimeDelta PasswordConfirmationFrequencyFrequencyToTimeDelta(
+ PasswordConfirmationFrequency frequency) {
+ base::TimeDelta time_delta;
+ switch (frequency) {
+ case PasswordConfirmationFrequency::SIX_HOURS:
+ time_delta = base::TimeDelta::FromHours(6);
jdufault 2016/10/21 19:03:45 Return the value directly and remove the |time_del
sammiequon 2016/10/21 23:49:25 Done.
+ break;
+ case PasswordConfirmationFrequency::TWELVE_HOURS:
+ time_delta = base::TimeDelta::FromHours(12);
+ break;
+ case PasswordConfirmationFrequency::DAY:
+ time_delta = base::TimeDelta::FromDays(1);
+ break;
+ case PasswordConfirmationFrequency::WEEK:
+ time_delta = base::TimeDelta::FromDays(7);
+ break;
+ default:
+ NOTREACHED();
+ }
+ return time_delta;
+}
-// static
-const base::TimeDelta PinStorage::kStrongAuthTimeout =
- base::TimeDelta::FromHours(24);
+} // namespace
// static
void PinStorage::RegisterProfilePrefs(
@@ -66,6 +84,17 @@ bool PinStorage::HasStrongAuth() const {
return !last_strong_auth_.is_null();
}
+bool PinStorage::NeedsStrongAuth() const {
+ PasswordConfirmationFrequency strong_auth_interval =
+ static_cast<PasswordConfirmationFrequency>(
+ pref_service_->GetInteger(prefs::kQuickUnlockTimeout));
+ base::TimeDelta strong_auth_timeout =
+ PasswordConfirmationFrequencyFrequencyToTimeDelta(strong_auth_interval);
+ ;
jdufault 2016/10/21 19:03:44 Remove extra ;
sammiequon 2016/10/21 23:49:25 Done.
+
+ return TimeSinceLastStrongAuth() > strong_auth_timeout;
+}
+
base::TimeDelta PinStorage::TimeSinceLastStrongAuth() const {
DCHECK(!last_strong_auth_.is_null());
return base::Time::Now() - last_strong_auth_;
@@ -96,6 +125,16 @@ void PinStorage::RemovePin() {
pref_service_->SetString(prefs::kQuickUnlockPinSecret, "");
}
+bool PinStorage::IsPinUnlockEnabled() const {
+ const base::ListValue* screen_lock_whitelist =
+ pref_service_->GetList(prefs::kQuickUnlockModeWhitelist);
+ auto all_value = base::StringValue("all");
jdufault 2016/10/21 19:03:45 base::StringValue all_value("all")?
sammiequon 2016/10/21 23:49:25 Done.
+ auto pin_value = base::StringValue("pin");
+ return screen_lock_whitelist->Find(all_value) !=
+ screen_lock_whitelist->end() ||
+ screen_lock_whitelist->Find(pin_value) != screen_lock_whitelist->end();
+}
+
std::string PinStorage::PinSalt() const {
return pref_service_->GetString(prefs::kQuickUnlockPinSalt);
}
@@ -107,11 +146,10 @@ std::string PinStorage::PinSecret() const {
bool PinStorage::IsPinAuthenticationAvailable() const {
const bool exceeded_unlock_attempts =
unlock_attempt_count() >= kMaximumUnlockAttempts;
- const bool has_strong_auth =
- HasStrongAuth() && TimeSinceLastStrongAuth() < kStrongAuthTimeout;
+ const bool has_strong_auth = HasStrongAuth() && !NeedsStrongAuth();
- return IsQuickUnlockEnabled() && IsPinSet() && has_strong_auth &&
- !exceeded_unlock_attempts;
+ return IsPinUnlockEnabled() && IsQuickUnlockEnabled() && IsPinSet() &&
+ has_strong_auth && !exceeded_unlock_attempts;
}
bool PinStorage::TryAuthenticatePin(const std::string& pin) {

Powered by Google App Engine
This is Rietveld 408576698