Commit 25a76093 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Passwords] PasswordForm in //chrome/browser/android

This change drops usages of autofill::PasswordForm in //c/b/android in
favor of password_manager::PasswordForm.

TBR=mamir

Bug: 1067347
Change-Id: I76d503a30aac561a633f17c2925c56335abd1df9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2445269
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813149}
parent b400a21e
......@@ -11,7 +11,8 @@
PasswordEditDelegateSettingsImpl::PasswordEditDelegateSettingsImpl(
Profile* profile,
base::span<const std::unique_ptr<autofill::PasswordForm>> forms_to_change,
base::span<const std::unique_ptr<password_manager::PasswordForm>>
forms_to_change,
std::vector<base::string16> existing_usernames)
: profile_(profile), existing_usernames_(std::move(existing_usernames)) {
DCHECK(!forms_to_change.empty());
......@@ -21,7 +22,7 @@ PasswordEditDelegateSettingsImpl::PasswordEditDelegateSettingsImpl(
forms_to_change_.reserve(forms_to_change.size());
for (const auto& password_form : forms_to_change) {
forms_to_change_.push_back(
std::make_unique<autofill::PasswordForm>(*password_form));
std::make_unique<password_manager::PasswordForm>(*password_form));
}
}
......
......@@ -11,7 +11,7 @@
#include "base/strings/string16.h"
#include "chrome/browser/android/password_edit_delegate.h"
#include "chrome/browser/android/password_editing_bridge.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/password_store_consumer.h"
class Profile;
......@@ -27,7 +27,8 @@ class PasswordEditDelegateSettingsImpl : public PasswordEditDelegate {
// username conflicts with any previously existing ones.
PasswordEditDelegateSettingsImpl(
Profile* profile,
base::span<const std::unique_ptr<autofill::PasswordForm>> forms_to_change,
base::span<const std::unique_ptr<password_manager::PasswordForm>>
forms_to_change,
std::vector<base::string16> existing_usernames);
~PasswordEditDelegateSettingsImpl() override;
......@@ -37,7 +38,7 @@ class PasswordEditDelegateSettingsImpl : public PasswordEditDelegate {
private:
Profile* profile_ = nullptr;
std::vector<base::string16> existing_usernames_;
std::vector<std::unique_ptr<autofill::PasswordForm>> forms_to_change_;
std::vector<std::unique_ptr<password_manager::PasswordForm>> forms_to_change_;
};
#endif // CHROME_BROWSER_ANDROID_PASSWORD_EDIT_DELEGATE_SETTINGS_IMPL_H_
......@@ -16,7 +16,7 @@
#include "chrome/browser/android/password_edit_delegate_settings_impl.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/password_list_sorter.h"
#include "components/password_manager/core/browser/password_manager_test_utils.h"
#include "components/password_manager/core/browser/test_password_store.h"
......@@ -40,7 +40,7 @@ constexpr char kUsername1[] = "user";
constexpr char kUsername2[] = "user2";
std::vector<std::pair<std::string, std::string>> GetUsernamesAndPasswords(
const std::vector<autofill::PasswordForm>& forms) {
const std::vector<password_manager::PasswordForm>& forms) {
std::vector<std::pair<std::string, std::string>> result;
result.reserve(forms.size());
for (const auto& form : forms) {
......@@ -51,10 +51,10 @@ std::vector<std::pair<std::string, std::string>> GetUsernamesAndPasswords(
return result;
}
autofill::PasswordForm MakeSavedForm(const GURL& origin,
password_manager::PasswordForm MakeSavedForm(const GURL& origin,
base::StringPiece username,
base::StringPiece password) {
autofill::PasswordForm form;
password_manager::PasswordForm form;
form.url = origin;
form.signon_realm = origin.GetOrigin().spec();
form.username_element = base::ASCIIToUTF16("Email");
......@@ -64,15 +64,16 @@ autofill::PasswordForm MakeSavedForm(const GURL& origin,
return form;
}
std::vector<std::unique_ptr<autofill::PasswordForm>> ExtractEquivalentForms(
const autofill::PasswordForm& edited_form,
const std::vector<autofill::PasswordForm>& saved_forms) {
std::vector<std::unique_ptr<password_manager::PasswordForm>>
ExtractEquivalentForms(
const password_manager::PasswordForm& edited_form,
const std::vector<password_manager::PasswordForm>& saved_forms) {
std::string sort_key = password_manager::CreateSortKey(edited_form);
std::vector<std::unique_ptr<autofill::PasswordForm>> equivalent_forms;
for (const autofill::PasswordForm& form : saved_forms) {
std::vector<std::unique_ptr<password_manager::PasswordForm>> equivalent_forms;
for (const password_manager::PasswordForm& form : saved_forms) {
if (password_manager::CreateSortKey(form) == sort_key) {
equivalent_forms.push_back(
std::make_unique<autofill::PasswordForm>(form));
std::make_unique<password_manager::PasswordForm>(form));
}
}
return equivalent_forms;
......@@ -80,7 +81,7 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> ExtractEquivalentForms(
std::vector<base::string16> ExtractUsernamesSameUrl(
const GURL& url,
const std::vector<autofill::PasswordForm>& saved_forms) {
const std::vector<password_manager::PasswordForm>& saved_forms) {
std::vector<base::string16> existing_usernames;
for (const auto& form : saved_forms) {
if (form.url == url) {
......@@ -106,14 +107,14 @@ class PasswordEditDelegateSettingsImplTest : public testing::Test {
void RunUntilIdle() { task_environment_.RunUntilIdle(); }
std::unique_ptr<PasswordEditDelegateSettingsImpl> CreateTestDelegate(
const std::vector<std::unique_ptr<autofill::PasswordForm>>& forms,
const std::vector<std::unique_ptr<password_manager::PasswordForm>>& forms,
std::vector<base::string16> existing_usernames);
const std::vector<autofill::PasswordForm>& GetStoredPasswordsForRealm(
const std::vector<password_manager::PasswordForm>& GetStoredPasswordsForRealm(
base::StringPiece signon_realm);
void InitializeStoreWithForms(
const std::vector<autofill::PasswordForm>& saved_forms);
const std::vector<password_manager::PasswordForm>& saved_forms);
private:
content::BrowserTaskEnvironment task_environment_;
......@@ -131,13 +132,13 @@ class PasswordEditDelegateSettingsImplTest : public testing::Test {
std::unique_ptr<PasswordEditDelegateSettingsImpl>
PasswordEditDelegateSettingsImplTest::CreateTestDelegate(
const std::vector<std::unique_ptr<autofill::PasswordForm>>& forms,
const std::vector<std::unique_ptr<password_manager::PasswordForm>>& forms,
std::vector<base::string16> existing_usernames) {
return std::make_unique<PasswordEditDelegateSettingsImpl>(
&profile_, forms, std::move(existing_usernames));
}
const std::vector<autofill::PasswordForm>&
const std::vector<password_manager::PasswordForm>&
PasswordEditDelegateSettingsImplTest::GetStoredPasswordsForRealm(
base::StringPiece signon_realm) {
const auto& stored_passwords = GetStore()->stored_passwords();
......@@ -146,7 +147,7 @@ PasswordEditDelegateSettingsImplTest::GetStoredPasswordsForRealm(
}
void PasswordEditDelegateSettingsImplTest::InitializeStoreWithForms(
const std::vector<autofill::PasswordForm>& saved_forms) {
const std::vector<password_manager::PasswordForm>& saved_forms) {
for (const auto& form : saved_forms) {
GetStore()->AddLogin(form);
}
......@@ -154,11 +155,11 @@ void PasswordEditDelegateSettingsImplTest::InitializeStoreWithForms(
}
TEST_F(PasswordEditDelegateSettingsImplTest, EditPassword) {
autofill::PasswordForm edited_form =
password_manager::PasswordForm edited_form =
MakeSavedForm(GURL(kExampleCom), kUsername1, kPassword1);
std::vector<autofill::PasswordForm> saved_forms = {edited_form};
std::vector<password_manager::PasswordForm> saved_forms = {edited_form};
InitializeStoreWithForms(saved_forms);
std::vector<std::unique_ptr<autofill::PasswordForm>> forms_to_change =
std::vector<std::unique_ptr<password_manager::PasswordForm>> forms_to_change =
ExtractEquivalentForms(edited_form, saved_forms);
std::vector<base::string16> existing_usernames =
ExtractUsernamesSameUrl(edited_form.url, saved_forms);
......@@ -174,13 +175,13 @@ TEST_F(PasswordEditDelegateSettingsImplTest, EditPassword) {
}
TEST_F(PasswordEditDelegateSettingsImplTest, EditUsername) {
autofill::PasswordForm edited_form =
password_manager::PasswordForm edited_form =
MakeSavedForm(GURL(kExampleCom), kUsername1, kPassword1);
std::vector<autofill::PasswordForm> saved_forms = {edited_form};
std::vector<password_manager::PasswordForm> saved_forms = {edited_form};
InitializeStoreWithForms(saved_forms);
std::vector<std::unique_ptr<autofill::PasswordForm>> forms_to_change =
std::vector<std::unique_ptr<password_manager::PasswordForm>> forms_to_change =
ExtractEquivalentForms(edited_form, saved_forms);
std::vector<base::string16> existing_usernames =
ExtractUsernamesSameUrl(edited_form.url, saved_forms);
......@@ -196,13 +197,13 @@ TEST_F(PasswordEditDelegateSettingsImplTest, EditUsername) {
}
TEST_F(PasswordEditDelegateSettingsImplTest, EditUsernameAndPassword) {
autofill::PasswordForm edited_form =
password_manager::PasswordForm edited_form =
MakeSavedForm(GURL(kExampleCom), kUsername1, kPassword1);
std::vector<autofill::PasswordForm> saved_forms = {edited_form};
std::vector<password_manager::PasswordForm> saved_forms = {edited_form};
InitializeStoreWithForms(saved_forms);
std::vector<std::unique_ptr<autofill::PasswordForm>> forms_to_change =
std::vector<std::unique_ptr<password_manager::PasswordForm>> forms_to_change =
ExtractEquivalentForms(edited_form, saved_forms);
std::vector<base::string16> existing_usernames =
ExtractUsernamesSameUrl(edited_form.url, saved_forms);
......@@ -218,14 +219,15 @@ TEST_F(PasswordEditDelegateSettingsImplTest, EditUsernameAndPassword) {
}
TEST_F(PasswordEditDelegateSettingsImplTest, RejectSameUsernameForSameRealm) {
autofill::PasswordForm edited_form =
password_manager::PasswordForm edited_form =
MakeSavedForm(GURL(kExampleCom), kUsername1, kPassword1);
autofill::PasswordForm other_form =
password_manager::PasswordForm other_form =
MakeSavedForm(GURL(kExampleCom), kUsername2, kPassword2);
std::vector<autofill::PasswordForm> saved_forms = {edited_form, other_form};
std::vector<password_manager::PasswordForm> saved_forms = {edited_form,
other_form};
InitializeStoreWithForms(saved_forms);
std::vector<std::unique_ptr<autofill::PasswordForm>> forms_to_change =
std::vector<std::unique_ptr<password_manager::PasswordForm>> forms_to_change =
ExtractEquivalentForms(edited_form, saved_forms);
std::vector<base::string16> existing_usernames =
ExtractUsernamesSameUrl(edited_form.url, saved_forms);
......@@ -241,14 +243,15 @@ TEST_F(PasswordEditDelegateSettingsImplTest, RejectSameUsernameForSameRealm) {
}
TEST_F(PasswordEditDelegateSettingsImplTest, UpdateDuplicates) {
autofill::PasswordForm edited_form = MakeSavedForm(
password_manager::PasswordForm edited_form = MakeSavedForm(
GURL(base::StrCat({kExampleCom, "pathA"})), kUsername1, kPassword1);
autofill::PasswordForm other_form = MakeSavedForm(
password_manager::PasswordForm other_form = MakeSavedForm(
GURL(base::StrCat({kExampleCom, "pathB"})), kUsername1, kPassword1);
std::vector<autofill::PasswordForm> saved_forms = {edited_form, other_form};
std::vector<password_manager::PasswordForm> saved_forms = {edited_form,
other_form};
InitializeStoreWithForms(saved_forms);
std::vector<std::unique_ptr<autofill::PasswordForm>> forms_to_change =
std::vector<std::unique_ptr<password_manager::PasswordForm>> forms_to_change =
ExtractEquivalentForms(edited_form, saved_forms);
std::vector<base::string16> existing_usernames =
ExtractUsernamesSameUrl(edited_form.url, saved_forms);
......@@ -266,19 +269,19 @@ TEST_F(PasswordEditDelegateSettingsImplTest, UpdateDuplicates) {
TEST_F(PasswordEditDelegateSettingsImplTest,
EditUsernameForTheRightCredential) {
autofill::PasswordForm edited_form =
password_manager::PasswordForm edited_form =
MakeSavedForm(GURL(kExampleCom), kUsername1, kPassword1);
autofill::PasswordForm other_form1 =
password_manager::PasswordForm other_form1 =
MakeSavedForm(GURL(kExampleCom), kUsername2, kPassword2);
autofill::PasswordForm other_form2 =
password_manager::PasswordForm other_form2 =
MakeSavedForm(GURL(kExampleOrg), kUsername1, kPassword1);
autofill::PasswordForm other_form3 =
password_manager::PasswordForm other_form3 =
MakeSavedForm(GURL(kExampleOrg), kUsername2, kPassword2);
std::vector<autofill::PasswordForm> saved_forms = {edited_form, other_form1,
other_form2, other_form3};
std::vector<password_manager::PasswordForm> saved_forms = {
edited_form, other_form1, other_form2, other_form3};
InitializeStoreWithForms(saved_forms);
std::vector<std::unique_ptr<autofill::PasswordForm>> forms_to_change =
std::vector<std::unique_ptr<password_manager::PasswordForm>> forms_to_change =
ExtractEquivalentForms(edited_form, saved_forms);
std::vector<base::string16> existing_usernames =
ExtractUsernamesSameUrl(edited_form.url, saved_forms);
......@@ -299,19 +302,19 @@ TEST_F(PasswordEditDelegateSettingsImplTest,
TEST_F(PasswordEditDelegateSettingsImplTest,
EditPasswordForTheRightCredential) {
autofill::PasswordForm edited_form =
password_manager::PasswordForm edited_form =
MakeSavedForm(GURL(kExampleCom), kUsername1, kPassword1);
autofill::PasswordForm other_form1 =
password_manager::PasswordForm other_form1 =
MakeSavedForm(GURL(kExampleCom), kUsername2, kPassword2);
autofill::PasswordForm other_form2 =
password_manager::PasswordForm other_form2 =
MakeSavedForm(GURL(kExampleOrg), kUsername1, kPassword1);
autofill::PasswordForm other_form3 =
password_manager::PasswordForm other_form3 =
MakeSavedForm(GURL(kExampleOrg), kUsername2, kPassword2);
std::vector<autofill::PasswordForm> saved_forms = {edited_form, other_form1,
other_form2, other_form3};
std::vector<password_manager::PasswordForm> saved_forms = {
edited_form, other_form1, other_form2, other_form3};
InitializeStoreWithForms(saved_forms);
std::vector<std::unique_ptr<autofill::PasswordForm>> forms_to_change =
std::vector<std::unique_ptr<password_manager::PasswordForm>> forms_to_change =
ExtractEquivalentForms(edited_form, saved_forms);
std::vector<base::string16> existing_usernames =
ExtractUsernamesSameUrl(edited_form.url, saved_forms);
......
......@@ -23,7 +23,8 @@ void PasswordEditingBridge::LaunchPasswordEntryEditor(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& context,
Profile* profile,
base::span<const std::unique_ptr<autofill::PasswordForm>> forms_to_change,
base::span<const std::unique_ptr<password_manager::PasswordForm>>
forms_to_change,
std::vector<base::string16> existing_usernames) {
// |forms_to_change| is built in
// |PasswordManagerPresnter::TryGetPasswordForms|, which under certain
......
......@@ -39,7 +39,8 @@ class PasswordEditingBridge {
JNIEnv* env,
const base::android::JavaParamRef<jobject>& context,
Profile* profile,
base::span<const std::unique_ptr<autofill::PasswordForm>> forms_to_change,
base::span<const std::unique_ptr<password_manager::PasswordForm>>
forms_to_change,
std::vector<base::string16> existing_usernames);
void HandleEditSavedPasswordEntry(
......
......@@ -30,9 +30,9 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/grit/generated_resources.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/export/password_csv_writer.h"
#include "components/password_manager/core/browser/leak_detection/authenticated_leak_check.h"
#include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/password_ui_utils.h"
#include "components/password_manager/core/browser/ui/credential_provider_interface.h"
#include "content/public/browser/browser_thread.h"
......@@ -73,7 +73,8 @@ Profile* PasswordUIViewAndroid::GetProfile() {
}
void PasswordUIViewAndroid::SetPasswordList(
const std::vector<std::unique_ptr<autofill::PasswordForm>>& password_list) {
const std::vector<std::unique_ptr<password_manager::PasswordForm>>&
password_list) {
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jobject> ui_controller = weak_java_ui_controller_.get(env);
if (!ui_controller.is_null()) {
......@@ -83,7 +84,7 @@ void PasswordUIViewAndroid::SetPasswordList(
}
void PasswordUIViewAndroid::SetPasswordExceptionList(
const std::vector<std::unique_ptr<autofill::PasswordForm>>&
const std::vector<std::unique_ptr<password_manager::PasswordForm>>&
password_exception_list) {
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jobject> ui_controller = weak_java_ui_controller_.get(env);
......@@ -104,7 +105,7 @@ ScopedJavaLocalRef<jobject> PasswordUIViewAndroid::GetSavedPasswordEntry(
const JavaRef<jobject>&,
int index) {
DCHECK_EQ(State::ALIVE, state_);
const autofill::PasswordForm* form =
const password_manager::PasswordForm* form =
password_manager_presenter_.GetPassword(index);
if (!form) {
return Java_PasswordUIView_createSavedPasswordEntry(
......@@ -125,7 +126,7 @@ ScopedJavaLocalRef<jstring> PasswordUIViewAndroid::GetSavedPasswordException(
const JavaRef<jobject>&,
int index) {
DCHECK_EQ(State::ALIVE, state_);
const autofill::PasswordForm* form =
const password_manager::PasswordForm* form =
password_manager_presenter_.GetPasswordException(index);
if (!form)
return ConvertUTF8ToJavaString(env, std::string());
......@@ -232,7 +233,7 @@ PasswordUIViewAndroid::ObtainAndSerializePasswords(
credential_provider_for_testing_ ? credential_provider_for_testing_
: &password_manager_presenter_;
std::vector<std::unique_ptr<autofill::PasswordForm>> passwords =
std::vector<std::unique_ptr<password_manager::PasswordForm>> passwords =
provider->GetAllPasswords();
// The UI should not trigger serialization if there are not passwords.
......
......@@ -50,10 +50,10 @@ class PasswordUIViewAndroid : public PasswordUIView {
// PasswordUIView implementation.
Profile* GetProfile() override;
void SetPasswordList(
const std::vector<std::unique_ptr<autofill::PasswordForm>>& password_list)
override;
const std::vector<std::unique_ptr<password_manager::PasswordForm>>&
password_list) override;
void SetPasswordExceptionList(
const std::vector<std::unique_ptr<autofill::PasswordForm>>&
const std::vector<std::unique_ptr<password_manager::PasswordForm>>&
password_exception_list) override;
// Calls from Java.
......
......@@ -19,8 +19,8 @@
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/export/password_csv_writer.h"
#include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/ui/credential_provider_interface.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_utils.h"
......@@ -33,9 +33,9 @@
namespace android {
using autofill::PasswordForm;
using base::android::AttachCurrentThread;
using base::android::JavaParamRef;
using password_manager::PasswordForm;
namespace {
......
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