Commit 4faf26ae authored by Oscar Johansson's avatar Oscar Johansson Committed by Commit Bot

Move function to util (components/password_manager/)

When building using jumbo, files gets merged and
functions with the same name may end up in the same
namespace/scope and conflict. This happens for the
function UpdateMetadataForUsage.

This commit solves the issue by moving the function
to a shared util file.

Bug: 869381
Change-Id: I57b8f9c96c785a3bbfc8250f0edbe7690c3b3ff7
Reviewed-on: https://chromium-review.googlesource.com/1160482
Commit-Queue: Oscar Johansson <oscarj@opera.com>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580514}
parent fe1b2e05
......@@ -60,14 +60,6 @@ ValueElementPair PasswordToSave(const PasswordForm& form) {
return {form.new_password_value, form.new_password_element};
}
// Update |credential| to reflect usage.
void UpdateMetadataForUsage(PasswordForm* credential) {
++credential->times_used;
// Remove alternate usernames. At this point we assume that we have found
// the right username.
credential->other_possible_usernames.clear();
}
// Copies field properties masks from the form |from| to the form |to|.
void CopyFieldPropertiesMasks(const FormData& from, FormData* to) {
......@@ -363,7 +355,7 @@ void NewPasswordFormManager::CreatePendingCredentials() {
// If this isn't updated, then password generation uploads are off for
// sites where PSL matching is required to fill the login form, as two
// PASSWORD votes are uploaded per saved password instead of one.
UpdateMetadataForUsage(&pending_credentials_);
password_manager_util::UpdateMetadataForUsage(&pending_credentials_);
// Update |pending_credentials_| in order to be able correctly save it.
pending_credentials_.origin = submitted_form_.origin;
......
......@@ -63,15 +63,6 @@ bool IsProbablyNotUsername(const base::string16& s) {
return !s.empty() && DoesStringContainOnlyDigits(s) && s.size() < 3;
}
// Update |credential| to reflect usage.
void UpdateMetadataForUsage(PasswordForm* credential) {
++credential->times_used;
// Remove alternate usernames. At this point we assume that we have found
// the right username.
credential->other_possible_usernames.clear();
}
// Returns true iff |best_matches| contain a preferred credential with a
// username other than |preferred_username|.
bool DidPreferenceChange(
......@@ -599,7 +590,7 @@ void PasswordFormManager::ProcessUpdate() {
DCHECK(!IsNewLogin() && pending_credentials_.preferred);
DCHECK(!client_->IsIncognito());
UpdateMetadataForUsage(&pending_credentials_);
password_manager_util::UpdateMetadataForUsage(&pending_credentials_);
base::RecordAction(
base::UserMetricsAction("PasswordManager_LoginFollowingAutofill"));
......@@ -643,7 +634,7 @@ void PasswordFormManager::CreatePendingCredentials() {
// If this isn't updated, then password generation uploads are off for
// sites where PSL matching is required to fill the login form, as two
// PASSWORD votes are uploaded per saved password instead of one.
UpdateMetadataForUsage(&pending_credentials_);
password_manager_util::UpdateMetadataForUsage(&pending_credentials_);
// Update |pending_credentials_| in order to be able correctly save it.
pending_credentials_.origin = submitted_form_->origin;
......
......@@ -40,7 +40,7 @@ class BlacklistedCredentialsCleaner
~BlacklistedCredentialsCleaner() override = default;
void OnGetPasswordStoreResults(
std::vector<std::unique_ptr<autofill::PasswordForm>> results) override {
std::vector<std::unique_ptr<PasswordForm>> results) override {
bool need_to_clean = !prefs_->GetBoolean(
password_manager::prefs::kBlacklistedCredentialsStripped);
UMA_HISTOGRAM_BOOLEAN("PasswordManager.BlacklistedSites.NeedToBeCleaned",
......@@ -55,7 +55,7 @@ class BlacklistedCredentialsCleaner
// TODO(https://crbug.com/817754): remove the code once majority of the users
// executed it.
void RemoveUsernameAndPassword(
const std::vector<std::unique_ptr<autofill::PasswordForm>>& results) {
const std::vector<std::unique_ptr<PasswordForm>>& results) {
bool cleaned_something = false;
for (const auto& form : results) {
DCHECK(form->blacklisted_by_user);
......@@ -77,7 +77,7 @@ class BlacklistedCredentialsCleaner
}
void RemoveDuplicates(
const std::vector<std::unique_ptr<autofill::PasswordForm>>& results) {
const std::vector<std::unique_ptr<PasswordForm>>& results) {
std::set<std::string> signon_realms;
for (const auto& form : results) {
DCHECK(form->blacklisted_by_user);
......@@ -112,6 +112,15 @@ bool IsBetterMatch(const PasswordForm* lhs, const PasswordForm* rhs) {
} // namespace
// Update |credential| to reflect usage.
void UpdateMetadataForUsage(PasswordForm* credential) {
++credential->times_used;
// Remove alternate usernames. At this point we assume that we have found
// the right username.
credential->other_possible_usernames.clear();
}
password_manager::SyncState GetPasswordSyncState(
const syncer::SyncService* sync_service) {
if (sync_service && sync_service->IsFirstSetupComplete() &&
......@@ -138,10 +147,9 @@ password_manager::SyncState GetHistorySyncState(
return password_manager::NOT_SYNCING;
}
void FindDuplicates(
std::vector<std::unique_ptr<autofill::PasswordForm>>* forms,
std::vector<std::unique_ptr<autofill::PasswordForm>>* duplicates,
std::vector<std::vector<autofill::PasswordForm*>>* tag_groups) {
void FindDuplicates(std::vector<std::unique_ptr<PasswordForm>>* forms,
std::vector<std::unique_ptr<PasswordForm>>* duplicates,
std::vector<std::vector<PasswordForm*>>* tag_groups) {
if (forms->empty())
return;
......@@ -149,11 +157,11 @@ void FindDuplicates(
// duplicates. Therefore, the caller should try to preserve it.
std::stable_sort(forms->begin(), forms->end(), autofill::LessThanUniqueKey());
std::vector<std::unique_ptr<autofill::PasswordForm>> unique_forms;
std::vector<std::unique_ptr<PasswordForm>> unique_forms;
unique_forms.push_back(std::move(forms->front()));
if (tag_groups) {
tag_groups->clear();
tag_groups->push_back(std::vector<autofill::PasswordForm*>());
tag_groups->push_back(std::vector<PasswordForm*>());
tag_groups->front().push_back(unique_forms.front().get());
}
for (auto it = forms->begin() + 1; it != forms->end(); ++it) {
......@@ -163,8 +171,7 @@ void FindDuplicates(
duplicates->push_back(std::move(*it));
} else {
if (tag_groups)
tag_groups->push_back(
std::vector<autofill::PasswordForm*>(1, it->get()));
tag_groups->push_back(std::vector<PasswordForm*>(1, it->get()));
unique_forms.push_back(std::move(*it));
}
}
......@@ -172,22 +179,20 @@ void FindDuplicates(
}
void TrimUsernameOnlyCredentials(
std::vector<std::unique_ptr<autofill::PasswordForm>>* android_credentials) {
std::vector<std::unique_ptr<PasswordForm>>* android_credentials) {
// Remove username-only credentials which are not federated.
base::EraseIf(*android_credentials,
[](const std::unique_ptr<autofill::PasswordForm>& form) {
return form->scheme ==
autofill::PasswordForm::SCHEME_USERNAME_ONLY &&
[](const std::unique_ptr<PasswordForm>& form) {
return form->scheme == PasswordForm::SCHEME_USERNAME_ONLY &&
form->federation_origin.unique();
});
// Set "skip_zero_click" on federated credentials.
std::for_each(
android_credentials->begin(), android_credentials->end(),
[](const std::unique_ptr<autofill::PasswordForm>& form) {
if (form->scheme == autofill::PasswordForm::SCHEME_USERNAME_ONLY)
form->skip_zero_click = true;
});
std::for_each(android_credentials->begin(), android_credentials->end(),
[](const std::unique_ptr<PasswordForm>& form) {
if (form->scheme == PasswordForm::SCHEME_USERNAME_ONLY)
form->skip_zero_click = true;
});
}
bool IsLoggingActive(const password_manager::PasswordManagerClient* client) {
......
......@@ -32,6 +32,9 @@ class PrefService;
namespace password_manager_util {
// Update |credential| to reflect usage.
void UpdateMetadataForUsage(autofill::PasswordForm* credential);
// Reports whether and how passwords are currently synced. In particular, for a
// null |sync_service| returns NOT_SYNCING.
password_manager::SyncState GetPasswordSyncState(
......
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