Commit 2eda92c4 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Support moving multiple password in PasswordsPrivateDelegate

This is preparation for adding the functionality of moving multiple
passwords from settings view.

Mocks are in the linked bug.

Bug: 1139263
Change-Id: Ib173b0625f2ee82542164b703c97a53cee997030
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2480162Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819410}
parent a5fbc9db
...@@ -194,7 +194,7 @@ ResponseAction PasswordsPrivateMovePasswordToAccountFunction::Run() { ...@@ -194,7 +194,7 @@ ResponseAction PasswordsPrivateMovePasswordToAccountFunction::Run() {
api::passwords_private::MovePasswordToAccount::Params::Create(*args_); api::passwords_private::MovePasswordToAccount::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(parameters); EXTENSION_FUNCTION_VALIDATE(parameters);
GetDelegate(browser_context()) GetDelegate(browser_context())
->MovePasswordToAccount(parameters->id, GetSenderWebContents()); ->MovePasswordToAccount({parameters->id}, GetSenderWebContents());
return RespondNow(NoArguments()); return RespondNow(NoArguments());
} }
......
...@@ -102,7 +102,7 @@ class PasswordsPrivateApiTest : public ExtensionApiTest { ...@@ -102,7 +102,7 @@ class PasswordsPrivateApiTest : public ExtensionApiTest {
s_test_delegate_->AddCompromisedCredential(id); s_test_delegate_->AddCompromisedCredential(id);
} }
base::Optional<int> last_moved_password() const { const std::vector<int>& last_moved_password() const {
return s_test_delegate_->last_moved_password(); return s_test_delegate_->last_moved_password();
} }
...@@ -300,9 +300,9 @@ IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetPasswordCheckStatus) { ...@@ -300,9 +300,9 @@ IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetPasswordCheckStatus) {
} }
IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, MovePasswordToAccount) { IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, MovePasswordToAccount) {
EXPECT_FALSE(last_moved_password().has_value()); EXPECT_TRUE(last_moved_password().empty());
EXPECT_TRUE(RunPasswordsSubtest("movePasswordToAccount")) << message_; EXPECT_TRUE(RunPasswordsSubtest("movePasswordToAccount")) << message_;
EXPECT_EQ(42, last_moved_password()); EXPECT_EQ(42, last_moved_password()[0]);
} }
} // namespace extensions } // namespace extensions
...@@ -89,12 +89,12 @@ class PasswordsPrivateDelegate : public KeyedService { ...@@ -89,12 +89,12 @@ class PasswordsPrivateDelegate : public KeyedService {
PlaintextPasswordCallback callback, PlaintextPasswordCallback callback,
content::WebContents* web_contents) = 0; content::WebContents* web_contents) = 0;
// Moves a password currently stored on the device to being stored in the // Moves a list of passwords currently stored on the device to being stored in
// signed-in, non-syncing Google Account. The result is a no-op if any of // the signed-in, non-syncing Google Account. The result of any password is a
// these is true: |id| is invalid; |id| corresponds to a password already // no-op if any of these is true: |id| is invalid; |id| corresponds to a
// stored in the account; or the user is not using the account-scoped password // password already stored in the account; or the user is not using the
// storage. // account-scoped password storage.
virtual void MovePasswordToAccount(int id, virtual void MovePasswordToAccount(const std::vector<int>& ids,
content::WebContents* web_contents) = 0; content::WebContents* web_contents) = 0;
// Trigger the password import procedure, allowing the user to select a file // Trigger the password import procedure, allowing the user to select a file
......
...@@ -430,13 +430,16 @@ void PasswordsPrivateDelegateImpl::SetPasswordExceptionList( ...@@ -430,13 +430,16 @@ void PasswordsPrivateDelegateImpl::SetPasswordExceptionList(
} }
void PasswordsPrivateDelegateImpl::MovePasswordToAccount( void PasswordsPrivateDelegateImpl::MovePasswordToAccount(
int id, const std::vector<int>& ids,
content::WebContents* web_contents) { content::WebContents* web_contents) {
auto* client = ChromePasswordManagerClient::FromWebContents(web_contents); auto* client = ChromePasswordManagerClient::FromWebContents(web_contents);
DCHECK(client); DCHECK(client);
if (const std::string* sort_key = password_id_generator_.TryGetKey(id)) std::vector<std::string> sort_keys;
password_manager_presenter_->MovePasswordToAccountStore({*sort_key}, for (int id : ids) {
client); if (const std::string* sort_key = password_id_generator_.TryGetKey(id))
sort_keys.push_back(*sort_key);
}
password_manager_presenter_->MovePasswordToAccountStore(sort_keys, client);
} }
void PasswordsPrivateDelegateImpl::ImportPasswords( void PasswordsPrivateDelegateImpl::ImportPasswords(
......
...@@ -60,7 +60,7 @@ class PasswordsPrivateDelegateImpl : public PasswordsPrivateDelegate, ...@@ -60,7 +60,7 @@ class PasswordsPrivateDelegateImpl : public PasswordsPrivateDelegate,
api::passwords_private::PlaintextReason reason, api::passwords_private::PlaintextReason reason,
PlaintextPasswordCallback callback, PlaintextPasswordCallback callback,
content::WebContents* web_contents) override; content::WebContents* web_contents) override;
void MovePasswordToAccount(int id, void MovePasswordToAccount(const std::vector<int>& ids,
content::WebContents* web_contents) override; content::WebContents* web_contents) override;
void ImportPasswords(content::WebContents* web_contents) override; void ImportPasswords(content::WebContents* web_contents) override;
void ExportPasswords(base::OnceCallback<void(const std::string&)> accepted, void ExportPasswords(base::OnceCallback<void(const std::string&)> accepted,
......
...@@ -136,9 +136,9 @@ void TestPasswordsPrivateDelegate::RequestPlaintextPassword( ...@@ -136,9 +136,9 @@ void TestPasswordsPrivateDelegate::RequestPlaintextPassword(
} }
void TestPasswordsPrivateDelegate::MovePasswordToAccount( void TestPasswordsPrivateDelegate::MovePasswordToAccount(
int id, const std::vector<int>& ids,
content::WebContents* web_contents) { content::WebContents* web_contents) {
last_moved_password_ = id; last_moved_password_ = ids;
} }
void TestPasswordsPrivateDelegate::ImportPasswords( void TestPasswordsPrivateDelegate::ImportPasswords(
......
...@@ -37,7 +37,7 @@ class TestPasswordsPrivateDelegate : public PasswordsPrivateDelegate { ...@@ -37,7 +37,7 @@ class TestPasswordsPrivateDelegate : public PasswordsPrivateDelegate {
api::passwords_private::PlaintextReason reason, api::passwords_private::PlaintextReason reason,
PlaintextPasswordCallback callback, PlaintextPasswordCallback callback,
content::WebContents* web_contents) override; content::WebContents* web_contents) override;
void MovePasswordToAccount(int id, void MovePasswordToAccount(const std::vector<int>& ids,
content::WebContents* web_contents) override; content::WebContents* web_contents) override;
void ImportPasswords(content::WebContents* web_contents) override; void ImportPasswords(content::WebContents* web_contents) override;
void ExportPasswords(base::OnceCallback<void(const std::string&)> callback, void ExportPasswords(base::OnceCallback<void(const std::string&)> callback,
...@@ -92,7 +92,7 @@ class TestPasswordsPrivateDelegate : public PasswordsPrivateDelegate { ...@@ -92,7 +92,7 @@ class TestPasswordsPrivateDelegate : public PasswordsPrivateDelegate {
start_password_check_state_ = state; start_password_check_state_ = state;
} }
base::Optional<int> last_moved_password() const { const std::vector<int>& last_moved_password() const {
return last_moved_password_; return last_moved_password_;
} }
...@@ -135,7 +135,7 @@ class TestPasswordsPrivateDelegate : public PasswordsPrivateDelegate { ...@@ -135,7 +135,7 @@ class TestPasswordsPrivateDelegate : public PasswordsPrivateDelegate {
password_manager::BulkLeakCheckService::State::kRunning; password_manager::BulkLeakCheckService::State::kRunning;
// Records the id of the last password that was moved. // Records the id of the last password that was moved.
base::Optional<int> last_moved_password_ = base::nullopt; std::vector<int> last_moved_password_;
}; };
} // namespace extensions } // namespace extensions
......
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