| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/autofill_metrics.h" | 5 #include "components/autofill/core/browser/autofill_metrics.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
| 12 #include "base/metrics/user_metrics.h" | 12 #include "base/metrics/user_metrics.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "components/autofill/core/browser/autofill_experiments.h" | 14 #include "components/autofill/core/browser/autofill_experiments.h" |
| 15 #include "components/autofill/core/browser/autofill_type.h" | 15 #include "components/autofill/core/browser/autofill_type.h" |
| 16 #include "components/autofill/core/browser/form_structure.h" | 16 #include "components/autofill/core/browser/form_structure.h" |
| 17 #include "components/autofill/core/common/form_data.h" | 17 #include "components/autofill/core/common/form_data.h" |
| 18 #include "components/ukm/ukm_entry_builder.h" | 18 #include "components/ukm/ukm_entry_builder.h" |
| 19 | 19 |
| 20 namespace internal { | 20 namespace internal { |
| 21 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision"; | 21 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision"; |
| 22 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision"; | 22 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision"; |
| 23 const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement"; |
| 24 const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement"; |
| 23 } // namespace internal | 25 } // namespace internal |
| 24 | 26 |
| 25 namespace autofill { | 27 namespace autofill { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 // Note: if adding an enum value here, update the corresponding description for | 31 // Note: if adding an enum value here, update the corresponding description for |
| 30 // AutofillTypeQualityByFieldType in histograms.xml. | 32 // AutofillTypeQualityByFieldType in histograms.xml. |
| 31 enum FieldTypeGroupForMetrics { | 33 enum FieldTypeGroupForMetrics { |
| 32 GROUP_AMBIGUOUS = 0, | 34 GROUP_AMBIGUOUS = 0, |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 } | 699 } |
| 698 | 700 |
| 699 // static | 701 // static |
| 700 void AutofillMetrics::LogCardUploadDecisionUkm( | 702 void AutofillMetrics::LogCardUploadDecisionUkm( |
| 701 ukm::UkmService* ukm_service, | 703 ukm::UkmService* ukm_service, |
| 702 const GURL& url, | 704 const GURL& url, |
| 703 AutofillMetrics::CardUploadDecisionMetric upload_decision) { | 705 AutofillMetrics::CardUploadDecisionMetric upload_decision) { |
| 704 if (upload_decision >= AutofillMetrics::NUM_CARD_UPLOAD_DECISION_METRICS) | 706 if (upload_decision >= AutofillMetrics::NUM_CARD_UPLOAD_DECISION_METRICS) |
| 705 return; | 707 return; |
| 706 | 708 |
| 707 // Set up as a map because the follow-up CL will add more metrics. | 709 const std::vector<std::pair<const char*, int>> metrics = { |
| 708 std::map<std::string, int> metrics = { | |
| 709 {internal::kUKMCardUploadDecisionMetricName, | 710 {internal::kUKMCardUploadDecisionMetricName, |
| 710 static_cast<int>(upload_decision)}}; | 711 static_cast<int>(upload_decision)}}; |
| 711 LogUkm(ukm_service, url, internal::kUKMCardUploadDecisionEntryName, metrics); | 712 LogUkm(ukm_service, url, internal::kUKMCardUploadDecisionEntryName, metrics); |
| 712 } | 713 } |
| 713 | 714 |
| 714 // static | 715 // static |
| 715 bool AutofillMetrics::LogUkm(ukm::UkmService* ukm_service, | 716 void AutofillMetrics::LogDeveloperEngagementUkm( |
| 716 const GURL& url, | 717 ukm::UkmService* ukm_service, |
| 717 const std::string& ukm_entry_name, | 718 const GURL& url, |
| 718 const std::map<std::string, int>& metrics) { | 719 const std::vector<AutofillMetrics::DeveloperEngagementMetric>& metrics) { |
| 720 std::vector<std::pair<const char*, int>> form_structure_metrics; |
| 721 for (auto it = metrics.begin(); it != metrics.end(); ++it) { |
| 722 if (*it < AutofillMetrics::NUM_DEVELOPER_ENGAGEMENT_METRICS) |
| 723 form_structure_metrics.emplace_back(std::make_pair( |
| 724 internal::kUKMDeveloperEngagementMetricName, static_cast<int>(*it))); |
| 725 } |
| 726 LogUkm(ukm_service, url, internal::kUKMDeveloperEngagementEntryName, |
| 727 form_structure_metrics); |
| 728 } |
| 729 |
| 730 // static |
| 731 bool AutofillMetrics::LogUkm( |
| 732 ukm::UkmService* ukm_service, |
| 733 const GURL& url, |
| 734 const std::string& ukm_entry_name, |
| 735 const std::vector<std::pair<const char*, int>>& metrics) { |
| 719 if (!IsUkmLoggingEnabled() || !ukm_service || !url.is_valid() || | 736 if (!IsUkmLoggingEnabled() || !ukm_service || !url.is_valid() || |
| 720 metrics.empty()) { | 737 metrics.empty()) { |
| 721 return false; | 738 return false; |
| 722 } | 739 } |
| 723 | 740 |
| 724 int32_t source_id = ukm_service->GetNewSourceID(); | 741 int32_t source_id = ukm_service->GetNewSourceID(); |
| 725 ukm_service->UpdateSourceURL(source_id, url); | 742 ukm_service->UpdateSourceURL(source_id, url); |
| 726 std::unique_ptr<ukm::UkmEntryBuilder> builder = | 743 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
| 727 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str()); | 744 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str()); |
| 728 | 745 |
| 729 for (auto it = metrics.begin(); it != metrics.end(); ++it) { | 746 for (auto it = metrics.begin(); it != metrics.end(); ++it) { |
| 730 builder->AddMetric(it->first.c_str(), it->second); | 747 builder->AddMetric(it->first, it->second); |
| 731 } | 748 } |
| 732 | 749 |
| 733 return true; | 750 return true; |
| 734 } | 751 } |
| 735 | 752 |
| 736 AutofillMetrics::FormEventLogger::FormEventLogger(bool is_for_credit_card) | 753 AutofillMetrics::FormEventLogger::FormEventLogger(bool is_for_credit_card) |
| 737 : is_for_credit_card_(is_for_credit_card), | 754 : is_for_credit_card_(is_for_credit_card), |
| 738 is_server_data_available_(false), | 755 is_server_data_available_(false), |
| 739 is_local_data_available_(false), | 756 is_local_data_available_(false), |
| 740 is_context_secure_(false), | 757 is_context_secure_(false), |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 else if (is_server_data_available_ && !is_local_data_available_) | 947 else if (is_server_data_available_ && !is_local_data_available_) |
| 931 name += ".WithOnlyServerData"; | 948 name += ".WithOnlyServerData"; |
| 932 else if (!is_server_data_available_ && is_local_data_available_) | 949 else if (!is_server_data_available_ && is_local_data_available_) |
| 933 name += ".WithOnlyLocalData"; | 950 name += ".WithOnlyLocalData"; |
| 934 else | 951 else |
| 935 name += ".WithBothServerAndLocalData"; | 952 name += ".WithBothServerAndLocalData"; |
| 936 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); | 953 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); |
| 937 } | 954 } |
| 938 | 955 |
| 939 } // namespace autofill | 956 } // namespace autofill |
| OLD | NEW |