Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Unified Diff: components/password_manager/core/browser/credential_manager_pending_request_task.cc

Issue 2110993003: Filter out empty usernames while handling get() in the Credential Manager API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/password_manager/content/browser/credential_manager_impl_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/password_manager/core/browser/credential_manager_pending_request_task.cc
diff --git a/components/password_manager/core/browser/credential_manager_pending_request_task.cc b/components/password_manager/core/browser/credential_manager_pending_request_task.cc
index 26fb40ecd68e119ba209c1419c7bffb23f2ea8b3..dc995b0ad2a013c860242e2081edc6c6166207f9 100644
--- a/components/password_manager/core/browser/credential_manager_pending_request_task.cc
+++ b/components/password_manager/core/browser/credential_manager_pending_request_task.cc
@@ -23,18 +23,18 @@ namespace {
// Send a UMA histogram about if |local_results| has empty or duplicate
// usernames.
void ReportAccountChooserMetrics(
- const ScopedVector<autofill::PasswordForm>& local_results) {
+ const ScopedVector<autofill::PasswordForm>& local_results,
+ bool had_empty_username) {
std::vector<base::string16> usernames;
for (const auto& form : local_results)
usernames.push_back(form->username_value);
std::sort(usernames.begin(), usernames.end());
- bool has_empty_username = !usernames.empty() && usernames[0].empty();
bool has_duplicates =
std::adjacent_find(usernames.begin(), usernames.end()) != usernames.end();
metrics_util::AccountChooserUsabilityMetric metric;
- if (has_empty_username && has_duplicates)
+ if (had_empty_username && has_duplicates)
metric = metrics_util::ACCOUNT_CHOOSER_EMPTY_USERNAME_AND_DUPLICATES;
- else if (has_empty_username)
+ else if (had_empty_username)
metric = metrics_util::ACCOUNT_CHOOSER_EMPTY_USERNAME;
else if (has_duplicates)
metric = metrics_util::ACCOUNT_CHOOSER_DUPLICATES;
@@ -115,6 +115,14 @@ void CredentialManagerPendingRequestTask::OnGetPasswordStoreResults(
affiliated_results.weak_clear();
}
+ // Remove empty usernames from the list.
+ auto begin_empty = std::partition(local_results.begin(), local_results.end(),
+ [](autofill::PasswordForm* form) {
+ return !form->username_value.empty();
+ });
+ const bool has_empty_username = (begin_empty != local_results.end());
+ local_results.erase(begin_empty, local_results.end());
+
if ((local_results.empty() && federated_results.empty())) {
delegate_->SendCredential(send_callback_, CredentialInfo());
return;
@@ -147,7 +155,7 @@ void CredentialManagerPendingRequestTask::OnGetPasswordStoreResults(
std::unique_ptr<autofill::PasswordForm> potential_autosignin_form(
new autofill::PasswordForm(*local_results[0]));
if (!zero_click_only_)
- ReportAccountChooserMetrics(local_results);
+ ReportAccountChooserMetrics(local_results, has_empty_username);
if (zero_click_only_ ||
!delegate_->client()->PromptUserToChooseCredentials(
std::move(local_results), std::move(federated_results), origin_,
« no previous file with comments | « components/password_manager/content/browser/credential_manager_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698