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: Vadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580514}
diff --git a/components/password_manager/core/browser/new_password_form_manager.cc b/components/password_manager/core/browser/new_password_form_manager.cc
index 3ddaf1f..410250f 100644
--- a/components/password_manager/core/browser/new_password_form_manager.cc
+++ b/components/password_manager/core/browser/new_password_form_manager.cc
@@ -60,14 +60,6 @@
   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 @@
       // 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;
diff --git a/components/password_manager/core/browser/password_form_manager.cc b/components/password_manager/core/browser/password_form_manager.cc
index 1f556f02..32bb274b2 100644
--- a/components/password_manager/core/browser/password_form_manager.cc
+++ b/components/password_manager/core/browser/password_form_manager.cc
@@ -63,15 +63,6 @@
   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 @@
   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 @@
       // 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;
diff --git a/components/password_manager/core/browser/password_manager_util.cc b/components/password_manager/core/browser/password_manager_util.cc
index 7a3ef7719..0413115c 100644
--- a/components/password_manager/core/browser/password_manager_util.cc
+++ b/components/password_manager/core/browser/password_manager_util.cc
@@ -40,7 +40,7 @@
   ~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 @@
   // 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 @@
   }
 
   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 @@
 
 }  // 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 @@
   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 @@
   // 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 @@
       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 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) {
diff --git a/components/password_manager/core/browser/password_manager_util.h b/components/password_manager/core/browser/password_manager_util.h
index cfe81f4..9363a20 100644
--- a/components/password_manager/core/browser/password_manager_util.h
+++ b/components/password_manager/core/browser/password_manager_util.h
@@ -32,6 +32,9 @@
 
 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(