Chromium Code Reviews| Index: components/password_manager/core/browser/password_form_manager.cc |
| diff --git a/components/password_manager/core/browser/password_form_manager.cc b/components/password_manager/core/browser/password_form_manager.cc |
| index 247d539498daa6df089b315eec3ee742a2dfb698..0a85d5c5a57307748163667b5d259bbb064304c8 100644 |
| --- a/components/password_manager/core/browser/password_form_manager.cc |
| +++ b/components/password_manager/core/browser/password_form_manager.cc |
| @@ -627,7 +627,10 @@ void PasswordFormManager::SaveAsNewLogin() { |
| pending_credentials_.date_created = Time::Now(); |
| SanitizePossibleUsernames(&pending_credentials_); |
| - password_store->AddLogin(pending_credentials_); |
| + if (!presaved_form_) |
|
dvadym
2016/04/06 12:44:23
I'd prefer to reverse this condition, in order to
kolos1
2016/04/07 13:05:18
Done.
|
| + password_store->AddLogin(pending_credentials_); |
| + else |
| + ReplacePresavedPasswordWithPendingCredentials(password_store); |
| UpdatePreferredLoginState(password_store); |
| } |
| @@ -697,7 +700,9 @@ void PasswordFormManager::UpdateLogin() { |
| bool password_was_updated = false; |
| // Update the new preferred login. |
| - if (!selected_username_.empty()) { |
| + if (presaved_form_) { |
| + ReplacePresavedPasswordWithPendingCredentials(password_store); |
| + } else if (!selected_username_.empty()) { |
| // Username has changed. We set this selected username as the real |
| // username. Given that |username_value| is part of the Sync and |
| // PasswordStore primary key, the old primary key must be supplied. |
| @@ -1380,4 +1385,53 @@ void PasswordFormManager::WipeStoreCopyIfOutdated() { |
| } |
| } |
| +void PasswordFormManager::PresaveGeneratedPassword( |
| + const autofill::PasswordForm& form) { |
| + PasswordStore* store = client_->GetPasswordStore(); |
| + if (!store) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + store->AddLogin(form); |
| + presaved_form_.reset(new autofill::PasswordForm(form)); |
| +} |
| + |
| +void PasswordFormManager::UpdatePresavedPassword( |
| + const autofill::PasswordForm& new_form) { |
| + if (!presaved_form_) { |
| + PresaveGeneratedPassword(new_form); |
| + return; |
| + } |
| + |
| + PasswordStore* store = client_->GetPasswordStore(); |
| + if (!store) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + store->UpdateLoginWithPrimaryKey(new_form, *presaved_form_); |
| + presaved_form_.reset(new autofill::PasswordForm(new_form)); |
| +} |
| + |
| +void PasswordFormManager::RemovePresavedPassword() { |
| + if (!presaved_form_) |
| + return; |
| + |
| + PasswordStore* store = client_->GetPasswordStore(); |
| + if (!store) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + store->RemoveLogin(*presaved_form_); |
| + presaved_form_.reset(); |
| +} |
| + |
| +void PasswordFormManager::ReplacePresavedPasswordWithPendingCredentials( |
| + PasswordStore* store) { |
| + DCHECK(store); |
| + DCHECK(presaved_form_); |
| + |
| + store->UpdateLoginWithPrimaryKey(pending_credentials_, *presaved_form_); |
| + presaved_form_.reset(); |
| +} |
| + |
| } // namespace password_manager |