Commit e8dd4b2d authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[PwdCheckAndroid] Remove sorting from PasswordCheckManager

The sorting be handled entirely on the Java side, in
PasswordCheckMediator.

Bug: 1102025, 1092444
Change-Id: I8cee5bb162900387d7de21b6ab9201a845f6287b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2367056
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800104}
parent 45c667fc
......@@ -41,29 +41,6 @@ std::string CreateChangeUrl(const GURL& url) {
return url.GetOrigin().spec();
}
// Orders |compromised_credentials| in such a way that phished credentials
// precede leaked credentials, and that credentials of the same compromise type
// are ordered by recency.
// TODO(crbug.com/1117579): Share the common logic with desktop.
void OrderCompromisedCredentials(
std::vector<password_manager::CredentialWithPassword>& credentials) {
// Reordering phished credential to the beginning.
auto last_phished = std::partition(
credentials.begin(), credentials.end(), [](const auto& credential) {
return credential.compromise_type !=
password_manager::CompromiseTypeFlags::kCredentialLeaked;
});
// By construction the phished credentials precede the leaked credentials in
// |credentials|. Now sort both groups by their creation date so that most
// recent compromises appear first in both lists.
auto create_time_cmp = [](const auto& lhs, const auto& rhs) {
return lhs.create_time > rhs.create_time;
};
std::sort(credentials.begin(), last_phished, create_time_cmp);
std::sort(last_phished, credentials.end(), create_time_cmp);
}
} // namespace
using autofill::PasswordForm;
......@@ -142,7 +119,6 @@ std::vector<CompromisedCredentialForUI>
PasswordCheckManager::GetCompromisedCredentials() const {
std::vector<CredentialWithPassword> credentials =
compromised_credentials_manager_.GetCompromisedCredentials();
OrderCompromisedCredentials(credentials);
std::vector<CompromisedCredentialForUI> ui_credentials;
ui_credentials.reserve(credentials.size());
for (const auto& credential : credentials) {
......
......@@ -59,7 +59,6 @@ using State = password_manager::BulkLeakCheckService::State;
namespace {
constexpr char kExampleCom[] = "https://example.com";
constexpr char kExampleOrg[] = "http://www.example.org";
constexpr char kExampleApp[] = "com.example.app";
constexpr char kUsername1[] = "alice";
......@@ -391,48 +390,3 @@ TEST_F(PasswordCheckManagerTest,
base::nullopt, "https://example.com/",
CompromiseTypeFlags::kCredentialLeaked, /*has_script=*/true)));
}
TEST_F(PasswordCheckManagerTest, GetCompromisedCredentialsOrder) {
InitializeManager();
store().AddLogin(MakeSavedPassword(kExampleCom, kUsername1));
store().AddLogin(MakeSavedPassword(kExampleCom, kUsername2));
store().AddLogin(MakeSavedPassword(kExampleOrg, kUsername1));
store().AddLogin(MakeSavedPassword(kExampleOrg, kUsername2));
store().AddCompromisedCredentials(
MakeCompromised(kExampleCom, kUsername1, base::TimeDelta::FromMinutes(1),
CompromiseType::kLeaked));
store().AddCompromisedCredentials(
MakeCompromised(kExampleCom, kUsername2, base::TimeDelta::FromMinutes(5),
CompromiseType::kLeaked));
store().AddCompromisedCredentials(
MakeCompromised(kExampleCom, kUsername2, base::TimeDelta::FromMinutes(3),
CompromiseType::kPhished));
store().AddCompromisedCredentials(
MakeCompromised(kExampleOrg, kUsername2, base::TimeDelta::FromMinutes(4),
CompromiseType::kLeaked));
store().AddCompromisedCredentials(
MakeCompromised(kExampleOrg, kUsername1, base::TimeDelta::FromMinutes(2),
CompromiseType::kPhished));
RunUntilIdle();
EXPECT_THAT(
manager().GetCompromisedCredentials(),
ElementsAre(
ExpectCompromisedCredentialForUI(
base::ASCIIToUTF16(kUsername1), base::ASCIIToUTF16("example.org"),
base::nullopt, "http://www.example.org/",
CompromiseTypeFlags::kCredentialPhished, /*has_script_=*/false),
ExpectCompromisedCredentialForUI(
base::ASCIIToUTF16(kUsername2), base::ASCIIToUTF16("example.com"),
base::nullopt, "https://example.com/",
password_manager::CompromiseTypeFlags::kCredentialLeaked |
password_manager::CompromiseTypeFlags::kCredentialPhished,
/*has_script_=*/false),
ExpectCompromisedCredentialForUI(
base::ASCIIToUTF16(kUsername1), base::ASCIIToUTF16("example.com"),
base::nullopt, "https://example.com/",
CompromiseTypeFlags::kCredentialLeaked, /*has_script_=*/false),
ExpectCompromisedCredentialForUI(
base::ASCIIToUTF16(kUsername2), base::ASCIIToUTF16("example.org"),
base::nullopt, "http://www.example.org/",
CompromiseTypeFlags::kCredentialLeaked, /*has_script_=*/false)));
}
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