Chromium Code Reviews| 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 d1d7c03a22f4f3d7d798b7638ecb1126b06e12bc..540a3eba8f5b84fbbd8cea2627b2372125813c13 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 |
|
tbarzic
2014/12/18 10:49:05
I don't think you're using removeKeys anywhere
Tim Song
2014/12/18 22:42:54
Done.
|
| + // fetch and check the cryptohome keys against the keys in local preferences |
| + // as a sanity check. |
| CheckCryptohomeKeysAndMaybeHardlock(); |
| } |
| #endif |
| @@ -157,21 +168,24 @@ 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::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager() |
| + chromeos::UserSessionManager::GetInstance() |
| + ->GetEasyUnlockKeyManager() |
| ->RefreshKeys( |
| - *short_lived_user_context_->user_context(), |
| - devices, |
| - base::Bind(&EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices, |
| - weak_ptr_factory_.GetWeakPtr())); |
| + *short_lived_user_context_->user_context(), devices, |
| + base::Bind(&EasyUnlockServiceRegular::SetHardlockAfterKeyOperation, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + EasyUnlockScreenlockStateHandler::NO_HARDLOCK)); |
| } else { |
| CheckCryptohomeKeysAndMaybeHardlock(); |
| } |
| @@ -180,13 +194,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; |
| @@ -302,7 +309,7 @@ void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) { |
| return; |
| } |
| - ClearRemoteDevices(); |
| + SetRemoteDevices(base::ListValue()); |
| SetTurnOffFlowStatus(IDLE); |
| ReloadApp(); |
| } |