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() {
api::passwords_private::MovePasswordToAccount::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(parameters);
GetDelegate(browser_context())
->MovePasswordToAccount(parameters->id, GetSenderWebContents());
->MovePasswordToAccount({parameters->id}, GetSenderWebContents());
return RespondNow(NoArguments());
}
......
......@@ -102,7 +102,7 @@ class PasswordsPrivateApiTest : public ExtensionApiTest {
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();
}
......@@ -300,9 +300,9 @@ IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetPasswordCheckStatus) {
}
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_EQ(42, last_moved_password());
EXPECT_EQ(42, last_moved_password()[0]);
}
} // namespace extensions
......@@ -89,12 +89,12 @@ class PasswordsPrivateDelegate : public KeyedService {
PlaintextPasswordCallback callback,
content::WebContents* web_contents) = 0;
// Moves a password currently stored on the device to being stored in the
// signed-in, non-syncing Google Account. The result is a no-op if any of
// these is true: |id| is invalid; |id| corresponds to a password already
// stored in the account; or the user is not using the account-scoped password
// storage.
virtual void MovePasswordToAccount(int id,
// Moves a list of passwords currently stored on the device to being stored in
// the signed-in, non-syncing Google Account. The result of any password is a
// no-op if any of these is true: |id| is invalid; |id| corresponds to a
// password already stored in the account; or the user is not using the
// account-scoped password storage.
virtual void MovePasswordToAccount(const std::vector<int>& ids,
content::WebContents* web_contents) = 0;
// Trigger the password import procedure, allowing the user to select a file
......
......@@ -430,13 +430,16 @@ void PasswordsPrivateDelegateImpl::SetPasswordExceptionList(
}
void PasswordsPrivateDelegateImpl::MovePasswordToAccount(
int id,
const std::vector<int>& ids,
content::WebContents* web_contents) {
auto* client = ChromePasswordManagerClient::FromWebContents(web_contents);
DCHECK(client);
if (const std::string* sort_key = password_id_generator_.TryGetKey(id))
password_manager_presenter_->MovePasswordToAccountStore({*sort_key},
client);
std::vector<std::string> sort_keys;
for (int id : ids) {
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(
......
......@@ -60,7 +60,7 @@ class PasswordsPrivateDelegateImpl : public PasswordsPrivateDelegate,
api::passwords_private::PlaintextReason reason,
PlaintextPasswordCallback callback,
content::WebContents* web_contents) override;
void MovePasswordToAccount(int id,
void MovePasswordToAccount(const std::vector<int>& ids,
content::WebContents* web_contents) override;
void ImportPasswords(content::WebContents* web_contents) override;
void ExportPasswords(base::OnceCallback<void(const std::string&)> accepted,
......
......@@ -136,9 +136,9 @@ void TestPasswordsPrivateDelegate::RequestPlaintextPassword(
}
void TestPasswordsPrivateDelegate::MovePasswordToAccount(
int id,
const std::vector<int>& ids,
content::WebContents* web_contents) {
last_moved_password_ = id;
last_moved_password_ = ids;
}
void TestPasswordsPrivateDelegate::ImportPasswords(
......
......@@ -37,7 +37,7 @@ class TestPasswordsPrivateDelegate : public PasswordsPrivateDelegate {
api::passwords_private::PlaintextReason reason,
PlaintextPasswordCallback callback,
content::WebContents* web_contents) override;
void MovePasswordToAccount(int id,
void MovePasswordToAccount(const std::vector<int>& ids,
content::WebContents* web_contents) override;
void ImportPasswords(content::WebContents* web_contents) override;
void ExportPasswords(base::OnceCallback<void(const std::string&)> callback,
......@@ -92,7 +92,7 @@ class TestPasswordsPrivateDelegate : public PasswordsPrivateDelegate {
start_password_check_state_ = state;
}
base::Optional<int> last_moved_password() const {
const std::vector<int>& last_moved_password() const {
return last_moved_password_;
}
......@@ -135,7 +135,7 @@ class TestPasswordsPrivateDelegate : public PasswordsPrivateDelegate {
password_manager::BulkLeakCheckService::State::kRunning;
// 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
......
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