Commit 2321e384 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Remove PasswordFormManager.best_matches_/preferred_match_

Those member fields are leftovers from earlier implementations that are
not needed anymore. Instead we should query the FormFetcher.

Change-Id: I76a367c332257dd152cf4d3ec9b18b5f150105a9
Bug: 1004783
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1809302Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697237}
parent 0421fed4
...@@ -226,7 +226,7 @@ const GURL& PasswordFormManager::GetOrigin() const { ...@@ -226,7 +226,7 @@ const GURL& PasswordFormManager::GetOrigin() const {
const std::map<base::string16, const PasswordForm*>& const std::map<base::string16, const PasswordForm*>&
PasswordFormManager::GetBestMatches() const { PasswordFormManager::GetBestMatches() const {
return best_matches_; return form_fetcher_->GetBestMatches();
} }
std::vector<const autofill::PasswordForm*> std::vector<const autofill::PasswordForm*>
...@@ -280,7 +280,8 @@ void PasswordFormManager::Save() { ...@@ -280,7 +280,8 @@ void PasswordFormManager::Save() {
SanitizePossibleUsernames(&pending_credentials_); SanitizePossibleUsernames(&pending_credentials_);
pending_credentials_.date_created = base::Time::Now(); pending_credentials_.date_created = base::Time::Now();
votes_uploader_.SendVotesOnSave(observed_form_, *parsed_submitted_form_, votes_uploader_.SendVotesOnSave(observed_form_, *parsed_submitted_form_,
best_matches_, &pending_credentials_); form_fetcher_->GetBestMatches(),
&pending_credentials_);
SavePendingToStore(false /*update*/); SavePendingToStore(false /*update*/);
} else { } else {
ProcessUpdate(); ProcessUpdate();
...@@ -594,8 +595,6 @@ PasswordFormManager::PasswordFormManager( ...@@ -594,8 +595,6 @@ PasswordFormManager::PasswordFormManager(
void PasswordFormManager::OnFetchCompleted() { void PasswordFormManager::OnFetchCompleted() {
received_stored_credentials_time_ = TimeTicks::Now(); received_stored_credentials_time_ = TimeTicks::Now();
best_matches_ = form_fetcher_->GetBestMatches();
preferred_match_ = form_fetcher_->GetPreferredMatch();
// Copy out blacklisted matches. // Copy out blacklisted matches.
new_blacklisted_.reset(); new_blacklisted_.reset();
...@@ -750,10 +749,10 @@ void PasswordFormManager::Fill() { ...@@ -750,10 +749,10 @@ void PasswordFormManager::Fill() {
return; return;
#endif #endif
SendFillInformationToRenderer(client_, driver_.get(), SendFillInformationToRenderer(
*observed_password_form.get(), best_matches_, client_, driver_.get(), *observed_password_form.get(),
form_fetcher_->GetFederatedMatches(), form_fetcher_->GetBestMatches(), form_fetcher_->GetFederatedMatches(),
preferred_match_, metrics_recorder_.get()); form_fetcher_->GetPreferredMatch(), metrics_recorder_.get());
} }
void PasswordFormManager::FillForm(const FormData& observed_form) { void PasswordFormManager::FillForm(const FormData& observed_form) {
...@@ -858,7 +857,7 @@ void PasswordFormManager::CreatePendingCredentials() { ...@@ -858,7 +857,7 @@ void PasswordFormManager::CreatePendingCredentials() {
// Calculate the user's action based on existing matches and the submitted // Calculate the user's action based on existing matches and the submitted
// form. // form.
metrics_recorder_->CalculateUserAction(best_matches_, metrics_recorder_->CalculateUserAction(form_fetcher_->GetBestMatches(),
*parsed_submitted_form_); *parsed_submitted_form_);
// This function might be called multiple times so set variables that are // This function might be called multiple times so set variables that are
...@@ -870,7 +869,7 @@ void PasswordFormManager::CreatePendingCredentials() { ...@@ -870,7 +869,7 @@ void PasswordFormManager::CreatePendingCredentials() {
// Look for the actually submitted credentials in the list of previously saved // Look for the actually submitted credentials in the list of previously saved
// credentials that were available to autofilling. // credentials that were available to autofilling.
const PasswordForm* saved_form = password_manager_util::GetMatchForUpdating( const PasswordForm* saved_form = password_manager_util::GetMatchForUpdating(
*parsed_submitted_form_, best_matches_); *parsed_submitted_form_, form_fetcher_->GetBestMatches());
if (saved_form) { if (saved_form) {
// A similar credential exists in the store already. // A similar credential exists in the store already.
pending_credentials_ = *saved_form; pending_credentials_ = *saved_form;
...@@ -978,7 +977,8 @@ void PasswordFormManager::CreatePendingCredentialsForNewCredentials( ...@@ -978,7 +977,8 @@ void PasswordFormManager::CreatePendingCredentialsForNewCredentials(
void PasswordFormManager::ProcessUpdate() { void PasswordFormManager::ProcessUpdate() {
DCHECK_EQ(FormFetcher::State::NOT_WAITING, form_fetcher_->GetState()); DCHECK_EQ(FormFetcher::State::NOT_WAITING, form_fetcher_->GetState());
DCHECK(preferred_match_ || pending_credentials_.IsFederatedCredential()); DCHECK(form_fetcher_->GetPreferredMatch() ||
pending_credentials_.IsFederatedCredential());
// If we're doing an Update, we either autofilled correctly and need to // If we're doing an Update, we either autofilled correctly and need to
// update the stats, or the user typed in a new password for autofilled // update the stats, or the user typed in a new password for autofilled
// username, or the user selected one of the non-preferred matches, // username, or the user selected one of the non-preferred matches,
...@@ -1008,16 +1008,17 @@ void PasswordFormManager::ProcessUpdate() { ...@@ -1008,16 +1008,17 @@ void PasswordFormManager::ProcessUpdate() {
} }
if (pending_credentials_.times_used == 1) { if (pending_credentials_.times_used == 1) {
votes_uploader_.UploadFirstLoginVotes(best_matches_, pending_credentials_, votes_uploader_.UploadFirstLoginVotes(form_fetcher_->GetBestMatches(),
pending_credentials_,
*parsed_submitted_form_); *parsed_submitted_form_);
} }
} }
void PasswordFormManager::FillHttpAuth() { void PasswordFormManager::FillHttpAuth() {
DCHECK(IsHttpAuth()); DCHECK(IsHttpAuth());
if (!preferred_match_) if (!form_fetcher_->GetPreferredMatch())
return; return;
client_->AutofillHttpAuth(*preferred_match_, this); client_->AutofillHttpAuth(*form_fetcher_->GetPreferredMatch(), this);
} }
std::unique_ptr<PasswordForm> PasswordFormManager::ParseFormAndMakeLogging( std::unique_ptr<PasswordForm> PasswordFormManager::ParseFormAndMakeLogging(
...@@ -1102,7 +1103,7 @@ void PasswordFormManager::CalculateFillingAssistanceMetric( ...@@ -1102,7 +1103,7 @@ void PasswordFormManager::CalculateFillingAssistanceMetric(
void PasswordFormManager::SavePendingToStore(bool update) { void PasswordFormManager::SavePendingToStore(bool update) {
const PasswordForm* saved_form = password_manager_util::GetMatchForUpdating( const PasswordForm* saved_form = password_manager_util::GetMatchForUpdating(
*parsed_submitted_form_, best_matches_); *parsed_submitted_form_, form_fetcher_->GetBestMatches());
if ((update || password_overridden_) && if ((update || password_overridden_) &&
!pending_credentials_.IsFederatedCredential()) { !pending_credentials_.IsFederatedCredential()) {
DCHECK(saved_form); DCHECK(saved_form);
......
...@@ -294,11 +294,6 @@ class PasswordFormManager : public PasswordFormManagerInterface, ...@@ -294,11 +294,6 @@ class PasswordFormManager : public PasswordFormManagerInterface,
// API. // API.
base::Optional<PasswordStore::FormDigest> observed_not_web_form_digest_; base::Optional<PasswordStore::FormDigest> observed_not_web_form_digest_;
// Set of nonblacklisted PasswordForms from the DB that best match the form
// being managed by |this|, indexed by username. The PasswordForms are owned
// by |form_fetcher_|.
std::map<base::string16, const autofill::PasswordForm*> best_matches_;
// Set of blacklisted forms from the PasswordStore that best match the current // Set of blacklisted forms from the PasswordStore that best match the current
// form. They are owned by |form_fetcher_|. // form. They are owned by |form_fetcher_|.
std::vector<const autofill::PasswordForm*> blacklisted_matches_; std::vector<const autofill::PasswordForm*> blacklisted_matches_;
...@@ -312,12 +307,6 @@ class PasswordFormManager : public PasswordFormManagerInterface, ...@@ -312,12 +307,6 @@ class PasswordFormManager : public PasswordFormManagerInterface,
// which are owned by |form_fetcher_|). // which are owned by |form_fetcher_|).
std::unique_ptr<autofill::PasswordForm> new_blacklisted_; std::unique_ptr<autofill::PasswordForm> new_blacklisted_;
// Convenience pointer to entry in best_matches_ that is marked
// as preferred. This is only allowed to be null if there are no best matches
// at all, since there will always be one preferred login when there are
// multiple matches (when first saved, a login is marked preferred).
const autofill::PasswordForm* preferred_match_ = nullptr;
// Takes care of recording metrics and events for |*this|. // Takes care of recording metrics and events for |*this|.
scoped_refptr<PasswordFormMetricsRecorder> metrics_recorder_; scoped_refptr<PasswordFormMetricsRecorder> metrics_recorder_;
......
...@@ -3097,7 +3097,7 @@ TEST_F(PasswordManagerTest, CreatePasswordFormManagerOnSaving) { ...@@ -3097,7 +3097,7 @@ TEST_F(PasswordManagerTest, CreatePasswordFormManagerOnSaving) {
EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_))
.WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save)));
// The form disappeared, so the submission is condered to be successful. // The form disappeared, so the submission is considered to be successful.
manager()->OnPasswordFormsRendered(&driver_, {}, true); manager()->OnPasswordFormsRendered(&driver_, {}, true);
ASSERT_TRUE(form_manager_to_save); ASSERT_TRUE(form_manager_to_save);
EXPECT_THAT(form_manager_to_save->GetPendingCredentials(), EXPECT_THAT(form_manager_to_save->GetPendingCredentials(),
......
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