Skip to content

Commit

Permalink
Add metrics to log whether IBANs are now shown due to blocklist or not.
Browse files Browse the repository at this point in the history
Bug: 1473113
Change-Id: I44639d43013e9c075441d4f1d148231eb76f949e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4781213
Commit-Queue: Qihui Zhao <qihuizhao@google.com>
Reviewed-by: Olivia Saul <jsaul@google.com>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Florian Leimgruber <fleimgruber@google.com>
Cr-Commit-Position: refs/heads/main@{#1185502}
  • Loading branch information
Qihui Zhao authored and Chromium LUCI CQ committed Aug 19, 2023
1 parent 45195ae commit c892694
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 19 deletions.
46 changes: 27 additions & 19 deletions components/autofill/core/browser/iban_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "components/autofill/core/browser/autofill_optimization_guide.h"
#include "components/autofill/core/browser/autofill_suggestion_generator.h"
#include "components/autofill/core/browser/browser_autofill_manager.h"
#include "components/autofill/core/browser/metrics/payments/iban_metrics.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/suggestions_context.h"
#include "components/autofill/core/common/autofill_clock.h"
Expand All @@ -33,36 +34,43 @@ bool IbanManager::OnGetSingleFieldSuggestions(
return false;
}

if (!personal_data_manager_ ||
!personal_data_manager_->IsAutofillCreditCardEnabled()) {
return false;
}

std::vector<Iban*> ibans = personal_data_manager_->GetLocalIbans();
if (ibans.empty()) {
return false;
}

// AutofillOptimizationGuide will not be present on unsupported platforms.
if (auto* autofill_optimization_guide =
client.GetAutofillOptimizationGuide()) {
if (autofill_optimization_guide->ShouldBlockSingleFieldSuggestions(
client.GetLastCommittedPrimaryMainFrameOrigin().GetURL(),
focused_field)) {
autofill_metrics::LogIbanSuggestionBlockListStatusMetric(
autofill_metrics::IbanSuggestionBlockListStatus::kBlocked);
return false;
}
autofill_metrics::LogIbanSuggestionBlockListStatusMetric(
autofill_metrics::IbanSuggestionBlockListStatus::kAllowed);
} else {
autofill_metrics::LogIbanSuggestionBlockListStatusMetric(
autofill_metrics::IbanSuggestionBlockListStatus::
kBlocklistIsNotAvailable);
}

if (!personal_data_manager_ ||
!personal_data_manager_->IsAutofillCreditCardEnabled()) {
return false;
}
// Rank the IBANs by ranking score (see AutoFillDataModel for details).
base::ranges::sort(ibans, [comparison_time = AutofillClock::Now()](
const Iban* iban0, const Iban* iban1) {
return iban0->HasGreaterRankingThan(iban1, comparison_time);
});
SendIbanSuggestions(ibans, QueryHandler(field.global_id(), trigger_source,
field.value, handler));

std::vector<Iban*> ibans = personal_data_manager_->GetLocalIbans();
if (!ibans.empty()) {
// Rank the IBANs by ranking score (see AutoFillDataModel for details).
base::Time comparison_time = AutofillClock::Now();
if (ibans.size() > 1) {
base::ranges::sort(
ibans, [comparison_time](const Iban* iban0, const Iban* iban1) {
return iban0->HasGreaterRankingThan(iban1, comparison_time);
});
}
SendIbanSuggestions(ibans, QueryHandler(field.global_id(), trigger_source,
field.value, handler));
return true;
}
return false;
return true;
}

base::WeakPtr<IbanManager> IbanManager::GetWeakPtr() {
Expand Down
67 changes: 67 additions & 0 deletions components/autofill/core/browser/iban_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,73 @@ TEST_F(IbanManagerTest, NotIbanFieldFocused_NoSuggestionsShown) {
/*context=*/context));
}

// Tests that when showing IBAN suggestions is allowed by the site-specific
// blocklist, appropriate metrics are logged.
TEST_F(IbanManagerTest, Metrics_Suggestions_Allowed) {
base::HistogramTester histogram_tester;
SetUpIban(test::kIbanValue, kNickname_0);

AutofillField test_field;
test_field.unique_renderer_id = test::MakeFieldRendererId();
SuggestionsContext context = GetIbanFocusedSuggestionsContext(test_field);
// Simulate request for suggestions.
iban_manager_.OnGetSingleFieldSuggestions(
AutofillSuggestionTriggerSource::kFormControlElementClicked, test_field,
autofill_client_, suggestions_handler_.GetWeakPtr(), context);

histogram_tester.ExpectUniqueSample(
"Autofill.Iban.ShowSuggestionsBlocklistDecision",
autofill_metrics::IbanSuggestionBlockListStatus::kAllowed, 1);
}

// Tests that when showing IBAN suggestions is blocked by the site-specific
// blocklist, appropriate metrics are logged.
TEST_F(IbanManagerTest, Metrics_Suggestions_Blocked) {
base::HistogramTester histogram_tester;
SetUpIban(test::kIbanValue, kNickname_0);
AutofillField test_field;
SuggestionsContext context = GetIbanFocusedSuggestionsContext(test_field);

// Setting up mock to verify that suggestions returning is not triggered if
// the website is blocked.
EXPECT_CALL(suggestions_handler_, OnSuggestionsReturned).Times(0);
ON_CALL(*static_cast<MockAutofillOptimizationGuide*>(
autofill_client_.GetAutofillOptimizationGuide()),
ShouldBlockSingleFieldSuggestions)
.WillByDefault(testing::Return(true));
// Simulate request for suggestions.
iban_manager_.OnGetSingleFieldSuggestions(
AutofillSuggestionTriggerSource::kFormControlElementClicked, test_field,
autofill_client_, suggestions_handler_.GetWeakPtr(),
/*context=*/context);

histogram_tester.ExpectUniqueSample(
"Autofill.Iban.ShowSuggestionsBlocklistDecision",
autofill_metrics::IbanSuggestionBlockListStatus::kBlocked, 1);
}

// Tests that when showing IBAN suggestions and the site-specific blocklist is
// not available, appropriate metrics are logged.
TEST_F(IbanManagerTest, Metrics_Suggestions_BlocklistNotAccessible) {
base::HistogramTester histogram_tester;
SetUpIban(test::kIbanValue, kNickname_0);
AutofillField test_field;
SuggestionsContext context = GetIbanFocusedSuggestionsContext(test_field);
// Delete the AutofillOptimizationGuide.
autofill_client_.ResetAutofillOptimizationGuide();

// Simulate request for suggestions.
iban_manager_.OnGetSingleFieldSuggestions(
AutofillSuggestionTriggerSource::kFormControlElementClicked, test_field,
autofill_client_, suggestions_handler_.GetWeakPtr(),
/*context=*/context);

histogram_tester.ExpectUniqueSample(
"Autofill.Iban.ShowSuggestionsBlocklistDecision",
autofill_metrics::IbanSuggestionBlockListStatus::kBlocklistIsNotAvailable,
1);
}

// Test that the metrics for IBAN-related suggestions shown and shown once are
// logged correctly.
TEST_F(IbanManagerTest, Metrics_SuggestionsShown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ void LogIndividualIbanSuggestionsEvent(IbanSuggestionsEvent event) {
base::UmaHistogramEnumeration("Autofill.Iban.Suggestions", event);
}

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

} // namespace autofill::autofill_metrics
18 changes: 18 additions & 0 deletions components/autofill/core/browser/metrics/payments/iban_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ enum class IbanSuggestionsEvent {
kMaxValue = kIbanSuggestionSelectedOnce,
};

// Metrics to track the site blocklist status when showing IBAN suggestions.
enum class IbanSuggestionBlockListStatus {
// IBAN suggestions were allowed.
kAllowed = 0,
// IBAN suggestions were blocked due to the site's origin being in the
// blocklist.
kBlocked = 1,
// Blocklist is not available.
kBlocklistIsNotAvailable = 2,
kMaxValue = kBlocklistIsNotAvailable,
};

// Logs various metrics about the local IBANs associated with a profile. This
// should be called each time a new Chrome profile is launched.
// `disused_data_threshold` is the time threshold to mark an IBAN as disused.
Expand All @@ -90,6 +102,12 @@ void LogSaveIbanBubbleResultSavedWithNicknameMetric(bool save_with_nickname);
// Logs metrics related to IBAN individual suggestions being shown or selected.
void LogIndividualIbanSuggestionsEvent(IbanSuggestionsEvent event);

// Logs when the user clicks on an IBAN field and triggers IBAN autofill.
// `event` donates whether IBAN suggestions were allowed to be shown, blocked
// from being shown, or if the blocklist was not accessible at all.
void LogIbanSuggestionBlockListStatusMetric(
IbanSuggestionBlockListStatus event);

} // namespace autofill::autofill_metrics

#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_METRICS_PAYMENTS_IBAN_METRICS_H_
6 changes: 6 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52895,6 +52895,12 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
</int>
</enum>

<enum name="IbanSuggestionBlockListStatus">
<int value="0" label="Allowed"/>
<int value="1" label="Blocked"/>
<int value="2" label="Blocklist is not available"/>
</enum>

<enum name="IbanSuggestionsEvent">
<int value="0" label="IBAN suggestions shown"/>
<int value="1" label="IBAN suggestions shown (once)"/>
Expand Down
12 changes: 12 additions & 0 deletions tools/metrics/histograms/metadata/autofill/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2331,6 +2331,18 @@ chromium-metrics-reviews@google.com.
</summary>
</histogram>

<histogram name="Autofill.Iban.ShowSuggestionsBlocklistDecision"
enum="IbanSuggestionBlockListStatus" expires_after="2024-07-01">
<owner>qihuizhao@google.com</owner>
<owner>jsaul@google.com</owner>
<owner>payments-autofill-team@google.com</owner>
<summary>
Recorded when the user has IBANs and clicks on an IBAN form field. Logs
whether IBAN suggestions were allowed to be shown, blocked from being shown,
or if the blocklist was not accessible at all.
</summary>
</histogram>

<histogram name="Autofill.Iban.Suggestions" enum="IbanSuggestionsEvent"
expires_after="2024-03-01">
<owner>qihuizhao@google.com</owner>
Expand Down

0 comments on commit c892694

Please sign in to comment.