Commit ca5afd3b authored by vasilii's avatar vasilii Committed by Commit bot

Change ScopedVector to vector<unique_ptr> in the password's UI code.

In addition the code performs small related refactoring. No functional changes should happen.

BUG=555132

Review-Url: https://codereview.chromium.org/2253233005
Cr-Commit-Position: refs/heads/master@{#413422}
parent 8b406045
...@@ -39,11 +39,11 @@ namespace { ...@@ -39,11 +39,11 @@ namespace {
void AddElementsToJavaCredentialArray( void AddElementsToJavaCredentialArray(
JNIEnv* env, JNIEnv* env,
ScopedJavaLocalRef<jobjectArray> java_credentials_array, ScopedJavaLocalRef<jobjectArray> java_credentials_array,
const std::vector<const autofill::PasswordForm*>& password_forms, const std::vector<std::unique_ptr<autofill::PasswordForm>>& password_forms,
password_manager::CredentialType type, password_manager::CredentialType type,
int indexStart = 0) { int indexStart = 0) {
int index = indexStart; int index = indexStart;
for (auto* password_form : password_forms) { for (const auto& password_form : password_forms) {
ScopedJavaLocalRef<jobject> java_credential = CreateNativeCredential( ScopedJavaLocalRef<jobject> java_credential = CreateNativeCredential(
env, *password_form, index - indexStart, static_cast<int>(type)); env, *password_form, index - indexStart, static_cast<int>(type));
env->SetObjectArrayElement(java_credentials_array.obj(), index, env->SetObjectArrayElement(java_credentials_array.obj(), index,
...@@ -92,10 +92,10 @@ void AvatarFetcherAndroid::OnFetchComplete(const GURL& url, ...@@ -92,10 +92,10 @@ void AvatarFetcherAndroid::OnFetchComplete(const GURL& url,
void FetchAvatars( void FetchAvatars(
const base::android::ScopedJavaGlobalRef<jobject>& java_dialog, const base::android::ScopedJavaGlobalRef<jobject>& java_dialog,
const std::vector<const autofill::PasswordForm*>& password_forms, const std::vector<std::unique_ptr<autofill::PasswordForm>>& password_forms,
int index, int index,
net::URLRequestContextGetter* request_context) { net::URLRequestContextGetter* request_context) {
for (auto* password_form : password_forms) { for (const auto& password_form : password_forms) {
if (!password_form->icon_url.is_valid()) if (!password_form->icon_url.is_valid())
continue; continue;
// Fetcher deletes itself once fetching is finished. // Fetcher deletes itself once fetching is finished.
...@@ -110,8 +110,8 @@ void FetchAvatars( ...@@ -110,8 +110,8 @@ void FetchAvatars(
AccountChooserDialogAndroid::AccountChooserDialogAndroid( AccountChooserDialogAndroid::AccountChooserDialogAndroid(
content::WebContents* web_contents, content::WebContents* web_contents,
ScopedVector<autofill::PasswordForm> local_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials,
ScopedVector<autofill::PasswordForm> federated_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>> federated_credentials,
const GURL& origin, const GURL& origin,
const ManagePasswordsState::CredentialsCallback& callback) const ManagePasswordsState::CredentialsCallback& callback)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
...@@ -139,14 +139,14 @@ void AccountChooserDialogAndroid::ShowDialog() { ...@@ -139,14 +139,14 @@ void AccountChooserDialogAndroid::ShowDialog() {
&title, &title_link_range); &title, &title_link_range);
gfx::NativeWindow native_window = web_contents_->GetTopLevelNativeWindow(); gfx::NativeWindow native_window = web_contents_->GetTopLevelNativeWindow();
size_t credential_array_size = size_t credential_array_size =
local_credentials_forms().size() + federated_credentials_forms().size(); local_credentials_forms().size() + federation_providers_forms().size();
ScopedJavaLocalRef<jobjectArray> java_credentials_array = ScopedJavaLocalRef<jobjectArray> java_credentials_array =
CreateNativeCredentialArray(env, credential_array_size); CreateNativeCredentialArray(env, credential_array_size);
AddElementsToJavaCredentialArray( AddElementsToJavaCredentialArray(
env, java_credentials_array, local_credentials_forms(), env, java_credentials_array, local_credentials_forms(),
password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
AddElementsToJavaCredentialArray( AddElementsToJavaCredentialArray(
env, java_credentials_array, federated_credentials_forms(), env, java_credentials_array, federation_providers_forms(),
password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED, password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED,
local_credentials_forms().size()); local_credentials_forms().size());
base::android::ScopedJavaGlobalRef<jobject> java_dialog_global; base::android::ScopedJavaGlobalRef<jobject> java_dialog_global;
...@@ -167,7 +167,7 @@ void AccountChooserDialogAndroid::ShowDialog() { ...@@ -167,7 +167,7 @@ void AccountChooserDialogAndroid::ShowDialog() {
Profile::FromBrowserContext(web_contents_->GetBrowserContext()) Profile::FromBrowserContext(web_contents_->GetBrowserContext())
->GetRequestContext(); ->GetRequestContext();
FetchAvatars(dialog_jobject_, local_credentials_forms(), 0, request_context); FetchAvatars(dialog_jobject_, local_credentials_forms(), 0, request_context);
FetchAvatars(dialog_jobject_, federated_credentials_forms(), FetchAvatars(dialog_jobject_, federation_providers_forms(),
local_credentials_forms().size(), request_context); local_credentials_forms().size(), request_context);
} }
...@@ -221,14 +221,14 @@ void AccountChooserDialogAndroid::OnDialogCancel() { ...@@ -221,14 +221,14 @@ void AccountChooserDialogAndroid::OnDialogCancel() {
false /* signin_button_clicked */); false /* signin_button_clicked */);
} }
const std::vector<const autofill::PasswordForm*>& const std::vector<std::unique_ptr<autofill::PasswordForm>>&
AccountChooserDialogAndroid::local_credentials_forms() const { AccountChooserDialogAndroid::local_credentials_forms() const {
return passwords_data_.GetCurrentForms(); return passwords_data_.GetCurrentForms();
} }
const std::vector<const autofill::PasswordForm*>& const std::vector<std::unique_ptr<autofill::PasswordForm>>&
AccountChooserDialogAndroid::federated_credentials_forms() const { AccountChooserDialogAndroid::federation_providers_forms() const {
return passwords_data_.federated_credentials_forms(); return passwords_data_.federation_providers_forms();
} }
void AccountChooserDialogAndroid::ChooseCredential( void AccountChooserDialogAndroid::ChooseCredential(
...@@ -247,9 +247,9 @@ void AccountChooserDialogAndroid::ChooseCredential( ...@@ -247,9 +247,9 @@ void AccountChooserDialogAndroid::ChooseCredential(
const auto& credentials_forms = const auto& credentials_forms =
(type == CredentialType::CREDENTIAL_TYPE_PASSWORD) (type == CredentialType::CREDENTIAL_TYPE_PASSWORD)
? local_credentials_forms() ? local_credentials_forms()
: federated_credentials_forms(); : federation_providers_forms();
if (index < credentials_forms.size()) { if (index < credentials_forms.size()) {
passwords_data_.ChooseCredential(credentials_forms[index]); passwords_data_.ChooseCredential(credentials_forms[index].get());
} }
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "chrome/browser/ui/passwords/manage_passwords_state.h" #include "chrome/browser/ui/passwords/manage_passwords_state.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
...@@ -29,8 +28,8 @@ class AccountChooserDialogAndroid : public content::WebContentsObserver { ...@@ -29,8 +28,8 @@ class AccountChooserDialogAndroid : public content::WebContentsObserver {
public: public:
AccountChooserDialogAndroid( AccountChooserDialogAndroid(
content::WebContents* web_contents, content::WebContents* web_contents,
ScopedVector<autofill::PasswordForm> local_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials,
ScopedVector<autofill::PasswordForm> federated_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>> federation_providers,
const GURL& origin, const GURL& origin,
const ManagePasswordsState::CredentialsCallback& callback); const ManagePasswordsState::CredentialsCallback& callback);
...@@ -61,11 +60,11 @@ class AccountChooserDialogAndroid : public content::WebContentsObserver { ...@@ -61,11 +60,11 @@ class AccountChooserDialogAndroid : public content::WebContentsObserver {
private: private:
void OnDialogCancel(); void OnDialogCancel();
const std::vector<const autofill::PasswordForm*>& local_credentials_forms() const std::vector<std::unique_ptr<autofill::PasswordForm>>&
const; local_credentials_forms() const;
const std::vector<const autofill::PasswordForm*>& const std::vector<std::unique_ptr<autofill::PasswordForm>>&
federated_credentials_forms() const; federation_providers_forms() const;
void ChooseCredential(size_t index, void ChooseCredential(size_t index,
password_manager::CredentialType type, password_manager::CredentialType type,
......
...@@ -49,7 +49,7 @@ class AccountChooserDialogAndroidTest : public ChromeRenderViewHostTestHarness { ...@@ -49,7 +49,7 @@ class AccountChooserDialogAndroidTest : public ChromeRenderViewHostTestHarness {
AccountChooserDialogAndroid* CreateDialogManyAccounts(); AccountChooserDialogAndroid* CreateDialogManyAccounts();
AccountChooserDialogAndroid* CreateDialog( AccountChooserDialogAndroid* CreateDialog(
ScopedVector<autofill::PasswordForm> credentials); std::vector<std::unique_ptr<autofill::PasswordForm>> credentials);
private: private:
DISALLOW_COPY_AND_ASSIGN(AccountChooserDialogAndroidTest); DISALLOW_COPY_AND_ASSIGN(AccountChooserDialogAndroidTest);
...@@ -62,8 +62,8 @@ void AccountChooserDialogAndroidTest::SetUp() { ...@@ -62,8 +62,8 @@ void AccountChooserDialogAndroidTest::SetUp() {
} }
AccountChooserDialogAndroid* AccountChooserDialogAndroidTest::CreateDialog( AccountChooserDialogAndroid* AccountChooserDialogAndroidTest::CreateDialog(
ScopedVector<autofill::PasswordForm> credentials) { std::vector<std::unique_ptr<autofill::PasswordForm>> credentials) {
ScopedVector<autofill::PasswordForm> deprecated_federated; std::vector<std::unique_ptr<autofill::PasswordForm>> deprecated_federated;
return new AccountChooserDialogAndroid( return new AccountChooserDialogAndroid(
web_contents(), std::move(credentials), std::move(deprecated_federated), web_contents(), std::move(credentials), std::move(deprecated_federated),
GURL("https://example.com"), GURL("https://example.com"),
...@@ -73,14 +73,14 @@ AccountChooserDialogAndroid* AccountChooserDialogAndroidTest::CreateDialog( ...@@ -73,14 +73,14 @@ AccountChooserDialogAndroid* AccountChooserDialogAndroidTest::CreateDialog(
AccountChooserDialogAndroid* AccountChooserDialogAndroid*
AccountChooserDialogAndroidTest::CreateDialogOneAccount() { AccountChooserDialogAndroidTest::CreateDialogOneAccount() {
ScopedVector<autofill::PasswordForm> credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> credentials;
credentials.push_back(CreatePasswordFormFromDataForTesting(kFormData)); credentials.push_back(CreatePasswordFormFromDataForTesting(kFormData));
return CreateDialog(std::move(credentials)); return CreateDialog(std::move(credentials));
} }
AccountChooserDialogAndroid* AccountChooserDialogAndroid*
AccountChooserDialogAndroidTest::CreateDialogManyAccounts() { AccountChooserDialogAndroidTest::CreateDialogManyAccounts() {
ScopedVector<autofill::PasswordForm> credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> credentials;
credentials.push_back(CreatePasswordFormFromDataForTesting(kFormData)); credentials.push_back(CreatePasswordFormFromDataForTesting(kFormData));
credentials.push_back(CreatePasswordFormFromDataForTesting(kFormData)); credentials.push_back(CreatePasswordFormFromDataForTesting(kFormData));
return CreateDialog(std::move(credentials)); return CreateDialog(std::move(credentials));
......
...@@ -254,19 +254,23 @@ bool ChromePasswordManagerClient::PromptUserToChooseCredentials( ...@@ -254,19 +254,23 @@ bool ChromePasswordManagerClient::PromptUserToChooseCredentials(
CredentialsCallback intercept = CredentialsCallback intercept =
base::Bind(&ChromePasswordManagerClient::OnCredentialsChosen, base::Bind(&ChromePasswordManagerClient::OnCredentialsChosen,
base::Unretained(this), callback, local_forms.size() == 1); base::Unretained(this), callback, local_forms.size() == 1);
std::vector<std::unique_ptr<autofill::PasswordForm>> locals =
password_manager_util::ConvertScopedVector(std::move(local_forms));
std::vector<std::unique_ptr<autofill::PasswordForm>> federations =
password_manager_util::ConvertScopedVector(std::move(federated_forms));
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Deletes itself on the event from Java counterpart, when user interacts with // Deletes itself on the event from Java counterpart, when user interacts with
// dialog. // dialog.
AccountChooserDialogAndroid* acccount_chooser_dialog = AccountChooserDialogAndroid* acccount_chooser_dialog =
new AccountChooserDialogAndroid(web_contents(), std::move(local_forms), new AccountChooserDialogAndroid(web_contents(), std::move(locals),
std::move(federated_forms), origin, std::move(federations), origin,
intercept); intercept);
acccount_chooser_dialog->ShowDialog(); acccount_chooser_dialog->ShowDialog();
return true; return true;
#else #else
return PasswordsClientUIDelegateFromWebContents(web_contents()) return PasswordsClientUIDelegateFromWebContents(web_contents())
->OnChooseCredentials(std::move(local_forms), std::move(federated_forms), ->OnChooseCredentials(std::move(locals), std::move(federations), origin,
origin, intercept); intercept);
#endif #endif
} }
...@@ -302,11 +306,13 @@ void ChromePasswordManagerClient::NotifyUserAutoSignin( ...@@ -302,11 +306,13 @@ void ChromePasswordManagerClient::NotifyUserAutoSignin(
// If a site gets back a credential some navigations are likely to occur. They // If a site gets back a credential some navigations are likely to occur. They
// shouldn't trigger the autofill password manager. // shouldn't trigger the autofill password manager.
password_manager_.DropFormManagers(); password_manager_.DropFormManagers();
std::vector<std::unique_ptr<autofill::PasswordForm>> forms =
password_manager_util::ConvertScopedVector(std::move(local_forms));
#if BUILDFLAG(ANDROID_JAVA_UI) #if BUILDFLAG(ANDROID_JAVA_UI)
ShowAutoSigninPrompt(web_contents(), local_forms[0]->username_value); ShowAutoSigninPrompt(web_contents(), forms[0]->username_value);
#else #else
PasswordsClientUIDelegateFromWebContents(web_contents()) PasswordsClientUIDelegateFromWebContents(web_contents())
->OnAutoSignin(std::move(local_forms), origin); ->OnAutoSignin(std::move(forms), origin);
#endif #endif
} }
......
...@@ -52,7 +52,7 @@ bool UpdatePasswordInfoBarDelegate::ShowMultipleAccounts() const { ...@@ -52,7 +52,7 @@ bool UpdatePasswordInfoBarDelegate::ShowMultipleAccounts() const {
return GetCurrentForms().size() > 1 && !is_password_overriden; return GetCurrentForms().size() > 1 && !is_password_overriden;
} }
const std::vector<const autofill::PasswordForm*>& const std::vector<std::unique_ptr<autofill::PasswordForm>>&
UpdatePasswordInfoBarDelegate::GetCurrentForms() const { UpdatePasswordInfoBarDelegate::GetCurrentForms() const {
return passwords_state_.GetCurrentForms(); return passwords_state_.GetCurrentForms();
} }
......
...@@ -40,7 +40,8 @@ class UpdatePasswordInfoBarDelegate : public PasswordManagerInfoBarDelegate { ...@@ -40,7 +40,8 @@ class UpdatePasswordInfoBarDelegate : public PasswordManagerInfoBarDelegate {
// credential is being affected. // credential is being affected.
bool ShowMultipleAccounts() const; bool ShowMultipleAccounts() const;
const std::vector<const autofill::PasswordForm*>& GetCurrentForms() const; const std::vector<std::unique_ptr<autofill::PasswordForm>>&
GetCurrentForms() const;
// Returns the username of the saved credentials in the case when there is // Returns the username of the saved credentials in the case when there is
// only one credential pair stored. // only one credential pair stored.
......
...@@ -41,8 +41,8 @@ UpdatePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) { ...@@ -41,8 +41,8 @@ UpdatePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) {
std::vector<base::string16> usernames; std::vector<base::string16> usernames;
if (update_password_delegate->ShowMultipleAccounts()) { if (update_password_delegate->ShowMultipleAccounts()) {
for (auto* password_form : update_password_delegate->GetCurrentForms()) for (const auto& form : update_password_delegate->GetCurrentForms())
usernames.push_back(password_form->username_value); usernames.push_back(form->username_value);
} else { } else {
usernames.push_back( usernames.push_back(
update_password_delegate->get_username_for_single_account()); update_password_delegate->get_username_for_single_account());
......
...@@ -27,7 +27,8 @@ class PasswordsModelDelegateMock; ...@@ -27,7 +27,8 @@ class PasswordsModelDelegateMock;
class ManagePasswordsControllerTest : public CocoaProfileTest { class ManagePasswordsControllerTest : public CocoaProfileTest {
public: public:
using VectorConstFormPtr = std::vector<const autofill::PasswordForm*>; using VectorConstFormPtr =
std::vector<std::unique_ptr<autofill::PasswordForm>>;
ManagePasswordsControllerTest(); ManagePasswordsControllerTest();
~ManagePasswordsControllerTest() override; ~ManagePasswordsControllerTest() override;
......
...@@ -57,8 +57,6 @@ void ManagePasswordsControllerTest::SetUpSavePendingState(bool empty_username) { ...@@ -57,8 +57,6 @@ void ManagePasswordsControllerTest::SetUpSavePendingState(bool empty_username) {
form.username_value = base::ASCIIToUTF16("username"); form.username_value = base::ASCIIToUTF16("username");
} }
EXPECT_CALL(*ui_controller_, GetPendingPassword()).WillOnce(ReturnRef(form)); EXPECT_CALL(*ui_controller_, GetPendingPassword()).WillOnce(ReturnRef(form));
std::vector<const autofill::PasswordForm*> forms;
EXPECT_CALL(*ui_controller_, GetCurrentForms()).WillOnce(ReturnRef(forms));
GURL origin(kSiteOrigin); GURL origin(kSiteOrigin);
EXPECT_CALL(*ui_controller_, GetOrigin()).WillOnce(ReturnRef(origin)); EXPECT_CALL(*ui_controller_, GetOrigin()).WillOnce(ReturnRef(origin));
EXPECT_CALL(*ui_controller_, GetState()) EXPECT_CALL(*ui_controller_, GetState())
...@@ -71,10 +69,10 @@ void ManagePasswordsControllerTest::SetUpUpdatePendingState( ...@@ -71,10 +69,10 @@ void ManagePasswordsControllerTest::SetUpUpdatePendingState(
bool multiple_forms) { bool multiple_forms) {
autofill::PasswordForm form; autofill::PasswordForm form;
EXPECT_CALL(*ui_controller_, GetPendingPassword()).WillOnce(ReturnRef(form)); EXPECT_CALL(*ui_controller_, GetPendingPassword()).WillOnce(ReturnRef(form));
std::vector<const autofill::PasswordForm*> forms; std::vector<std::unique_ptr<autofill::PasswordForm>> forms;
forms.push_back(&form); forms.push_back(base::MakeUnique<autofill::PasswordForm>(form));
if (multiple_forms) { if (multiple_forms) {
forms.push_back(&form); forms.push_back(base::MakeUnique<autofill::PasswordForm>(form));
} }
EXPECT_CALL(*ui_controller_, GetCurrentForms()).WillOnce(ReturnRef(forms)); EXPECT_CALL(*ui_controller_, GetCurrentForms()).WillOnce(ReturnRef(forms));
GURL origin(kSiteOrigin); GURL origin(kSiteOrigin);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace { namespace {
NSPopUpButton* CreateUsernamesPopUpButton( NSPopUpButton* CreateUsernamesPopUpButton(
const std::vector<const autofill::PasswordForm*>& forms, const std::vector<autofill::PasswordForm>& forms,
const base::string16& best_matched_username) { const base::string16& best_matched_username) {
DCHECK(!forms.empty()); DCHECK(!forms.empty());
std::vector<base::string16> usernames; std::vector<base::string16> usernames;
...@@ -23,11 +23,11 @@ NSPopUpButton* CreateUsernamesPopUpButton( ...@@ -23,11 +23,11 @@ NSPopUpButton* CreateUsernamesPopUpButton(
size_t preffered_form_index = forms.size(); size_t preffered_form_index = forms.size();
for (size_t index = 0; index < forms.size(); ++index) { for (size_t index = 0; index < forms.size(); ++index) {
usernames.push_back(forms[index]->username_value); usernames.push_back(forms[index].username_value);
if (forms[index]->username_value == best_matched_username) { if (forms[index].username_value == best_matched_username) {
best_matched_username_index = index; best_matched_username_index = index;
} }
if (forms[index]->preferred) { if (forms[index].preferred) {
preffered_form_index = index; preffered_form_index = index;
} }
} }
...@@ -61,7 +61,7 @@ NSPopUpButton* CreateUsernamesPopUpButton( ...@@ -61,7 +61,7 @@ NSPopUpButton* CreateUsernamesPopUpButton(
// Create the pop up button with usernames and the password field. // Create the pop up button with usernames and the password field.
usernamePopUpButton_.reset([CreateUsernamesPopUpButton( usernamePopUpButton_.reset([CreateUsernamesPopUpButton(
model_->local_credentials().get(), model_->local_credentials(),
model_->pending_password().username_value) retain]); model_->pending_password().username_value) retain]);
passwordField_.reset( passwordField_.reset(
[PasswordLabel(model_->pending_password().password_value) retain]); [PasswordLabel(model_->pending_password().password_value) retain]);
...@@ -111,7 +111,7 @@ NSPopUpButton* CreateUsernamesPopUpButton( ...@@ -111,7 +111,7 @@ NSPopUpButton* CreateUsernamesPopUpButton(
- (const autofill::PasswordForm*)getSelectedCredentials { - (const autofill::PasswordForm*)getSelectedCredentials {
int selected_index = [usernamePopUpButton_ indexOfSelectedItem]; int selected_index = [usernamePopUpButton_ indexOfSelectedItem];
CHECK(selected_index >= 0); CHECK(selected_index >= 0);
return model_->local_credentials()[selected_index]; return &model_->local_credentials()[selected_index];
} }
@end @end
...@@ -77,8 +77,8 @@ ...@@ -77,8 +77,8 @@
contentView = noPasswordsView_.get(); contentView = noPasswordsView_.get();
} else { } else {
passwordsListController_.reset([[PasswordsListViewController alloc] passwordsListController_.reset([[PasswordsListViewController alloc]
initWithModel:self.model initWithModelAndForms:self.model
forms:self.model->local_credentials().get()]); forms:&self.model->local_credentials()]);
contentView = [passwordsListController_ view]; contentView = [passwordsListController_ view];
} }
[view addSubview:contentView]; [view addSubview:contentView];
......
...@@ -69,15 +69,18 @@ TEST_F(ManagePasswordsViewControllerTest, ...@@ -69,15 +69,18 @@ TEST_F(ManagePasswordsViewControllerTest,
TEST_F(ManagePasswordsViewControllerTest, TEST_F(ManagePasswordsViewControllerTest,
ShouldShowAllPasswordItemsWhenPasswordsExistForSite) { ShouldShowAllPasswordItemsWhenPasswordsExistForSite) {
// Add a few password entries. // Add a few password entries.
autofill::PasswordForm form1; std::unique_ptr<autofill::PasswordForm> form1(new autofill::PasswordForm);
form1.username_value = base::ASCIIToUTF16("username1"); form1->username_value = base::ASCIIToUTF16("username1");
form1.password_value = base::ASCIIToUTF16("password1"); form1->password_value = base::ASCIIToUTF16("password1");
autofill::PasswordForm form2; std::unique_ptr<autofill::PasswordForm> form2(new autofill::PasswordForm);
form2.username_value = base::ASCIIToUTF16("username2"); form2->username_value = base::ASCIIToUTF16("username2");
form2.password_value = base::ASCIIToUTF16("password2"); form2->password_value = base::ASCIIToUTF16("password2");
SetUpManageState({&form1, &form2}); VectorConstFormPtr forms;
forms.push_back(std::move(form1));
forms.push_back(std::move(form2));
SetUpManageState(forms);
// Check the view state. // Check the view state.
ASSERT_TRUE([controller() passwordsListController]); ASSERT_TRUE([controller() passwordsListController]);
......
...@@ -131,8 +131,8 @@ IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest, DoubleOpenBubble) { ...@@ -131,8 +131,8 @@ IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest, DoubleOpenBubble) {
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest, DoubleOpenDifferentBubbles) { IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest, DoubleOpenDifferentBubbles) {
// Open the autosignin bubble first. // Open the autosignin bubble first.
DoWithSwizzledNSWindow(^{ DoWithSwizzledNSWindow(^{
ScopedVector<autofill::PasswordForm> local_credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.push_back(new autofill::PasswordForm(*test_form())); local_credentials.emplace_back(new autofill::PasswordForm(*test_form()));
SetupAutoSignin(std::move(local_credentials)); SetupAutoSignin(std::move(local_credentials));
}); });
EXPECT_TRUE(controller()); EXPECT_TRUE(controller());
......
...@@ -68,8 +68,6 @@ class ManagePasswordsBubbleCocoaTest : public CocoaProfileTest { ...@@ -68,8 +68,6 @@ class ManagePasswordsBubbleCocoaTest : public CocoaProfileTest {
ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(mock)); ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(mock));
autofill::PasswordForm form; autofill::PasswordForm form;
EXPECT_CALL(*mock, GetPendingPassword()).WillOnce(ReturnRef(form)); EXPECT_CALL(*mock, GetPendingPassword()).WillOnce(ReturnRef(form));
std::vector<const autofill::PasswordForm*> forms;
EXPECT_CALL(*mock, GetCurrentForms()).WillOnce(ReturnRef(forms));
GURL origin; GURL origin;
EXPECT_CALL(*mock, GetOrigin()).WillOnce(ReturnRef(origin)); EXPECT_CALL(*mock, GetOrigin()).WillOnce(ReturnRef(origin));
EXPECT_CALL(*mock, GetState()) EXPECT_CALL(*mock, GetState())
......
...@@ -17,7 +17,7 @@ struct PasswordForm; ...@@ -17,7 +17,7 @@ struct PasswordForm;
class ManagePasswordsBubbleModel; class ManagePasswordsBubbleModel;
typedef std::vector<const autofill::PasswordForm*> PasswordFormsVector; typedef std::vector<autofill::PasswordForm> PasswordFormsVector;
// Handles callbacks from ManagePasswordItemViewController. // Handles callbacks from ManagePasswordItemViewController.
@protocol PasswordItemDelegate<NSObject> @protocol PasswordItemDelegate<NSObject>
...@@ -39,8 +39,10 @@ typedef std::vector<const autofill::PasswordForm*> PasswordFormsVector; ...@@ -39,8 +39,10 @@ typedef std::vector<const autofill::PasswordForm*> PasswordFormsVector;
CGFloat firstColumnMaxWidth_; CGFloat firstColumnMaxWidth_;
CGFloat secondColumnMaxWidth_; CGFloat secondColumnMaxWidth_;
} }
- (id)initWithModel:(ManagePasswordsBubbleModel*)model - (id)initWithModelAndForms:(ManagePasswordsBubbleModel*)model
forms:(const PasswordFormsVector&)password_forms; forms:(const PasswordFormsVector*)password_forms;
- (id)initWithModelAndForm:(ManagePasswordsBubbleModel*)model
form:(const autofill::PasswordForm*)form;
@end @end
@interface PasswordsListViewController (Testing) @interface PasswordsListViewController (Testing)
......
...@@ -384,17 +384,17 @@ NSTextField* FederationLabel(const base::string16& text) { ...@@ -384,17 +384,17 @@ NSTextField* FederationLabel(const base::string16& text) {
@synthesize firstColumnMaxWidth = firstColumnMaxWidth_; @synthesize firstColumnMaxWidth = firstColumnMaxWidth_;
@synthesize secondColumnMaxWidth = secondColumnMaxWidth_; @synthesize secondColumnMaxWidth = secondColumnMaxWidth_;
- (id)initWithModel:(ManagePasswordsBubbleModel*)model - (id)initWithModelAndForms:(ManagePasswordsBubbleModel*)model
forms:(const PasswordFormsVector&)password_forms { forms:(const PasswordFormsVector*)password_forms {
if ((self = [super initWithNibName:nil bundle:nil])) { if ((self = [super initWithNibName:nil bundle:nil])) {
base::scoped_nsobject<NSMutableArray> items( base::scoped_nsobject<NSMutableArray> items(
[[NSMutableArray arrayWithCapacity:password_forms.size()] retain]); [[NSMutableArray arrayWithCapacity:password_forms->size()] retain]);
model_ = model; model_ = model;
// Create the controllers. // Create the controllers.
for (const autofill::PasswordForm* form : password_forms) { for (const auto& form : *password_forms) {
base::scoped_nsobject<ManagePasswordItemViewController> item( base::scoped_nsobject<ManagePasswordItemViewController> item(
[[ManagePasswordItemViewController alloc] initWithDelegate:self [[ManagePasswordItemViewController alloc] initWithDelegate:self
passwordForm:form]); passwordForm:&form]);
[items addObject:item.get()]; [items addObject:item.get()];
} }
itemViews_.reset(items.release()); itemViews_.reset(items.release());
...@@ -402,6 +402,21 @@ NSTextField* FederationLabel(const base::string16& text) { ...@@ -402,6 +402,21 @@ NSTextField* FederationLabel(const base::string16& text) {
return self; return self;
} }
- (id)initWithModelAndForm:(ManagePasswordsBubbleModel*)model
form:(const autofill::PasswordForm*)form {
if ((self = [super initWithNibName:nil bundle:nil])) {
base::scoped_nsobject<NSMutableArray> items(
[[NSMutableArray arrayWithCapacity:1] retain]);
model_ = model;
base::scoped_nsobject<ManagePasswordItemViewController> item(
[[ManagePasswordItemViewController alloc] initWithDelegate:self
passwordForm:form]);
[items addObject:item.get()];
itemViews_.reset(items.release());
}
return self;
}
- (void)loadView { - (void)loadView {
base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
......
...@@ -35,18 +35,21 @@ class PasswordsListViewControllerTest : public ManagePasswordsControllerTest { ...@@ -35,18 +35,21 @@ class PasswordsListViewControllerTest : public ManagePasswordsControllerTest {
public: public:
PasswordsListViewControllerTest() = default; PasswordsListViewControllerTest() = default;
void SetUpManageState(const VectorConstFormPtr& forms) { void SetUpManageState(const PasswordFormsVector* forms) {
ManagePasswordsControllerTest::SetUpManageState(forms); VectorConstFormPtr unique_ptr_forms(forms->size());
for (size_t i = 0; i < forms->size(); ++i)
unique_ptr_forms[i].reset(new autofill::PasswordForm(forms->at(i)));
ManagePasswordsControllerTest::SetUpManageState(unique_ptr_forms);
controller_.reset([[PasswordsListViewController alloc] controller_.reset([[PasswordsListViewController alloc]
initWithModel:GetModelAndCreateIfNull() initWithModelAndForms:GetModelAndCreateIfNull()
forms:forms]); forms:forms]);
} }
void SetUpPendingState(const autofill::PasswordForm* form) { void SetUpPendingState(const autofill::PasswordForm* form) {
ManagePasswordsControllerTest::SetUpSavePendingState(false); ManagePasswordsControllerTest::SetUpSavePendingState(false);
controller_.reset([[PasswordsListViewController alloc] controller_.reset([[PasswordsListViewController alloc]
initWithModel:GetModelAndCreateIfNull() initWithModelAndForm:GetModelAndCreateIfNull()
forms:std::vector<const autofill::PasswordForm*>(1, form)]); form:form]);
} }
ManagePasswordItemViewController* GetControllerAt(unsigned i) { ManagePasswordItemViewController* GetControllerAt(unsigned i) {
...@@ -88,10 +91,10 @@ class PasswordsListViewControllerTest : public ManagePasswordsControllerTest { ...@@ -88,10 +91,10 @@ class PasswordsListViewControllerTest : public ManagePasswordsControllerTest {
}; };
TEST_F(PasswordsListViewControllerTest, ManageStateShouldHaveManageView) { TEST_F(PasswordsListViewControllerTest, ManageStateShouldHaveManageView) {
ScopedVector<const autofill::PasswordForm> forms; std::vector<autofill::PasswordForm> forms;
forms.push_back(new autofill::PasswordForm(local_credential())); forms.push_back(local_credential());
forms.push_back(new autofill::PasswordForm(federated_credential())); forms.push_back(federated_credential());
SetUpManageState(forms.get()); SetUpManageState(&forms);
EXPECT_EQ(MANAGE_PASSWORD_ITEM_STATE_MANAGE, [GetControllerAt(0) state]); EXPECT_EQ(MANAGE_PASSWORD_ITEM_STATE_MANAGE, [GetControllerAt(0) state]);
EXPECT_EQ(MANAGE_PASSWORD_ITEM_STATE_MANAGE, [GetControllerAt(1) state]); EXPECT_EQ(MANAGE_PASSWORD_ITEM_STATE_MANAGE, [GetControllerAt(1) state]);
...@@ -103,9 +106,9 @@ TEST_F(PasswordsListViewControllerTest, ManageStateShouldHaveManageView) { ...@@ -103,9 +106,9 @@ TEST_F(PasswordsListViewControllerTest, ManageStateShouldHaveManageView) {
TEST_F(PasswordsListViewControllerTest, TEST_F(PasswordsListViewControllerTest,
ClickingDeleteShouldShowUndoViewAndDeletePassword) { ClickingDeleteShouldShowUndoViewAndDeletePassword) {
ScopedVector<const autofill::PasswordForm> forms; std::vector<autofill::PasswordForm> forms;
forms.push_back(new autofill::PasswordForm(local_credential())); forms.push_back(local_credential());
SetUpManageState(forms.get()); SetUpManageState(&forms);
ManagePasswordItemView* manageView = ManagePasswordItemView* manageView =
base::mac::ObjCCast<ManagePasswordItemView>( base::mac::ObjCCast<ManagePasswordItemView>(
...@@ -119,9 +122,9 @@ TEST_F(PasswordsListViewControllerTest, ...@@ -119,9 +122,9 @@ TEST_F(PasswordsListViewControllerTest,
TEST_F(PasswordsListViewControllerTest, TEST_F(PasswordsListViewControllerTest,
ClickingUndoShouldShowManageViewAndAddPassword) { ClickingUndoShouldShowManageViewAndAddPassword) {
ScopedVector<const autofill::PasswordForm> forms; std::vector<autofill::PasswordForm> forms;
forms.push_back(new autofill::PasswordForm(local_credential())); forms.push_back(local_credential());
SetUpManageState(forms.get()); SetUpManageState(&forms);
ManagePasswordItemView* manageView = ManagePasswordItemView* manageView =
base::mac::ObjCCast<ManagePasswordItemView>( base::mac::ObjCCast<ManagePasswordItemView>(
...@@ -140,10 +143,10 @@ TEST_F(PasswordsListViewControllerTest, ...@@ -140,10 +143,10 @@ TEST_F(PasswordsListViewControllerTest,
TEST_F(PasswordsListViewControllerTest, TEST_F(PasswordsListViewControllerTest,
ManageViewShouldHaveCorrectUsernameAndObscuredPassword) { ManageViewShouldHaveCorrectUsernameAndObscuredPassword) {
ScopedVector<const autofill::PasswordForm> forms; std::vector<autofill::PasswordForm> forms;
forms.push_back(new autofill::PasswordForm(local_credential())); forms.push_back(local_credential());
forms.push_back(new autofill::PasswordForm(federated_credential())); forms.push_back(federated_credential());
SetUpManageState(forms.get()); SetUpManageState(&forms);
ManagePasswordItemView* manageView = ManagePasswordItemView* manageView =
base::mac::ObjCCast<ManagePasswordItemView>( base::mac::ObjCCast<ManagePasswordItemView>(
[GetControllerAt(0) contentView]); [GetControllerAt(0) contentView]);
......
...@@ -42,11 +42,9 @@ ...@@ -42,11 +42,9 @@
- (NSView*)createPasswordView { - (NSView*)createPasswordView {
if (self.model->pending_password().username_value.empty()) if (self.model->pending_password().username_value.empty())
return nil; return nil;
std::vector<const autofill::PasswordForm*> password_forms;
password_forms.push_back(&self.model->pending_password());
passwordItem_.reset([[PasswordsListViewController alloc] passwordItem_.reset([[PasswordsListViewController alloc]
initWithModel:self.model initWithModelAndForm:self.model
forms:password_forms]); form:&self.model->pending_password()]);
return [passwordItem_ view]; return [passwordItem_ view];
} }
......
...@@ -48,11 +48,9 @@ ...@@ -48,11 +48,9 @@
[[CredentialsSelectionView alloc] initWithModel:self.model]); [[CredentialsSelectionView alloc] initWithModel:self.model]);
return passwordWithUsernameSelectionItem_.get(); return passwordWithUsernameSelectionItem_.get();
} else { } else {
std::vector<const autofill::PasswordForm*> password_forms;
password_forms.push_back(&self.model->pending_password());
passwordItem_.reset([[PasswordsListViewController alloc] passwordItem_.reset([[PasswordsListViewController alloc]
initWithModel:self.model initWithModelAndForm:self.model
forms:password_forms]); form:&self.model->pending_password()]);
return [passwordItem_ view]; return [passwordItem_ view];
} }
......
...@@ -50,14 +50,14 @@ void CleanStatisticsForSite(Profile* profile, const GURL& origin) { ...@@ -50,14 +50,14 @@ void CleanStatisticsForSite(Profile* profile, const GURL& origin) {
password_store->RemoveSiteStats(origin.GetOrigin()); password_store->RemoveSiteStats(origin.GetOrigin());
} }
ScopedVector<const autofill::PasswordForm> DeepCopyForms( std::vector<autofill::PasswordForm> DeepCopyForms(
const std::vector<const autofill::PasswordForm*>& forms) { const std::vector<std::unique_ptr<autofill::PasswordForm>>& forms) {
ScopedVector<const autofill::PasswordForm> result; std::vector<autofill::PasswordForm> result;
result.reserve(forms.size()); result.reserve(forms.size());
std::transform(forms.begin(), forms.end(), std::back_inserter(result), std::transform(forms.begin(), forms.end(), std::back_inserter(result),
[](const autofill::PasswordForm* form) { [](const std::unique_ptr<autofill::PasswordForm>& form) {
return new autofill::PasswordForm(*form); return *form;
}); });
return result; return result;
} }
...@@ -206,31 +206,37 @@ ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( ...@@ -206,31 +206,37 @@ ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
delegate_(std::move(delegate)) { delegate_(std::move(delegate)) {
origin_ = delegate_->GetOrigin(); origin_ = delegate_->GetOrigin();
state_ = delegate_->GetState(); state_ = delegate_->GetState();
password_manager::InteractionsStats interaction_stats;
if (state_ == password_manager::ui::PENDING_PASSWORD_STATE || if (state_ == password_manager::ui::PENDING_PASSWORD_STATE ||
state_ == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { state_ == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) {
pending_password_ = delegate_->GetPendingPassword(); pending_password_ = delegate_->GetPendingPassword();
local_credentials_ = DeepCopyForms(delegate_->GetCurrentForms()); if (state_ == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) {
} else if (state_ == password_manager::ui::CONFIRMATION_STATE) { local_credentials_ = DeepCopyForms(delegate_->GetCurrentForms());
// We don't need anything. password_overridden_ = delegate_->IsPasswordOverridden();
} else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { } else {
pending_password_ = delegate_->GetPendingPassword(); interaction_stats.origin_domain = origin_.GetOrigin();
} else { interaction_stats.username_value = pending_password_.username_value;
local_credentials_ = DeepCopyForms(delegate_->GetCurrentForms()); password_manager::InteractionsStats* stats =
} delegate_->GetCurrentInteractionStats();
if (stats) {
if (state_ == password_manager::ui::PENDING_PASSWORD_STATE || DCHECK_EQ(interaction_stats.username_value, stats->username_value);
state_ == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { DCHECK_EQ(interaction_stats.origin_domain, stats->origin_domain);
interaction_stats.dismissal_count = stats->dismissal_count;
}
}
UpdatePendingStateTitle(); UpdatePendingStateTitle();
} else if (state_ == password_manager::ui::CONFIRMATION_STATE) { } else if (state_ == password_manager::ui::CONFIRMATION_STATE) {
title_ = title_ =
l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE);
} else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) {
// There is no title. pending_password_ = delegate_->GetPendingPassword();
} else if (state_ == password_manager::ui::MANAGE_STATE) { } else if (state_ == password_manager::ui::MANAGE_STATE) {
local_credentials_ = DeepCopyForms(delegate_->GetCurrentForms());
UpdateManageStateTitle(); UpdateManageStateTitle();
manage_link_ =
l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK);
} }
password_manager::InteractionsStats interaction_stats;
if (state_ == password_manager::ui::CONFIRMATION_STATE) { if (state_ == password_manager::ui::CONFIRMATION_STATE) {
base::string16 save_confirmation_link = base::string16 save_confirmation_link =
l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_LINK); l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_LINK);
...@@ -250,23 +256,8 @@ ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( ...@@ -250,23 +256,8 @@ ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
confirmation_text_id, save_confirmation_link, &offset); confirmation_text_id, save_confirmation_link, &offset);
save_confirmation_link_range_ = save_confirmation_link_range_ =
gfx::Range(offset, offset + save_confirmation_link.length()); gfx::Range(offset, offset + save_confirmation_link.length());
} else if (state_ == password_manager::ui::PENDING_PASSWORD_STATE) {
interaction_stats.origin_domain = origin_.GetOrigin();
interaction_stats.username_value = pending_password_.username_value;
password_manager::InteractionsStats* stats =
delegate_->GetCurrentInteractionStats();
if (stats) {
DCHECK_EQ(interaction_stats.username_value, stats->username_value);
DCHECK_EQ(interaction_stats.origin_domain, stats->origin_domain);
interaction_stats.dismissal_count = stats->dismissal_count;
}
} else if (state_ == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) {
password_overridden_ = delegate_->IsPasswordOverridden();
} }
manage_link_ =
l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK);
password_manager::metrics_util::UIDisplayDisposition display_disposition = password_manager::metrics_util::UIDisplayDisposition display_disposition =
metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING; metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING;
if (display_reason == USER_ACTION) { if (display_reason == USER_ACTION) {
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_ #define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_MODEL_H_
#include <utility> #include <utility>
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/time/clock.h" #include "base/time/clock.h"
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
...@@ -88,7 +88,7 @@ class ManagePasswordsBubbleModel { ...@@ -88,7 +88,7 @@ class ManagePasswordsBubbleModel {
return pending_password_; return pending_password_;
} }
// Returns the available credentials which match the current site. // Returns the available credentials which match the current site.
const ScopedVector<const autofill::PasswordForm>& local_credentials() const { const std::vector<autofill::PasswordForm>& local_credentials() const {
return local_credentials_; return local_credentials_;
} }
const base::string16& manage_link() const { return manage_link_; } const base::string16& manage_link() const { return manage_link_; }
...@@ -144,7 +144,7 @@ class ManagePasswordsBubbleModel { ...@@ -144,7 +144,7 @@ class ManagePasswordsBubbleModel {
gfx::Range title_brand_link_range_; gfx::Range title_brand_link_range_;
autofill::PasswordForm pending_password_; autofill::PasswordForm pending_password_;
bool password_overridden_; bool password_overridden_;
ScopedVector<const autofill::PasswordForm> local_credentials_; std::vector<autofill::PasswordForm> local_credentials_;
base::string16 manage_link_; base::string16 manage_link_;
base::string16 save_confirmation_text_; base::string16 save_confirmation_text_;
gfx::Range save_confirmation_link_range_; gfx::Range save_confirmation_link_range_;
......
...@@ -172,8 +172,6 @@ void ManagePasswordsBubbleModelTest::SetUpWithState( ...@@ -172,8 +172,6 @@ void ManagePasswordsBubbleModelTest::SetUpWithState(
void ManagePasswordsBubbleModelTest::PretendPasswordWaiting() { void ManagePasswordsBubbleModelTest::PretendPasswordWaiting() {
autofill::PasswordForm form = GetPendingPassword(); autofill::PasswordForm form = GetPendingPassword();
EXPECT_CALL(*controller(), GetPendingPassword()).WillOnce(ReturnRef(form)); EXPECT_CALL(*controller(), GetPendingPassword()).WillOnce(ReturnRef(form));
std::vector<const autofill::PasswordForm*> forms;
EXPECT_CALL(*controller(), GetCurrentForms()).WillOnce(ReturnRef(forms));
password_manager::InteractionsStats stats = GetTestStats(); password_manager::InteractionsStats stats = GetTestStats();
EXPECT_CALL(*controller(), GetCurrentInteractionStats()) EXPECT_CALL(*controller(), GetCurrentInteractionStats())
.WillOnce(Return(&stats)); .WillOnce(Return(&stats));
...@@ -184,7 +182,7 @@ void ManagePasswordsBubbleModelTest::PretendPasswordWaiting() { ...@@ -184,7 +182,7 @@ void ManagePasswordsBubbleModelTest::PretendPasswordWaiting() {
void ManagePasswordsBubbleModelTest::PretendUpdatePasswordWaiting() { void ManagePasswordsBubbleModelTest::PretendUpdatePasswordWaiting() {
autofill::PasswordForm form = GetPendingPassword(); autofill::PasswordForm form = GetPendingPassword();
EXPECT_CALL(*controller(), GetPendingPassword()).WillOnce(ReturnRef(form)); EXPECT_CALL(*controller(), GetPendingPassword()).WillOnce(ReturnRef(form));
std::vector<const autofill::PasswordForm*> forms; std::vector<std::unique_ptr<autofill::PasswordForm>> forms;
EXPECT_CALL(*controller(), GetCurrentForms()).WillOnce(ReturnRef(forms)); EXPECT_CALL(*controller(), GetCurrentForms()).WillOnce(ReturnRef(forms));
EXPECT_CALL(*controller(), IsPasswordOverridden()).WillOnce(Return(false)); EXPECT_CALL(*controller(), IsPasswordOverridden()).WillOnce(Return(false));
SetUpWithState(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE, SetUpWithState(password_manager::ui::PENDING_PASSWORD_UPDATE_STATE,
...@@ -199,8 +197,8 @@ void ManagePasswordsBubbleModelTest::PretendAutoSigningIn() { ...@@ -199,8 +197,8 @@ void ManagePasswordsBubbleModelTest::PretendAutoSigningIn() {
} }
void ManagePasswordsBubbleModelTest::PretendManagingPasswords() { void ManagePasswordsBubbleModelTest::PretendManagingPasswords() {
autofill::PasswordForm form = GetPendingPassword(); std::vector<std::unique_ptr<autofill::PasswordForm>> forms(1);
std::vector<const autofill::PasswordForm*> forms(1, &form); forms[0].reset(new autofill::PasswordForm(GetPendingPassword()));
EXPECT_CALL(*controller(), GetCurrentForms()).WillOnce(ReturnRef(forms)); EXPECT_CALL(*controller(), GetCurrentForms()).WillOnce(ReturnRef(forms));
SetUpWithState(password_manager::ui::MANAGE_STATE, SetUpWithState(password_manager::ui::MANAGE_STATE,
ManagePasswordsBubbleModel::USER_ACTION); ManagePasswordsBubbleModel::USER_ACTION);
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/password_store_change.h" #include "components/password_manager/core/browser/password_store_change.h"
#include "components/password_manager/core/common/credential_manager_types.h" #include "components/password_manager/core/common/credential_manager_types.h"
...@@ -51,13 +50,14 @@ class ManagePasswordsState { ...@@ -51,13 +50,14 @@ class ManagePasswordsState {
// Move to CREDENTIAL_REQUEST_STATE. // Move to CREDENTIAL_REQUEST_STATE.
void OnRequestCredentials( void OnRequestCredentials(
ScopedVector<autofill::PasswordForm> local_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials,
ScopedVector<autofill::PasswordForm> federated_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>> federation_providers,
const GURL& origin); const GURL& origin);
// Move to AUTO_SIGNIN_STATE. |local_forms| can't be empty. // Move to AUTO_SIGNIN_STATE. |local_forms| can't be empty.
void OnAutoSignin(ScopedVector<autofill::PasswordForm> local_forms, void OnAutoSignin(
const GURL& origin); std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms,
const GURL& origin);
// Move to CONFIRMATION_STATE. // Move to CONFIRMATION_STATE.
void OnAutomaticPasswordSave( void OnAutomaticPasswordSave(
...@@ -103,14 +103,15 @@ class ManagePasswordsState { ...@@ -103,14 +103,15 @@ class ManagePasswordsState {
} }
// Current local forms. ManagePasswordsState is responsible for the forms. // Current local forms. ManagePasswordsState is responsible for the forms.
const std::vector<const autofill::PasswordForm*>& GetCurrentForms() const { const std::vector<std::unique_ptr<autofill::PasswordForm>>& GetCurrentForms()
return form_manager_ ? current_forms_weak_ : local_credentials_forms_.get(); const {
return local_credentials_forms_;
} }
// Current federated forms. // Current federated forms.
const std::vector<const autofill::PasswordForm*>& const std::vector<std::unique_ptr<autofill::PasswordForm>>&
federated_credentials_forms() const { federation_providers_forms() const {
return federated_credentials_forms_.get(); return federation_providers_forms_;
} }
private: private:
...@@ -133,19 +134,12 @@ class ManagePasswordsState { ...@@ -133,19 +134,12 @@ class ManagePasswordsState {
// Contains the password that was submitted. // Contains the password that was submitted.
std::unique_ptr<password_manager::PasswordFormManager> form_manager_; std::unique_ptr<password_manager::PasswordFormManager> form_manager_;
// Weak references to the passwords for the current status. The hard pointers // Contains all the current forms.
// are scattered between |form_manager_| and |local_credentials_forms_|. If std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials_forms_;
// |form_manager_| is nullptr then all the forms are stored in
// |local_credentials_forms_|. |current_forms_weak_| remains empty.
std::vector<const autofill::PasswordForm*> current_forms_weak_;
// If |form_manager_| is nullptr then |local_credentials_forms_| contains all
// the current forms. Otherwise, it's a container for the new forms coming
// from the PasswordStore.
ScopedVector<const autofill::PasswordForm> local_credentials_forms_;
// Federated credentials for the CREDENTIAL_REQUEST_STATE. // Federation providers for the CREDENTIAL_REQUEST_STATE.
ScopedVector<const autofill::PasswordForm> federated_credentials_forms_; std::vector<std::unique_ptr<autofill::PasswordForm>>
federation_providers_forms_;
// A callback to be invoked when user selects a credential. // A callback to be invoked when user selects a credential.
CredentialsCallback credentials_callback_; CredentialsCallback credentials_callback_;
......
...@@ -83,7 +83,7 @@ void ManagePasswordsTest::SetupAutomaticPassword() { ...@@ -83,7 +83,7 @@ void ManagePasswordsTest::SetupAutomaticPassword() {
} }
void ManagePasswordsTest::SetupAutoSignin( void ManagePasswordsTest::SetupAutoSignin(
ScopedVector<autofill::PasswordForm> local_credentials) { std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials) {
ASSERT_FALSE(local_credentials.empty()); ASSERT_FALSE(local_credentials.empty());
GURL origin = local_credentials[0]->origin; GURL origin = local_credentials[0]->origin;
GetController()->OnAutoSignin(std::move(local_credentials), origin); GetController()->OnAutoSignin(std::move(local_credentials), origin);
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "base/metrics/histogram_samples.h" #include "base/metrics/histogram_samples.h"
#include "base/test/histogram_tester.h" #include "base/test/histogram_tester.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
...@@ -47,7 +46,7 @@ class ManagePasswordsTest : public InProcessBrowserTest { ...@@ -47,7 +46,7 @@ class ManagePasswordsTest : public InProcessBrowserTest {
// Put the controller, icon, and bubble into an auto sign-in state. // Put the controller, icon, and bubble into an auto sign-in state.
void SetupAutoSignin( void SetupAutoSignin(
ScopedVector<autofill::PasswordForm> local_credentials); std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials);
// Get samples for |histogram|. // Get samples for |histogram|.
std::unique_ptr<base::HistogramSamples> GetSamples(const char* histogram); std::unique_ptr<base::HistogramSamples> GetSamples(const char* histogram);
......
...@@ -45,7 +45,7 @@ password_manager::PasswordStore* GetPasswordStore( ...@@ -45,7 +45,7 @@ password_manager::PasswordStore* GetPasswordStore(
} }
std::vector<std::unique_ptr<autofill::PasswordForm>> CopyFormVector( std::vector<std::unique_ptr<autofill::PasswordForm>> CopyFormVector(
const ScopedVector<autofill::PasswordForm>& forms) { const std::vector<std::unique_ptr<autofill::PasswordForm>>& forms) {
std::vector<std::unique_ptr<autofill::PasswordForm>> result(forms.size()); std::vector<std::unique_ptr<autofill::PasswordForm>> result(forms.size());
for (size_t i = 0; i < forms.size(); ++i) for (size_t i = 0; i < forms.size(); ++i)
result[i].reset(new autofill::PasswordForm(*forms[i])); result[i].reset(new autofill::PasswordForm(*forms[i]));
...@@ -97,8 +97,8 @@ void ManagePasswordsUIController::OnUpdatePasswordSubmitted( ...@@ -97,8 +97,8 @@ void ManagePasswordsUIController::OnUpdatePasswordSubmitted(
} }
bool ManagePasswordsUIController::OnChooseCredentials( bool ManagePasswordsUIController::OnChooseCredentials(
ScopedVector<autofill::PasswordForm> local_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials,
ScopedVector<autofill::PasswordForm> federated_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>> federated_credentials,
const GURL& origin, const GURL& origin,
const ManagePasswordsState::CredentialsCallback& callback) { const ManagePasswordsState::CredentialsCallback& callback) {
DCHECK(!local_credentials.empty() || !federated_credentials.empty()); DCHECK(!local_credentials.empty() || !federated_credentials.empty());
...@@ -120,7 +120,7 @@ bool ManagePasswordsUIController::OnChooseCredentials( ...@@ -120,7 +120,7 @@ bool ManagePasswordsUIController::OnChooseCredentials(
} }
void ManagePasswordsUIController::OnAutoSignin( void ManagePasswordsUIController::OnAutoSignin(
ScopedVector<autofill::PasswordForm> local_forms, std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms,
const GURL& origin) { const GURL& origin) {
DCHECK(!local_forms.empty()); DCHECK(!local_forms.empty());
DestroyAccountChooser(); DestroyAccountChooser();
...@@ -231,14 +231,14 @@ bool ManagePasswordsUIController::IsPasswordOverridden() const { ...@@ -231,14 +231,14 @@ bool ManagePasswordsUIController::IsPasswordOverridden() const {
return form_manager ? form_manager->password_overridden() : false; return form_manager ? form_manager->password_overridden() : false;
} }
const std::vector<const autofill::PasswordForm*>& const std::vector<std::unique_ptr<autofill::PasswordForm>>&
ManagePasswordsUIController::GetCurrentForms() const { ManagePasswordsUIController::GetCurrentForms() const {
return passwords_data_.GetCurrentForms(); return passwords_data_.GetCurrentForms();
} }
const std::vector<const autofill::PasswordForm*>& const std::vector<std::unique_ptr<autofill::PasswordForm>>&
ManagePasswordsUIController::GetFederatedForms() const { ManagePasswordsUIController::GetFederatedForms() const {
return passwords_data_.federated_credentials_forms(); return passwords_data_.federation_providers_forms();
} }
password_manager::InteractionsStats* password_manager::InteractionsStats*
......
...@@ -52,12 +52,14 @@ class ManagePasswordsUIController ...@@ -52,12 +52,14 @@ class ManagePasswordsUIController
std::unique_ptr<password_manager::PasswordFormManager> form_manager) std::unique_ptr<password_manager::PasswordFormManager> form_manager)
override; override;
bool OnChooseCredentials( bool OnChooseCredentials(
ScopedVector<autofill::PasswordForm> local_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials,
ScopedVector<autofill::PasswordForm> federated_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>>
federated_credentials,
const GURL& origin, const GURL& origin,
const ManagePasswordsState::CredentialsCallback& callback) override; const ManagePasswordsState::CredentialsCallback& callback) override;
void OnAutoSignin(ScopedVector<autofill::PasswordForm> local_forms, void OnAutoSignin(
const GURL& origin) override; std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms,
const GURL& origin) override;
void OnPromptEnableAutoSignin() override; void OnPromptEnableAutoSignin() override;
void OnAutomaticPasswordSave( void OnAutomaticPasswordSave(
std::unique_ptr<password_manager::PasswordFormManager> form_manager) std::unique_ptr<password_manager::PasswordFormManager> form_manager)
...@@ -88,10 +90,10 @@ class ManagePasswordsUIController ...@@ -88,10 +90,10 @@ class ManagePasswordsUIController
password_manager::ui::State GetState() const override; password_manager::ui::State GetState() const override;
const autofill::PasswordForm& GetPendingPassword() const override; const autofill::PasswordForm& GetPendingPassword() const override;
bool IsPasswordOverridden() const override; bool IsPasswordOverridden() const override;
const std::vector<const autofill::PasswordForm*>& GetCurrentForms() const std::vector<std::unique_ptr<autofill::PasswordForm>>& GetCurrentForms()
const override;
const std::vector<const autofill::PasswordForm*>& GetFederatedForms()
const override; const override;
const std::vector<std::unique_ptr<autofill::PasswordForm>>&
GetFederatedForms() const override;
password_manager::InteractionsStats* GetCurrentInteractionStats() const password_manager::InteractionsStats* GetCurrentInteractionStats() const
override; override;
void OnBubbleShown() override; void OnBubbleShown() override;
......
...@@ -23,10 +23,12 @@ class ManagePasswordsUIControllerMock : public ManagePasswordsUIController { ...@@ -23,10 +23,12 @@ class ManagePasswordsUIControllerMock : public ManagePasswordsUIController {
MOCK_CONST_METHOD0(GetState, password_manager::ui::State()); MOCK_CONST_METHOD0(GetState, password_manager::ui::State());
MOCK_CONST_METHOD0(GetPendingPassword, const autofill::PasswordForm&()); MOCK_CONST_METHOD0(GetPendingPassword, const autofill::PasswordForm&());
MOCK_CONST_METHOD0(IsPasswordOverridden, bool()); MOCK_CONST_METHOD0(IsPasswordOverridden, bool());
MOCK_CONST_METHOD0(GetCurrentForms, MOCK_CONST_METHOD0(
const std::vector<const autofill::PasswordForm*>&()); GetCurrentForms,
MOCK_CONST_METHOD0(GetFederatedForms, const std::vector<std::unique_ptr<autofill::PasswordForm>>&());
const std::vector<const autofill::PasswordForm*>&()); MOCK_CONST_METHOD0(
GetFederatedForms,
const std::vector<std::unique_ptr<autofill::PasswordForm>>&());
MOCK_CONST_METHOD0(GetCurrentInteractionStats, MOCK_CONST_METHOD0(GetCurrentInteractionStats,
password_manager::InteractionsStats*()); password_manager::InteractionsStats*());
MOCK_METHOD0(OnBubbleShown, void()); MOCK_METHOD0(OnBubbleShown, void());
......
...@@ -310,7 +310,7 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordAutofilled) { ...@@ -310,7 +310,7 @@ TEST_F(ManagePasswordsUIControllerTest, PasswordAutofilled) {
EXPECT_EQ(kTestUsername, controller()->GetCurrentForms()[0]->username_value); EXPECT_EQ(kTestUsername, controller()->GetCurrentForms()[0]->username_value);
// Controller should store a separate copy of the form as it doesn't own it. // Controller should store a separate copy of the form as it doesn't own it.
EXPECT_NE(test_form_ptr, controller()->GetCurrentForms()[0]); EXPECT_NE(test_form_ptr, controller()->GetCurrentForms()[0].get());
ExpectIconStateIs(password_manager::ui::MANAGE_STATE); ExpectIconStateIs(password_manager::ui::MANAGE_STATE);
} }
...@@ -519,9 +519,9 @@ TEST_F(ManagePasswordsUIControllerTest, AutomaticPasswordSave) { ...@@ -519,9 +519,9 @@ TEST_F(ManagePasswordsUIControllerTest, AutomaticPasswordSave) {
} }
TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocal) { TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocal) {
ScopedVector<autofill::PasswordForm> local_credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.push_back(new autofill::PasswordForm(test_local_form())); local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
ScopedVector<autofill::PasswordForm> federated_credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> federated_credentials;
GURL origin("http://example.com"); GURL origin("http://example.com");
PasswordDialogController* dialog_controller = nullptr; PasswordDialogController* dialog_controller = nullptr;
EXPECT_CALL(*controller(), CreateAccountChooser(_)).WillOnce( EXPECT_CALL(*controller(), CreateAccountChooser(_)).WillOnce(
...@@ -552,10 +552,10 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocal) { ...@@ -552,10 +552,10 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocal) {
} }
TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocalButFederated) { TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocalButFederated) {
ScopedVector<autofill::PasswordForm> local_credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.push_back( local_credentials.emplace_back(
new autofill::PasswordForm(test_federated_form())); new autofill::PasswordForm(test_federated_form()));
ScopedVector<autofill::PasswordForm> federated_credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> federated_credentials;
GURL origin("http://example.com"); GURL origin("http://example.com");
PasswordDialogController* dialog_controller = nullptr; PasswordDialogController* dialog_controller = nullptr;
EXPECT_CALL(*controller(), CreateAccountChooser(_)).WillOnce( EXPECT_CALL(*controller(), CreateAccountChooser(_)).WillOnce(
...@@ -586,9 +586,9 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocalButFederated) { ...@@ -586,9 +586,9 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialLocalButFederated) {
} }
TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialCancel) { TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialCancel) {
ScopedVector<autofill::PasswordForm> local_credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.push_back(new autofill::PasswordForm(test_local_form())); local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
ScopedVector<autofill::PasswordForm> federated_credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> federated_credentials;
GURL origin("http://example.com"); GURL origin("http://example.com");
PasswordDialogController* dialog_controller = nullptr; PasswordDialogController* dialog_controller = nullptr;
EXPECT_CALL(*controller(), CreateAccountChooser(_)).WillOnce( EXPECT_CALL(*controller(), CreateAccountChooser(_)).WillOnce(
...@@ -611,8 +611,8 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialCancel) { ...@@ -611,8 +611,8 @@ TEST_F(ManagePasswordsUIControllerTest, ChooseCredentialCancel) {
} }
TEST_F(ManagePasswordsUIControllerTest, AutoSignin) { TEST_F(ManagePasswordsUIControllerTest, AutoSignin) {
ScopedVector<autofill::PasswordForm> local_credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.push_back(new autofill::PasswordForm(test_local_form())); local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnAutoSignin(std::move(local_credentials), controller()->OnAutoSignin(std::move(local_credentials),
test_local_form().origin); test_local_form().origin);
...@@ -679,8 +679,8 @@ TEST_F(ManagePasswordsUIControllerTest, AutoSigninFirstRunAfterNavigation) { ...@@ -679,8 +679,8 @@ TEST_F(ManagePasswordsUIControllerTest, AutoSigninFirstRunAfterNavigation) {
} }
TEST_F(ManagePasswordsUIControllerTest, AutofillDuringAutoSignin) { TEST_F(ManagePasswordsUIControllerTest, AutofillDuringAutoSignin) {
ScopedVector<autofill::PasswordForm> local_credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.push_back(new autofill::PasswordForm(test_local_form())); local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnAutoSignin(std::move(local_credentials), controller()->OnAutoSignin(std::move(local_credentials),
test_local_form().origin); test_local_form().origin);
...@@ -749,8 +749,8 @@ TEST_F(ManagePasswordsUIControllerTest, ConfirmationStatePasswordAutofilled) { ...@@ -749,8 +749,8 @@ TEST_F(ManagePasswordsUIControllerTest, ConfirmationStatePasswordAutofilled) {
TEST_F(ManagePasswordsUIControllerTest, OpenBubbleTwice) { TEST_F(ManagePasswordsUIControllerTest, OpenBubbleTwice) {
// Open the autosignin bubble. // Open the autosignin bubble.
ScopedVector<autofill::PasswordForm> local_credentials; std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.push_back(new autofill::PasswordForm(test_local_form())); local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnAutoSignin(std::move(local_credentials), controller()->OnAutoSignin(std::move(local_credentials),
test_local_form().origin); test_local_form().origin);
...@@ -760,7 +760,7 @@ TEST_F(ManagePasswordsUIControllerTest, OpenBubbleTwice) { ...@@ -760,7 +760,7 @@ TEST_F(ManagePasswordsUIControllerTest, OpenBubbleTwice) {
controller()->GetModelDelegateProxy(); controller()->GetModelDelegateProxy();
// Open the bubble again. // Open the bubble again.
local_credentials.push_back(new autofill::PasswordForm(test_local_form())); local_credentials.emplace_back(new autofill::PasswordForm(test_local_form()));
EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility()); EXPECT_CALL(*controller(), OnUpdateBubbleAndIconVisibility());
controller()->OnAutoSignin(std::move(local_credentials), controller()->OnAutoSignin(std::move(local_credentials),
test_local_form().origin); test_local_form().origin);
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <vector> #include <vector>
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/scoped_vector.h"
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
namespace content { namespace content {
...@@ -45,15 +44,16 @@ class PasswordsClientUIDelegate { ...@@ -45,15 +44,16 @@ class PasswordsClientUIDelegate {
// a decision. If the UI isn't shown the method returns false and doesn't call // a decision. If the UI isn't shown the method returns false and doesn't call
// |callback|. // |callback|.
virtual bool OnChooseCredentials( virtual bool OnChooseCredentials(
ScopedVector<autofill::PasswordForm> local_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials,
ScopedVector<autofill::PasswordForm> federated_credentials, std::vector<std::unique_ptr<autofill::PasswordForm>>
federated_credentials,
const GURL& origin, const GURL& origin,
const base::Callback<void(const autofill::PasswordForm*)>& callback) = 0; const base::Callback<void(const autofill::PasswordForm*)>& callback) = 0;
// Called when user is auto signed in to the site. |local_forms[0]| contains // Called when user is auto signed in to the site. |local_forms[0]| contains
// the credential returned to the site. |origin| is a URL of the site. // the credential returned to the site. |origin| is a URL of the site.
virtual void OnAutoSignin( virtual void OnAutoSignin(
ScopedVector<autofill::PasswordForm> local_forms, std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms,
const GURL& origin) = 0; const GURL& origin) = 0;
// Called when it's the right time to enable autosign-in explicitly. // Called when it's the right time to enable autosign-in explicitly.
......
...@@ -46,11 +46,11 @@ class PasswordsModelDelegate { ...@@ -46,11 +46,11 @@ class PasswordsModelDelegate {
virtual bool IsPasswordOverridden() const = 0; virtual bool IsPasswordOverridden() const = 0;
// Returns current local forms for the current page. // Returns current local forms for the current page.
virtual const std::vector<const autofill::PasswordForm*>& virtual const std::vector<std::unique_ptr<autofill::PasswordForm>>&
GetCurrentForms() const = 0; GetCurrentForms() const = 0;
// Returns possible identity provider's credentials for the current site. // Returns possible identity provider's credentials for the current site.
virtual const std::vector<const autofill::PasswordForm*>& virtual const std::vector<std::unique_ptr<autofill::PasswordForm>>&
GetFederatedForms() const = 0; GetFederatedForms() const = 0;
// For PENDING_PASSWORD_STATE state returns the current statistics for // For PENDING_PASSWORD_STATE state returns the current statistics for
......
...@@ -22,10 +22,12 @@ class PasswordsModelDelegateMock ...@@ -22,10 +22,12 @@ class PasswordsModelDelegateMock
MOCK_CONST_METHOD0(GetState, password_manager::ui::State()); MOCK_CONST_METHOD0(GetState, password_manager::ui::State());
MOCK_CONST_METHOD0(GetPendingPassword, const autofill::PasswordForm&()); MOCK_CONST_METHOD0(GetPendingPassword, const autofill::PasswordForm&());
MOCK_CONST_METHOD0(IsPasswordOverridden, bool()); MOCK_CONST_METHOD0(IsPasswordOverridden, bool());
MOCK_CONST_METHOD0(GetCurrentForms, MOCK_CONST_METHOD0(
const std::vector<const autofill::PasswordForm*>&()); GetCurrentForms,
MOCK_CONST_METHOD0(GetFederatedForms, const std::vector<std::unique_ptr<autofill::PasswordForm>>&());
const std::vector<const autofill::PasswordForm*>&()); MOCK_CONST_METHOD0(
GetFederatedForms,
const std::vector<std::unique_ptr<autofill::PasswordForm>>&());
MOCK_CONST_METHOD0(GetCurrentInteractionStats, MOCK_CONST_METHOD0(GetCurrentInteractionStats,
password_manager::InteractionsStats*()); password_manager::InteractionsStats*());
MOCK_METHOD0(OnBubbleShown, void()); MOCK_METHOD0(OnBubbleShown, void());
......
...@@ -30,12 +30,13 @@ views::Label* GeneratePasswordLabel(const autofill::PasswordForm& form) { ...@@ -30,12 +30,13 @@ views::Label* GeneratePasswordLabel(const autofill::PasswordForm& form) {
} // namespace } // namespace
CredentialsSelectionView::CredentialsSelectionView( CredentialsSelectionView::CredentialsSelectionView(
ManagePasswordsBubbleModel* manage_passwords_bubble_model, ManagePasswordsBubbleModel* manage_passwords_bubble_model)
const std::vector<const autofill::PasswordForm*>& password_forms, : password_forms_(&manage_passwords_bubble_model->local_credentials()),
const base::string16& best_matched_username) default_index_(0),
: password_forms_(password_forms), is_default_best_match_(false),
is_default_preferred_(false),
action_reported_(false) { action_reported_(false) {
DCHECK(!password_forms.empty()); DCHECK(!password_forms_->empty());
// Layout. // Layout.
views::GridLayout* layout = new views::GridLayout(this); views::GridLayout* layout = new views::GridLayout(this);
...@@ -55,8 +56,7 @@ CredentialsSelectionView::CredentialsSelectionView( ...@@ -55,8 +56,7 @@ CredentialsSelectionView::CredentialsSelectionView(
layout->StartRowWithPadding(0, column_set_id, 0, layout->StartRowWithPadding(0, column_set_id, 0,
views::kRelatedControlVerticalSpacing); views::kRelatedControlVerticalSpacing);
combobox_ = GenerateUsernameCombobox( combobox_ = GenerateUsernameCombobox(
manage_passwords_bubble_model->local_credentials().get(), manage_passwords_bubble_model->pending_password().username_value);
best_matched_username);
layout->AddView(combobox_); layout->AddView(combobox_);
views::Label* label = views::Label* label =
GeneratePasswordLabel(manage_passwords_bubble_model->pending_password()); GeneratePasswordLabel(manage_passwords_bubble_model->pending_password());
...@@ -71,24 +71,23 @@ CredentialsSelectionView::~CredentialsSelectionView() { ...@@ -71,24 +71,23 @@ CredentialsSelectionView::~CredentialsSelectionView() {
const autofill::PasswordForm* const autofill::PasswordForm*
CredentialsSelectionView::GetSelectedCredentials() { CredentialsSelectionView::GetSelectedCredentials() {
DCHECK_EQ(password_forms_.size(), DCHECK_EQ(password_forms_->size(),
static_cast<size_t>(combobox_->model()->GetItemCount())); static_cast<size_t>(combobox_->model()->GetItemCount()));
ReportUserActionOnce(false, combobox_->selected_index()); ReportUserActionOnce(false, combobox_->selected_index());
return password_forms_[combobox_->selected_index()]; return &password_forms_->at(combobox_->selected_index());
} }
views::Combobox* CredentialsSelectionView::GenerateUsernameCombobox( views::Combobox* CredentialsSelectionView::GenerateUsernameCombobox(
const std::vector<const autofill::PasswordForm*>& forms,
const base::string16& best_matched_username) { const base::string16& best_matched_username) {
std::vector<base::string16> usernames; std::vector<base::string16> usernames;
size_t best_matched_username_index = forms.size(); size_t best_matched_username_index = password_forms_->size();
size_t preferred_form_index = forms.size(); size_t preferred_form_index = password_forms_->size();
for (size_t index = 0; index < forms.size(); ++index) { for (size_t index = 0; index < password_forms_->size(); ++index) {
usernames.push_back(forms[index]->username_value); usernames.push_back(password_forms_->at(index).username_value);
if (forms[index]->username_value == best_matched_username) { if (password_forms_->at(index).username_value == best_matched_username) {
best_matched_username_index = index; best_matched_username_index = index;
} }
if (forms[index]->preferred) { if (password_forms_->at(index).preferred) {
preferred_form_index = index; preferred_form_index = index;
} }
} }
...@@ -96,15 +95,11 @@ views::Combobox* CredentialsSelectionView::GenerateUsernameCombobox( ...@@ -96,15 +95,11 @@ views::Combobox* CredentialsSelectionView::GenerateUsernameCombobox(
views::Combobox* combobox = views::Combobox* combobox =
new views::Combobox(new ui::SimpleComboboxModel(usernames)); new views::Combobox(new ui::SimpleComboboxModel(usernames));
default_index_ = 0; if (best_matched_username_index < password_forms_->size()) {
is_default_best_match_ = false;
is_default_preferred_ = false;
if (best_matched_username_index < forms.size()) {
is_default_best_match_ = true; is_default_best_match_ = true;
default_index_ = best_matched_username_index; default_index_ = best_matched_username_index;
combobox->SetSelectedIndex(best_matched_username_index); combobox->SetSelectedIndex(best_matched_username_index);
} else if (preferred_form_index < forms.size()) { } else if (preferred_form_index < password_forms_->size()) {
is_default_preferred_ = true; is_default_preferred_ = true;
default_index_ = preferred_form_index; default_index_ = preferred_form_index;
combobox->SetSelectedIndex(preferred_form_index); combobox->SetSelectedIndex(preferred_form_index);
......
...@@ -19,10 +19,8 @@ class ManagePasswordsBubbleModel; ...@@ -19,10 +19,8 @@ class ManagePasswordsBubbleModel;
// A view where the user can select a credential. // A view where the user can select a credential.
class CredentialsSelectionView : public views::View { class CredentialsSelectionView : public views::View {
public: public:
CredentialsSelectionView( explicit CredentialsSelectionView(
ManagePasswordsBubbleModel* manage_passwords_bubble_model, ManagePasswordsBubbleModel* manage_passwords_bubble_model);
const std::vector<const autofill::PasswordForm*>& password_forms,
const base::string16& best_matched_username);
~CredentialsSelectionView() override; ~CredentialsSelectionView() override;
// This methods also reports a user action. // This methods also reports a user action.
...@@ -30,11 +28,10 @@ class CredentialsSelectionView : public views::View { ...@@ -30,11 +28,10 @@ class CredentialsSelectionView : public views::View {
private: private:
views::Combobox* GenerateUsernameCombobox( views::Combobox* GenerateUsernameCombobox(
const std::vector<const autofill::PasswordForm*>& forms,
const base::string16& best_matched_username); const base::string16& best_matched_username);
void ReportUserActionOnce(bool was_update_rejected, int selected_index); void ReportUserActionOnce(bool was_update_rejected, int selected_index);
const std::vector<const autofill::PasswordForm*>& password_forms_; const std::vector<autofill::PasswordForm>* password_forms_;
views::Combobox* combobox_; views::Combobox* combobox_;
int default_index_; int default_index_;
bool is_default_best_match_; bool is_default_best_match_;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <numeric> #include <numeric>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
...@@ -267,23 +268,32 @@ void ManagePasswordItemsView::PasswordFormRow::ResetControls() { ...@@ -267,23 +268,32 @@ void ManagePasswordItemsView::PasswordFormRow::ResetControls() {
// ManagePasswordItemsView // ManagePasswordItemsView
ManagePasswordItemsView::ManagePasswordItemsView( ManagePasswordItemsView::ManagePasswordItemsView(
ManagePasswordsBubbleModel* manage_passwords_bubble_model, ManagePasswordsBubbleModel* manage_passwords_bubble_model,
const std::vector<const autofill::PasswordForm*>& password_forms) const std::vector<autofill::PasswordForm>* password_forms)
: model_(manage_passwords_bubble_model) { : model_(manage_passwords_bubble_model) {
int fixed_height = PasswordFormRow::GetFixedHeight(model_->state()); int fixed_height = PasswordFormRow::GetFixedHeight(model_->state());
for (const autofill::PasswordForm* password_form : password_forms) { for (const auto& password_form : *password_forms) {
if (!password_form->is_public_suffix_match) if (!password_form.is_public_suffix_match)
password_forms_rows_.push_back( password_forms_rows_.push_back(base::MakeUnique<PasswordFormRow>(
new PasswordFormRow(this, password_form, fixed_height)); this, &password_form, fixed_height));
} }
AddRows(); AddRows();
} }
ManagePasswordItemsView::ManagePasswordItemsView(
ManagePasswordsBubbleModel* manage_passwords_bubble_model,
const autofill::PasswordForm* password_form)
: model_(manage_passwords_bubble_model) {
password_forms_rows_.push_back(
base::MakeUnique<PasswordFormRow>(this, password_form, 0));
AddRows();
}
ManagePasswordItemsView::~ManagePasswordItemsView() = default; ManagePasswordItemsView::~ManagePasswordItemsView() = default;
void ManagePasswordItemsView::AddRows() { void ManagePasswordItemsView::AddRows() {
views::GridLayout* layout = new views::GridLayout(this); views::GridLayout* layout = new views::GridLayout(this);
SetLayoutManager(layout); SetLayoutManager(layout);
for (auto* row : password_forms_rows_) { for (const std::unique_ptr<PasswordFormRow>& row : password_forms_rows_) {
if (row != password_forms_rows_[0]) if (row != password_forms_rows_[0])
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
row->AddRow(layout); row->AddRow(layout);
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
#ifndef CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORD_ITEMS_VIEW_H_ #ifndef CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORD_ITEMS_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORD_ITEMS_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORD_ITEMS_VIEW_H_
#include <memory>
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -24,7 +24,10 @@ class ManagePasswordItemsView : public views::View { ...@@ -24,7 +24,10 @@ class ManagePasswordItemsView : public views::View {
public: public:
ManagePasswordItemsView( ManagePasswordItemsView(
ManagePasswordsBubbleModel* manage_passwords_bubble_model, ManagePasswordsBubbleModel* manage_passwords_bubble_model,
const std::vector<const autofill::PasswordForm*>& password_forms); const std::vector<autofill::PasswordForm>* password_forms);
ManagePasswordItemsView(
ManagePasswordsBubbleModel* manage_passwords_bubble_model,
const autofill::PasswordForm* password_form);
private: private:
class PasswordFormRow; class PasswordFormRow;
...@@ -38,7 +41,7 @@ class ManagePasswordItemsView : public views::View { ...@@ -38,7 +41,7 @@ class ManagePasswordItemsView : public views::View {
// Changes the views according to the state of |password_forms_rows_|. // Changes the views according to the state of |password_forms_rows_|.
void Refresh(); void Refresh();
ScopedVector<PasswordFormRow> password_forms_rows_; std::vector<std::unique_ptr<PasswordFormRow>> password_forms_rows_;
ManagePasswordsBubbleModel* model_; ManagePasswordsBubbleModel* model_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordItemsView); DISALLOW_COPY_AND_ASSIGN(ManagePasswordItemsView);
......
...@@ -301,9 +301,8 @@ ManagePasswordsBubbleView::PendingView::PendingView( ...@@ -301,9 +301,8 @@ ManagePasswordsBubbleView::PendingView::PendingView(
// Create the pending credential item, save button and refusal combobox. // Create the pending credential item, save button and refusal combobox.
ManagePasswordItemsView* item = nullptr; ManagePasswordItemsView* item = nullptr;
if (!parent->model()->pending_password().username_value.empty()) { if (!parent->model()->pending_password().username_value.empty()) {
std::vector<const autofill::PasswordForm*> credentials( item = new ManagePasswordItemsView(parent_->model(),
1, &parent->model()->pending_password()); &parent->model()->pending_password());
item = new ManagePasswordItemsView(parent_->model(), credentials);
} }
save_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( save_button_ = views::MdTextButton::CreateSecondaryUiBlueButton(
this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON));
...@@ -412,18 +411,10 @@ ManagePasswordsBubbleView::ManageView::ManageView( ...@@ -412,18 +411,10 @@ ManagePasswordsBubbleView::ManageView::ManageView(
// If we have a list of passwords to store for the current site, display // If we have a list of passwords to store for the current site, display
// them to the user for management. Otherwise, render a "No passwords for // them to the user for management. Otherwise, render a "No passwords for
// this site" message. // this site" message.
bool only_PSL_matches =
find_if(parent_->model()->local_credentials().begin(),
parent_->model()->local_credentials().end(),
[](const autofill::PasswordForm* form) {
return !form->is_public_suffix_match;
}) == parent_->model()->local_credentials().end();
BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET);
if (!only_PSL_matches) { if (!parent_->model()->local_credentials().empty()) {
ManagePasswordItemsView* item = new ManagePasswordItemsView( ManagePasswordItemsView* item = new ManagePasswordItemsView(
parent_->model(), parent_->model()->local_credentials().get()); parent_->model(), &parent_->model()->local_credentials());
layout->StartRowWithPadding(0, SINGLE_VIEW_COLUMN_SET, 0, layout->StartRowWithPadding(0, SINGLE_VIEW_COLUMN_SET, 0,
views::kUnrelatedControlVerticalSpacing); views::kUnrelatedControlVerticalSpacing);
layout->AddView(item); layout->AddView(item);
...@@ -655,14 +646,11 @@ ManagePasswordsBubbleView::UpdatePendingView::UpdatePendingView( ...@@ -655,14 +646,11 @@ ManagePasswordsBubbleView::UpdatePendingView::UpdatePendingView(
// Create the pending credential item, update button. // Create the pending credential item, update button.
View* item = nullptr; View* item = nullptr;
if (parent->model()->ShouldShowMultipleAccountUpdateUI()) { if (parent->model()->ShouldShowMultipleAccountUpdateUI()) {
selection_view_ = new CredentialsSelectionView( selection_view_ = new CredentialsSelectionView(parent->model());
parent->model(), parent->model()->local_credentials().get(),
parent->model()->pending_password().username_value);
item = selection_view_; item = selection_view_;
} else { } else {
std::vector<const autofill::PasswordForm*> forms; item = new ManagePasswordItemsView(parent_->model(),
forms.push_back(&parent->model()->pending_password()); &parent->model()->pending_password());
item = new ManagePasswordItemsView(parent_->model(), forms);
} }
nope_button_ = views::MdTextButton::CreateSecondaryUiButton( nope_button_ = views::MdTextButton::CreateSecondaryUiButton(
this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON)); this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON));
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_samples.h" #include "base/metrics/histogram_samples.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -290,13 +291,14 @@ IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, AutoSignin) { ...@@ -290,13 +291,14 @@ IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, AutoSignin) {
base::FeatureList::SetInstance(std::move(feature_list)); base::FeatureList::SetInstance(std::move(feature_list));
ASSERT_TRUE(base::FeatureList::IsEnabled(features::kCredentialManagementAPI)); ASSERT_TRUE(base::FeatureList::IsEnabled(features::kCredentialManagementAPI));
ScopedVector<autofill::PasswordForm> local_credentials;
test_form()->origin = GURL("https://example.com"); test_form()->origin = GURL("https://example.com");
test_form()->display_name = base::ASCIIToUTF16("Peter"); test_form()->display_name = base::ASCIIToUTF16("Peter");
test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com"); test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com");
GURL icon_url("https://google.com/icon.png"); GURL icon_url("https://google.com/icon.png");
test_form()->icon_url = icon_url; test_form()->icon_url = icon_url;
local_credentials.push_back(new autofill::PasswordForm(*test_form())); std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.push_back(
base::MakeUnique<autofill::PasswordForm>(*test_form()));
// Prepare to capture the network request. // Prepare to capture the network request.
TestURLFetcherCallback url_callback; TestURLFetcherCallback url_callback;
...@@ -322,11 +324,12 @@ IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, AutoSignin) { ...@@ -322,11 +324,12 @@ IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, AutoSignin) {
} }
IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, AutoSigninNoFocus) { IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleViewTest, AutoSigninNoFocus) {
ScopedVector<autofill::PasswordForm> local_credentials;
test_form()->origin = GURL("https://example.com"); test_form()->origin = GURL("https://example.com");
test_form()->display_name = base::ASCIIToUTF16("Peter"); test_form()->display_name = base::ASCIIToUTF16("Peter");
test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com"); test_form()->username_value = base::ASCIIToUTF16("pet12@gmail.com");
local_credentials.push_back(new autofill::PasswordForm(*test_form())); std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials;
local_credentials.push_back(
base::MakeUnique<autofill::PasswordForm>(*test_form()));
// Open another window with focus. // Open another window with focus.
Browser* focused_window = CreateBrowser(browser()->profile()); Browser* focused_window = CreateBrowser(browser()->profile());
......
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