Commit a661429a authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Use PasswordStore.Unblacklist() inside PasswordFormManager

This CL removes all the complexity of unblacklisting listing an origin
and uses the recently introduce Unblacklist() method inside
PasswordStore.

Change-Id: Ia66625be452e8545db44e86d6c0380d55ed13a5a
Bug: 1004783
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1810898
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698495}
parent d1b73ad4
......@@ -30,6 +30,10 @@ class FormSaver {
virtual autofill::PasswordForm PermanentlyBlacklist(
PasswordStore::FormDigest digest) = 0;
// Unblacklist the origin described by |digest| by deleting all corresponding
// blacklisted entries.
virtual void Unblacklist(const PasswordStore::FormDigest& digest) = 0;
// Saves the |pending| form.
// |matches| are relevant credentials for the site. After saving |pending|,
// the following clean up steps are performed on the credentials stored on
......
......@@ -102,6 +102,10 @@ PasswordForm FormSaverImpl::PermanentlyBlacklist(
return blacklisted;
}
void FormSaverImpl::Unblacklist(const PasswordStore::FormDigest& digest) {
store_->Unblacklist(digest, /*completion=*/base::DoNothing());
}
void FormSaverImpl::Save(PasswordForm pending,
const std::vector<const PasswordForm*>& matches,
const base::string16& old_password) {
......
......@@ -26,6 +26,7 @@ class FormSaverImpl : public FormSaver {
// FormSaver:
autofill::PasswordForm PermanentlyBlacklist(
PasswordStore::FormDigest digest) override;
void Unblacklist(const PasswordStore::FormDigest& digest) override;
void Save(autofill::PasswordForm pending,
const std::vector<const autofill::PasswordForm*>& matches,
const base::string16& old_password) override;
......
......@@ -252,23 +252,14 @@ base::span<const InteractionsStats> PasswordFormManager::GetInteractionsStats()
}
bool PasswordFormManager::IsBlacklisted() const {
return !blacklisted_matches_.empty() || newly_blacklisted_;
return !form_fetcher_->GetBlacklistedMatches().empty() || newly_blacklisted_;
}
void PasswordFormManager::Save() {
DCHECK_EQ(FormFetcher::State::NOT_WAITING, form_fetcher_->GetState());
DCHECK(!client_->IsIncognito());
for (auto blacklisted_iterator = blacklisted_matches_.begin();
blacklisted_iterator != blacklisted_matches_.end();) {
form_saver_->Remove(**blacklisted_iterator);
blacklisted_iterator = blacklisted_matches_.erase(blacklisted_iterator);
}
if (newly_blacklisted_) {
PasswordForm newly_blacklisted_form =
password_manager_util::MakeNormalizedBlacklistedForm(
ConstructObservedFormDigest());
form_saver_->Remove(newly_blacklisted_form);
if (IsBlacklisted()) {
form_saver_->Unblacklist(ConstructObservedFormDigest());
newly_blacklisted_ = false;
}
......@@ -605,8 +596,6 @@ void PasswordFormManager::OnFetchCompleted() {
// Copy out blacklisted matches.
newly_blacklisted_ = false;
blacklisted_matches_ = form_fetcher_->GetBlacklistedMatches();
autofills_left_ = kMaxTimesAutofill;
if (IsCredentialAPISave()) {
......
......@@ -296,10 +296,6 @@ class PasswordFormManager : public PasswordFormManagerInterface,
// API.
base::Optional<PasswordStore::FormDigest> observed_not_web_form_digest_;
// Set of blacklisted forms from the PasswordStore that best match the current
// form. They are owned by |form_fetcher_|.
std::vector<const autofill::PasswordForm*> blacklisted_matches_;
// If the observed form gets blacklisted through |this|, we keep the
// information in this boolean flag until data is potentially refreshed by
// reading from PasswordStore again. Upon reading from the store again, we set
......
......@@ -11,6 +11,8 @@ autofill::PasswordForm StubFormSaver::PermanentlyBlacklist(
return autofill::PasswordForm();
}
void StubFormSaver::Unblacklist(const PasswordStore::FormDigest& digest) {}
std::unique_ptr<FormSaver> StubFormSaver::Clone() {
return nullptr;
}
......
......@@ -20,6 +20,7 @@ class StubFormSaver : public FormSaver {
// FormSaver:
autofill::PasswordForm PermanentlyBlacklist(
PasswordStore::FormDigest digest) override;
void Unblacklist(const PasswordStore::FormDigest& digest) override;
void Save(autofill::PasswordForm pending,
const std::vector<const autofill::PasswordForm*>& matches,
const base::string16& old_password) override {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment