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

Unified Diff: chrome/browser/signin/easy_unlock_service_regular.cc

Issue 808563004: Clean up Smart Lock cryptohome keys logic: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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/signin/easy_unlock_service_regular.cc
diff --git a/chrome/browser/signin/easy_unlock_service_regular.cc b/chrome/browser/signin/easy_unlock_service_regular.cc
index 4eede4d687cfc88dfe4e4bd22438fb7d6a2c88f1..2a390d30ce471221f9fc594d641afd06a29f49c7 100644
--- a/chrome/browser/signin/easy_unlock_service_regular.cc
+++ b/chrome/browser/signin/easy_unlock_service_regular.cc
@@ -91,19 +91,30 @@ void EasyUnlockServiceRegular::OnUserContextFromReauth(
base::ThreadTaskRunnerHandle::Get().get()));
OpenSetupApp();
-}
-void EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices(bool success) {
- // If the keys were refreshed successfully, the hardlock state should be
- // cleared, so Smart Lock can be used normally. Otherwise, we fall back to
- // a hardlock state to force the user to type in their credentials again.
- if (success) {
- SetHardlockStateForUser(GetUserEmail(),
- EasyUnlockScreenlockStateHandler::NO_HARDLOCK);
+ // Use this opportunity to clear the crytohome keys if it was not already
+ // cleared earlier.
+ const base::ListValue* devices = GetRemoteDevices();
+ if (!devices || devices->empty()) {
+ chromeos::EasyUnlockKeyManager* key_manager =
+ chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
+ key_manager->RefreshKeys(
+ user_context, base::ListValue(),
+ base::Bind(&EasyUnlockServiceRegular::SetHardlockAfterKeyOperation,
+ weak_ptr_factory_.GetWeakPtr(),
+ EasyUnlockScreenlockStateHandler::NO_PAIRING));
}
+}
+
+void EasyUnlockServiceRegular::SetHardlockAfterKeyOperation(
+ EasyUnlockScreenlockStateHandler::HardlockState state_on_success,
+ bool success) {
+ if (success)
+ SetHardlockStateForUser(GetUserEmail(), state_on_success);
- // Even if the keys refresh suceeded, we still fetch the cryptohome keys as a
- // sanity check.
+ // Even if the key operation (removeKey or refreshKey) suceeded, we still
+ // fetch and check the cryptohome keys against the keys in local preferences
+ // as a sanity check.
CheckCryptohomeKeysAndMaybeHardlock();
}
#endif
@@ -157,13 +168,15 @@ void EasyUnlockServiceRegular::SetRemoteDevices(
const base::ListValue& devices) {
DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
prefs::kEasyUnlockPairing);
- pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy());
+ if (devices.empty())
+ pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
+ else
+ pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy());
#if defined(OS_CHROMEOS)
// TODO(tengs): Investigate if we can determine if the remote devices were set
// from sync or from the setup app.
- if (short_lived_user_context_ && short_lived_user_context_->user_context() &&
- !devices.empty()) {
+ if (short_lived_user_context_ && short_lived_user_context_->user_context()) {
// We may already have the password cached, so proceed to create the
// cryptohome keys for sign-in or the system will be hardlocked.
chromeos::UserContext* user_context =
@@ -173,8 +186,9 @@ void EasyUnlockServiceRegular::SetRemoteDevices(
key_manager->RefreshKeys(
*user_context, devices,
- base::Bind(&EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices,
- weak_ptr_factory_.GetWeakPtr()));
+ base::Bind(&EasyUnlockServiceRegular::SetHardlockAfterKeyOperation,
+ weak_ptr_factory_.GetWeakPtr(),
+ EasyUnlockScreenlockStateHandler::NO_HARDLOCK));
} else {
CheckCryptohomeKeysAndMaybeHardlock();
}
@@ -183,13 +197,6 @@ void EasyUnlockServiceRegular::SetRemoteDevices(
#endif
}
-void EasyUnlockServiceRegular::ClearRemoteDevices() {
- DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
- prefs::kEasyUnlockPairing);
- pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
- CheckCryptohomeKeysAndMaybeHardlock();
-}
-
void EasyUnlockServiceRegular::RunTurnOffFlow() {
if (turn_off_flow_status_ == PENDING)
return;
@@ -305,7 +312,7 @@ void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) {
return;
}
- ClearRemoteDevices();
+ SetRemoteDevices(base::ListValue());
SetTurnOffFlowStatus(IDLE);
ReloadApp();
}

Powered by Google App Engine
This is Rietveld 408576698