Commit 27038f20 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Introduce PasswordFormManager::IsMovableToAccountStore()

This method decided whether the pending credentials in the
password form manager can be moved to the account of the currently
signed in user.

Bug: 1032992
Change-Id: I088a24cb99111014c5f87468ac9fc566c6014c59
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2139658
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760121}
parent f74fe5d5
...@@ -54,6 +54,25 @@ bool FakeFormFetcher::IsBlacklisted() const { ...@@ -54,6 +54,25 @@ bool FakeFormFetcher::IsBlacklisted() const {
bool FakeFormFetcher::IsMovingBlocked(const autofill::GaiaIdHash& destination, bool FakeFormFetcher::IsMovingBlocked(const autofill::GaiaIdHash& destination,
const base::string16& username) const { const base::string16& username) const {
// This is analogous to the implementation in
// MultiStoreFormFetcher::IsMovingBlocked().
for (const std::vector<const PasswordForm*>& matches_vector :
{federated_, non_federated_}) {
for (const PasswordForm* form : matches_vector) {
// Only local entries can be moved to the account store (though
// account store matches should never have |moving_blocked_for_list|
// entries anyway).
if (form->IsUsingAccountStore())
continue;
// Ignore PSL matches for blocking moving.
if (form->is_public_suffix_match)
continue;
if (form->username_value != username)
continue;
if (base::Contains(form->moving_blocked_for_list, destination))
return true;
}
}
return false; return false;
} }
......
...@@ -28,6 +28,7 @@ class MockPasswordFormManagerForUI : public PasswordFormManagerForUI { ...@@ -28,6 +28,7 @@ class MockPasswordFormManagerForUI : public PasswordFormManagerForUI {
MOCK_CONST_METHOD0(GetInteractionsStats, MOCK_CONST_METHOD0(GetInteractionsStats,
base::span<const InteractionsStats>()); base::span<const InteractionsStats>());
MOCK_CONST_METHOD0(IsBlacklisted, bool()); MOCK_CONST_METHOD0(IsBlacklisted, bool());
MOCK_CONST_METHOD0(IsMovableToAccountStore, bool());
MOCK_METHOD0(Save, void()); MOCK_METHOD0(Save, void());
MOCK_METHOD1(Update, MOCK_METHOD1(Update,
void(const autofill::PasswordForm& credentials_to_update)); void(const autofill::PasswordForm& credentials_to_update));
......
...@@ -30,11 +30,14 @@ ...@@ -30,11 +30,14 @@
#include "components/password_manager/core/browser/possible_username_data.h" #include "components/password_manager/core/browser/possible_username_data.h"
#include "components/password_manager/core/browser/statistics_table.h" #include "components/password_manager/core/browser/statistics_table.h"
#include "components/password_manager/core/common/password_manager_features.h" #include "components/password_manager/core/common/password_manager_features.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "google_apis/gaia/core_account_id.h"
using autofill::FormData; using autofill::FormData;
using autofill::FormFieldData; using autofill::FormFieldData;
using autofill::FormSignature; using autofill::FormSignature;
using autofill::FormStructure; using autofill::FormStructure;
using autofill::GaiaIdHash;
using autofill::NOT_USERNAME; using autofill::NOT_USERNAME;
using autofill::PasswordForm; using autofill::PasswordForm;
using autofill::SINGLE_USERNAME; using autofill::SINGLE_USERNAME;
...@@ -267,6 +270,38 @@ bool PasswordFormManager::IsBlacklisted() const { ...@@ -267,6 +270,38 @@ bool PasswordFormManager::IsBlacklisted() const {
return form_fetcher_->IsBlacklisted() || newly_blacklisted_; return form_fetcher_->IsBlacklisted() || newly_blacklisted_;
} }
bool PasswordFormManager::IsMovableToAccountStore() const {
signin::IdentityManager* identity_manager = client_->GetIdentityManager();
if (!identity_manager)
return false;
const std::string gaia_id =
identity_manager
->GetPrimaryAccountInfo(signin::ConsentLevel::kNotRequired)
.gaia;
// If there is no signed in user, we cannot move the credentials to the
// account store.
if (gaia_id.empty())
return false;
const base::string16& username = GetPendingCredentials().username_value;
const base::string16& password = GetPendingCredentials().password_value;
const std::vector<const PasswordForm*> matches =
form_fetcher_->GetBestMatches();
// If no match in the profile store with the same username and password exist,
// then there is nothing to move.
if (std::none_of(matches.cbegin(), matches.cend(),
[&](const PasswordForm* match) {
return !match->IsUsingAccountStore() &&
match->username_value == username &&
match->password_value == password;
})) {
return false;
}
return !form_fetcher_->IsMovingBlocked(GaiaIdHash::FromGaiaId(gaia_id),
username);
}
void PasswordFormManager::Save() { void PasswordFormManager::Save() {
DCHECK_EQ(FormFetcher::State::NOT_WAITING, form_fetcher_->GetState()); DCHECK_EQ(FormFetcher::State::NOT_WAITING, form_fetcher_->GetState());
DCHECK(!client_->IsIncognito()); DCHECK(!client_->IsIncognito());
......
...@@ -145,6 +145,7 @@ class PasswordFormManager : public PasswordFormManagerForUI, ...@@ -145,6 +145,7 @@ class PasswordFormManager : public PasswordFormManagerForUI,
PasswordFormMetricsRecorder* GetMetricsRecorder() override; PasswordFormMetricsRecorder* GetMetricsRecorder() override;
base::span<const InteractionsStats> GetInteractionsStats() const override; base::span<const InteractionsStats> GetInteractionsStats() const override;
bool IsBlacklisted() const override; bool IsBlacklisted() const override;
bool IsMovableToAccountStore() const override;
void Save() override; void Save() override;
void Update(const autofill::PasswordForm& credentials_to_update) override; void Update(const autofill::PasswordForm& credentials_to_update) override;
......
...@@ -58,6 +58,12 @@ class PasswordFormManagerForUI { ...@@ -58,6 +58,12 @@ class PasswordFormManagerForUI {
// Determines if the user opted to 'never remember' passwords for this form. // Determines if the user opted to 'never remember' passwords for this form.
virtual bool IsBlacklisted() const = 0; virtual bool IsBlacklisted() const = 0;
// Determines whether the submitted credentials returned by
// GetPendingCredentials() can be moved to the signed in account store.
// Returns true if the submitted credentials are stored in the profile store
// and the current signed in user didn't block moving them.
virtual bool IsMovableToAccountStore() const = 0;
// Handles save-as-new or update of the form managed by this manager. // Handles save-as-new or update of the form managed by this manager.
virtual void Save() = 0; virtual void Save() = 0;
......
...@@ -51,6 +51,7 @@ class PasswordDataForUI : public PasswordFormManagerForUI { ...@@ -51,6 +51,7 @@ class PasswordDataForUI : public PasswordFormManagerForUI {
PasswordFormMetricsRecorder* GetMetricsRecorder() override; PasswordFormMetricsRecorder* GetMetricsRecorder() override;
base::span<const InteractionsStats> GetInteractionsStats() const override; base::span<const InteractionsStats> GetInteractionsStats() const override;
bool IsBlacklisted() const override; bool IsBlacklisted() const override;
bool IsMovableToAccountStore() const override;
void Save() override; void Save() override;
void Update(const PasswordForm& credentials_to_update) override; void Update(const PasswordForm& credentials_to_update) override;
void OnUpdateUsernameFromPrompt(const base::string16& new_username) override; void OnUpdateUsernameFromPrompt(const base::string16& new_username) override;
...@@ -129,6 +130,11 @@ bool PasswordDataForUI::IsBlacklisted() const { ...@@ -129,6 +130,11 @@ bool PasswordDataForUI::IsBlacklisted() const {
return false; return false;
} }
bool PasswordDataForUI::IsMovableToAccountStore() const {
// This is irrelevant for the generation conflict resolution bubble.
return false;
}
void PasswordDataForUI::Save() { void PasswordDataForUI::Save() {
bubble_interaction_cb_.Run(true, pending_form_); bubble_interaction_cb_.Run(true, pending_form_);
} }
......
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