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