File: iban_metrics.cc

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (194 lines) | stat: -rw-r--r-- 7,472 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill/core/browser/metrics/payments/iban_metrics.h"

#include <string>
#include <vector>

#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/strcat.h"
#include "components/autofill/core/browser/data_model/payments/iban.h"
#include "components/autofill/core/common/autofill_clock.h"

namespace autofill::autofill_metrics {

void LogStoredIbanMetrics(
    const std::vector<std::unique_ptr<Iban>>& local_ibans,
    const std::vector<std::unique_ptr<Iban>>& server_ibans,
    base::TimeDelta disused_data_threshold) {
  auto LogStoredIban = [disused_data_threshold](
                           const std::vector<std::unique_ptr<Iban>>& ibans) {
    if (ibans.empty()) {
      return;
    }
    // Iterate over all of the IBANs and gather metrics.
    size_t num_ibans_with_nickname = 0;
    size_t num_disused_ibans = 0;
    const base::Time now = AutofillClock::Now();
    const std::string histogram_suffix =
        ibans[0]->record_type() == Iban::kLocalIban ? "Local" : "Server";
    for (const std::unique_ptr<Iban>& iban : ibans) {
      const base::TimeDelta time_since_last_use =
          now - iban->usage_history().use_date();
      if (time_since_last_use > disused_data_threshold) {
        num_disused_ibans++;
      }
      base::UmaHistogramCounts1000(
          base::StrCat(
              {"Autofill.DaysSinceLastUse.StoredIban.", histogram_suffix}),
          time_since_last_use.InDays());
      if (!iban->nickname().empty()) {
        num_ibans_with_nickname++;
      }
    }

    base::UmaHistogramCounts100(
        base::StrCat({"Autofill.StoredIbanCount.", histogram_suffix}),
        ibans.size());
    base::UmaHistogramCounts100(
        base::StrCat(
            {"Autofill.StoredIbanCount.", histogram_suffix, ".WithNickname"}),
        num_ibans_with_nickname);

    base::UmaHistogramCounts100(
        base::StrCat({"Autofill.StoredIbanDisusedCount.", histogram_suffix}),
        num_disused_ibans);
  };

  LogStoredIban(local_ibans);
  LogStoredIban(server_ibans);
  base::UmaHistogramCounts100("Autofill.StoredIbanCount",
                              local_ibans.size() + server_ibans.size());
}

void LogDaysSinceLastIbanUse(const Iban& iban) {
  CHECK(iban.record_type() == Iban::RecordType::kLocalIban ||
        iban.record_type() == Iban::RecordType::kServerIban);
  base::UmaHistogramCounts1000(
      base::StrCat({"Autofill.DaysSinceLastUse.StoredIban.",
                    (iban.record_type() == Iban::RecordType::kServerIban)
                        ? "Server"
                        : "Local"}),
      (AutofillClock::Now() - iban.usage_history().use_date()).InDays());
}

void LogStrikesPresentWhenIbanSaved(const int num_strikes,
                                    bool is_upload_save) {
  base::UmaHistogramCounts100(
      base::StrCat({"Autofill.StrikeDatabase.StrikesPresentWhenIbanSaved.",
                    is_upload_save ? "Upload" : "Local"}),
      num_strikes);
}

void LogIbanSaveNotOfferedDueToMaxStrikesMetric(
    AutofillMetrics::SaveTypeMetric metric) {
  base::UmaHistogramEnumeration(
      "Autofill.StrikeDatabase.IbanSaveNotOfferedDueToMaxStrikes", metric);
}

void LogUploadIbanMetric(UploadIbanOriginMetric origin_metric,
                         UploadIbanActionMetric action_metric) {
  std::string histogram_name = "Autofill.UploadIban.";
  switch (action_metric) {
    case UploadIbanActionMetric::kOffered:
      histogram_name += "Offered";
      break;
    case UploadIbanActionMetric::kAccepted:
      histogram_name += "Accepted";
      break;
    case UploadIbanActionMetric::kDeclined:
      histogram_name += "Declined";
      break;
    case UploadIbanActionMetric::kIgnored:
      histogram_name += "Ignored";
      break;
  }
  base::UmaHistogramEnumeration(histogram_name, origin_metric);
}

void LogSaveIbanPromptOfferMetric(SaveIbanPromptOffer metric,
                                  bool is_reshow,
                                  bool is_upload_save) {
  std::string base_histogram_name = base::StrCat(
      {"Autofill.SaveIbanPromptOffer.", is_upload_save ? "Upload" : "Local",
       is_reshow ? ".Reshows" : ".FirstShow"});
  base::UmaHistogramEnumeration(base_histogram_name, metric);
}

void LogSaveIbanPromptResultMetric(SaveIbanPromptResult metric,
                                   bool is_reshow,
                                   bool is_upload_save) {
  std::string base_histogram_name = base::StrCat(
      {"Autofill.SaveIbanPromptResult.", is_upload_save ? "Upload" : "Local",
       is_reshow ? ".Reshows" : ".FirstShow"});
  base::UmaHistogramEnumeration(base_histogram_name, metric);
}

void LogSaveIbanPromptResultSavedWithNicknameMetric(bool save_with_nickname,
                                                    bool is_upload_save) {
  base::UmaHistogramBoolean(
      base::StrCat({"Autofill.SaveIbanPromptResult.",
                    is_upload_save ? "Upload" : "Local", ".SavedWithNickname"}),
      save_with_nickname);
}

void LogIndividualIbanSuggestionsEvent(IbanSuggestionsEvent event) {
  base::UmaHistogramEnumeration("Autofill.Iban.Suggestions", event);
}

void LogIbanSuggestionBlockListStatusMetric(
    IbanSuggestionBlockListStatus event) {
  base::UmaHistogramEnumeration(
      "Autofill.Iban.ShowSuggestionsBlocklistDecision", event);
}

void LogServerIbanLinkClicked(AutofillMetrics::PaymentsSigninState sync_state) {
  base::UmaHistogramEnumeration("Autofill.ServerIbanLinkClicked", sync_state);
}

void LogIbanUploadEnabledMetric(
    IbanUploadEnabledStatus metric,
    AutofillMetrics::PaymentsSigninState sync_state) {
  const std::string base_metric = std::string("Autofill.IbanUploadEnabled");
  base::UmaHistogramEnumeration(base_metric, metric);

  const std::string sync_subhistogram_metric =
      base_metric + AutofillMetrics::GetMetricsSyncStateSuffix(sync_state);
  base::UmaHistogramEnumeration(sync_subhistogram_metric, metric);
}

void LogServerIbanUnmaskLatency(base::TimeDelta latency, bool is_successful) {
  base::UmaHistogramTimes(base::StrCat({"Autofill.Iban.UnmaskIbanDuration.",
                                        is_successful ? "Success" : "Failure"}),
                          latency);
  base::UmaHistogramTimes("Autofill.Iban.UnmaskIbanDuration", latency);
}

void LogServerIbanUnmaskStatus(bool is_successful) {
  base::UmaHistogramBoolean("Autofill.Iban.UnmaskIbanResult", is_successful);
}

void LogIbanSaveOfferedCountry(std::string_view country_code) {
  base::UmaHistogramEnumeration("Autofill.Iban.CountryOfSaveOfferedIban",
                                Iban::GetIbanSupportedCountry(country_code));
}

void LogIbanSaveAcceptedCountry(std::string_view country_code) {
  base::UmaHistogramEnumeration("Autofill.Iban.CountryOfSaveAcceptedIban",
                                Iban::GetIbanSupportedCountry(country_code));
}

void LogIbanSelectedCountry(std::string_view country_code) {
  base::UmaHistogramEnumeration("Autofill.Iban.CountryOfSelectedIban",
                                Iban::GetIbanSupportedCountry(country_code));
}

void LogIbanUploadSaveFailed(bool iban_saved_locally) {
  base::UmaHistogramBoolean("Autofill.IbanUpload.SaveFailed",
                            iban_saved_locally);
}

}  // namespace autofill::autofill_metrics