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

Unified Diff: components/autofill/core/browser/autofill_metrics.cc

Issue 2740633002: [Autofill] Add upstreaming UKM (Closed)
Patch Set: Fixed comments Created 3 years, 9 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
Index: components/autofill/core/browser/autofill_metrics.cc
diff --git a/components/autofill/core/browser/autofill_metrics.cc b/components/autofill/core/browser/autofill_metrics.cc
index 3300b672d536b6c2c3499ee8fe1a85f357048294..239334c5e660612da4f9da3d85384c3f663ff38e 100644
--- a/components/autofill/core/browser/autofill_metrics.cc
+++ b/components/autofill/core/browser/autofill_metrics.cc
@@ -11,9 +11,16 @@
#include "base/metrics/sparse_histogram.h"
#include "base/metrics/user_metrics.h"
#include "base/time/time.h"
+#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/form_structure.h"
#include "components/autofill/core/common/form_data.h"
+#include "components/ukm/ukm_entry_builder.h"
+
+namespace internal {
+const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision";
+const char kUKMCardUploadDecisionMetricName[] = "UploadDecision";
+} // namespace internal
namespace autofill {
@@ -689,6 +696,43 @@ void AutofillMetrics::LogShowedHttpNotSecureExplanation() {
base::UserMetricsAction("Autofill_ShowedHttpNotSecureExplanation"));
}
+// static
+void AutofillMetrics::LogCardUploadDecisionUkm(
+ ukm::UkmService* ukm_service,
+ const GURL& url,
+ AutofillMetrics::CardUploadDecisionMetric upload_decision) {
+ if (upload_decision >= AutofillMetrics::NUM_CARD_UPLOAD_DECISION_METRICS)
+ return;
+
+ // Set up as a map because the follow-up CL will add more metrics.
+ std::map<std::string, int> metrics = {
+ {internal::kUKMCardUploadDecisionMetricName,
+ static_cast<int>(upload_decision)}};
+ LogUkm(ukm_service, url, internal::kUKMCardUploadDecisionEntryName, metrics);
+}
+
+// static
+bool AutofillMetrics::LogUkm(ukm::UkmService* ukm_service,
+ const GURL& url,
+ const std::string& ukm_entry_name,
+ const std::map<std::string, int>& metrics) {
+ if (!IsUkmLoggingEnabled() || !ukm_service || !url.is_valid() ||
+ metrics.empty()) {
+ return false;
+ }
+
+ int32_t source_id = ukm_service->GetNewSourceID();
+ ukm_service->UpdateSourceURL(source_id, url);
+ std::unique_ptr<ukm::UkmEntryBuilder> builder =
+ ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str());
+
+ for (auto it = metrics.begin(); it != metrics.end(); ++it) {
+ builder->AddMetric(it->first.c_str(), it->second);
+ }
+
+ return true;
+}
+
AutofillMetrics::FormEventLogger::FormEventLogger(bool is_for_credit_card)
: is_for_credit_card_(is_for_credit_card),
is_server_data_available_(false),
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.h ('k') | components/autofill/core/browser/autofill_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698