-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract ui info and delegate from AutofillSaveCardInfoBarDelegateMobile
* Move non-infobar code out of AutofillSaveCardInfoBarDelegateMobile to be reusable for the upcoming save card bottom sheet on Chrome for Android. Bug: 1454271 Low-Coverage-Reason: Coverage not run in CQ. Change-Id: I968e4683b77615d5318dc22479d9b869e6f7d91c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4721765 Reviewed-by: Chris Lu <thegreenfrog@chromium.org> Reviewed-by: Stephen McGruer <smcgruer@chromium.org> Reviewed-by: Rouslan Solomakhin <rouslan@chromium.org> Commit-Queue: Slobodan Pejic <slobodan@chromium.org> Reviewed-by: Jan Keitel <jkeitel@google.com> Reviewed-by: Tommy Martino <tmartino@chromium.org> Reviewed-by: Peter Kotwicz <pkotwicz@chromium.org> Cr-Commit-Position: refs/heads/main@{#1186485}
- Loading branch information
Slobodan Pejic
authored and
Chromium LUCI CQ
committed
Aug 22, 2023
1 parent
8bade2d
commit eecf6b1
Showing
13 changed files
with
1,032 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
components/autofill/core/browser/payments/autofill_save_card_delegate.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// 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/payments/autofill_save_card_delegate.h" | ||
|
||
#include "components/autofill/core/browser/metrics/payments/credit_card_save_metrics.h" | ||
|
||
namespace autofill { | ||
|
||
AutofillSaveCardDelegate::AutofillSaveCardDelegate( | ||
absl::variant<AutofillClient::LocalSaveCardPromptCallback, | ||
AutofillClient::UploadSaveCardPromptCallback> callback, | ||
AutofillClient::SaveCreditCardOptions options) | ||
: options_(options), | ||
had_user_interaction_(false), | ||
callback_(std::move(callback)) {} | ||
|
||
AutofillSaveCardDelegate::~AutofillSaveCardDelegate() = default; | ||
|
||
void AutofillSaveCardDelegate::OnUiShown() { | ||
AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN, | ||
is_for_upload(), options_); | ||
} | ||
|
||
void AutofillSaveCardDelegate::OnUiAccepted() { | ||
// Acceptance can be logged immediately if: | ||
// 1. the user is accepting local save. | ||
// 2. or when we don't need more info in order to upload. | ||
if (!is_for_upload() || | ||
(!options_.should_request_name_from_user && | ||
!options_.should_request_expiration_date_from_user)) { | ||
LogSaveCreditCardPromptResult( | ||
autofill_metrics::SaveCreditCardPromptResult::kAccepted, | ||
is_for_upload(), options_); | ||
} | ||
LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); | ||
RunSaveCardPromptCallback( | ||
AutofillClient::SaveCardOfferUserDecision::kAccepted, | ||
/*user_provided_details=*/{}); | ||
} | ||
|
||
void AutofillSaveCardDelegate::OnUiUpdatedAndAccepted( | ||
AutofillClient::UserProvidedCardDetails user_provided_details) { | ||
LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED); | ||
RunSaveCardPromptCallback( | ||
AutofillClient::SaveCardOfferUserDecision::kAccepted, | ||
user_provided_details); | ||
} | ||
|
||
void AutofillSaveCardDelegate::OnUiCanceled() { | ||
RunSaveCardPromptCallback( | ||
AutofillClient::SaveCardOfferUserDecision::kDeclined, | ||
/*user_provided_details=*/{}); | ||
LogUserAction(AutofillMetrics::INFOBAR_DENIED); | ||
LogSaveCreditCardPromptResult( | ||
autofill_metrics::SaveCreditCardPromptResult::kDenied, is_for_upload(), | ||
options_); | ||
} | ||
|
||
void AutofillSaveCardDelegate::OnUiIgnored() { | ||
if (!had_user_interaction_) { | ||
RunSaveCardPromptCallback( | ||
AutofillClient::SaveCardOfferUserDecision::kIgnored, | ||
/*user_provided_details=*/{}); | ||
LogUserAction(AutofillMetrics::INFOBAR_IGNORED); | ||
LogSaveCreditCardPromptResult( | ||
autofill_metrics::SaveCreditCardPromptResult::kIgnored, is_for_upload(), | ||
options_); | ||
} | ||
} | ||
|
||
void AutofillSaveCardDelegate::RunSaveCardPromptCallback( | ||
AutofillClient::SaveCardOfferUserDecision user_decision, | ||
AutofillClient::UserProvidedCardDetails user_provided_details) { | ||
if (is_for_upload()) { | ||
absl::get<AutofillClient::UploadSaveCardPromptCallback>( | ||
std::move(callback_)) | ||
.Run(user_decision, user_provided_details); | ||
} else { | ||
absl::get<AutofillClient::LocalSaveCardPromptCallback>(std::move(callback_)) | ||
.Run(user_decision); | ||
} | ||
} | ||
|
||
void AutofillSaveCardDelegate::LogUserAction( | ||
AutofillMetrics::InfoBarMetric user_action) { | ||
DCHECK(!had_user_interaction_); | ||
|
||
AutofillMetrics::LogCreditCardInfoBarMetric(user_action, is_for_upload(), | ||
options_); | ||
had_user_interaction_ = true; | ||
} | ||
|
||
} // namespace autofill |
Oops, something went wrong.