[Passwords] Introduce PasswordManager.FillingAssistance suffixes

This change introduces a histogram suffixes for
PasswordManager.FillingAssistance that detail whether the form was
filled on a secure or insecure origin. This is useful for experiments
that only target a subset of origins, for example the ongoing HTTP
FOAS experiment.

TBR=jdoerrie@chromium.org

(cherry picked from commit 5a39502e15ac0f3dd880590e423461eb72802d2d)

Bug: 918846, 914765
Change-Id: I6ae96701bbbbd2b364e3e52c4f1ec35e163f499f
Reviewed-on: https://chromium-review.googlesource.com/c/1446155
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Dominic Battré <battre@chromium.org>
Reviewed-by: Ilya Sherman <isherman@chromium.org>
Reviewed-by: Vadym Doroshenko <dvadym@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#628062}
Reviewed-on: https://chromium-review.googlesource.com/c/1449576
Reviewed-by: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/branch-heads/3683@{#143}
Cr-Branched-From: e51029943e0a38dd794b73caaf6373d5496ae783-refs/heads/master@{#625896}
diff --git a/components/password_manager/core/browser/password_form_metrics_recorder.cc b/components/password_manager/core/browser/password_form_metrics_recorder.cc
index 360fb3a..0106e0f 100644
--- a/components/password_manager/core/browser/password_form_metrics_recorder.cc
+++ b/components/password_manager/core/browser/password_form_metrics_recorder.cc
@@ -232,6 +232,15 @@
     FillingAssistance filling_assistance = *filling_assistance_;
     UMA_HISTOGRAM_ENUMERATION("PasswordManager.FillingAssistance",
                               filling_assistance);
+
+    if (is_main_frame_secure_) {
+      UMA_HISTOGRAM_ENUMERATION(
+          "PasswordManager.FillingAssistance.SecureOrigin", filling_assistance);
+    } else {
+      UMA_HISTOGRAM_ENUMERATION(
+          "PasswordManager.FillingAssistance.InsecureOrigin",
+          filling_assistance);
+    }
   }
 
   ukm_entry_builder_.Record(ukm::UkmRecorder::Get());
diff --git a/components/password_manager/core/browser/password_form_metrics_recorder_unittest.cc b/components/password_manager/core/browser/password_form_metrics_recorder_unittest.cc
index 8bb5d4c..8571590 100644
--- a/components/password_manager/core/browser/password_form_metrics_recorder_unittest.cc
+++ b/components/password_manager/core/browser/password_form_metrics_recorder_unittest.cc
@@ -752,34 +752,51 @@
 
 void CheckFillingAssistanceTestCase(
     const FillingAssistanceTestCase& test_case) {
-  SCOPED_TRACE(testing::Message("Test description: ")
-               << test_case.description_for_logging);
+  for (bool is_main_frame_secure : {false, true}) {
+    SCOPED_TRACE(testing::Message("Test description: ")
+                 << test_case.description_for_logging
+                 << ", is_main_frame_secure: " << std::boolalpha
+                 << is_main_frame_secure);
 
-  base::test::ScopedTaskEnvironment scoped_task_environment_;
-  base::HistogramTester histogram_tester;
+    base::test::ScopedTaskEnvironment scoped_task_environment_;
+    base::HistogramTester histogram_tester;
 
-  FormData form_data = ConvertToFormData(test_case.fields);
-  std::set<base::string16> saved_usernames =
-      ConvertToString16Set(test_case.saved_usernames);
-  std::set<base::string16> saved_passwords =
-      ConvertToString16Set(test_case.saved_passwords);
+    FormData form_data = ConvertToFormData(test_case.fields);
+    std::set<base::string16> saved_usernames =
+        ConvertToString16Set(test_case.saved_usernames);
+    std::set<base::string16> saved_passwords =
+        ConvertToString16Set(test_case.saved_passwords);
 
-  auto recorder =
-      CreatePasswordFormMetricsRecorder(true /*is_main_frame_secure*/, nullptr);
-  if (test_case.submission_detected)
-    recorder->CalculateFillingAssistanceMetric(form_data, saved_usernames,
-                                               saved_passwords);
+    auto recorder =
+        CreatePasswordFormMetricsRecorder(is_main_frame_secure, nullptr);
+    if (test_case.submission_detected)
+      recorder->CalculateFillingAssistanceMetric(form_data, saved_usernames,
+                                                 saved_passwords);
 
-  if (test_case.submission_is_successful)
-    recorder->LogSubmitPassed();
-  recorder.reset();
+    if (test_case.submission_is_successful)
+      recorder->LogSubmitPassed();
+    recorder.reset();
 
-  int expected_count = test_case.expectation ? 1 : 0;
-  histogram_tester.ExpectTotalCount("PasswordManager.FillingAssistance",
-                                    expected_count);
-  if (test_case.expectation) {
-    histogram_tester.ExpectUniqueSample("PasswordManager.FillingAssistance",
-                                        test_case.expectation.value(), 1);
+    int expected_count = test_case.expectation ? 1 : 0;
+    int expected_insecure_count = !is_main_frame_secure ? expected_count : 0;
+    int expected_secure_count = is_main_frame_secure ? expected_count : 0;
+    histogram_tester.ExpectTotalCount("PasswordManager.FillingAssistance",
+                                      expected_count);
+    histogram_tester.ExpectTotalCount(
+        "PasswordManager.FillingAssistance.InsecureOrigin",
+        expected_insecure_count);
+    histogram_tester.ExpectTotalCount(
+        "PasswordManager.FillingAssistance.SecureOrigin",
+        expected_secure_count);
+    if (test_case.expectation) {
+      histogram_tester.ExpectUniqueSample("PasswordManager.FillingAssistance",
+                                          *test_case.expectation, 1);
+      histogram_tester.ExpectUniqueSample(
+          is_main_frame_secure
+              ? "PasswordManager.FillingAssistance.SecureOrigin"
+              : "PasswordManager.FillingAssistance.InsecureOrigin",
+          *test_case.expectation, 1);
+    }
   }
 }
 
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 3a3d352..4b5c863 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -139405,6 +139405,14 @@
   <affected-histogram name="PasswordManager.TotalAccountsHiRes.WithScheme"/>
 </histogram_suffixes>
 
+<histogram_suffixes name="PasswordSecurityOrigin" separator=".">
+  <suffix name="InsecureOrigin"
+      label="The recording took place on an insecure origin."/>
+  <suffix name="SecureOrigin"
+      label="The recording took place on a secure origin."/>
+  <affected-histogram name="PasswordManager.FillingAssistance"/>
+</histogram_suffixes>
+
 <histogram_suffixes name="PaymentRequestOutcome" separator=".">
   <suffix name="Completed" label="The Payment Request was completed"/>
   <suffix name="OtherAborted"