Commit 32311190 authored by Sujie Zhu's avatar Sujie Zhu Committed by Commit Bot

[Autofill Auth] Move UnmaskAuthFlowType to CreditCardAccessManager

Apart from being used for metrics, we also base our branching logic on
UnmaskAuthFlowType in CreditCardAccessManager. so it should be declared
in CreditCardAccessManager instead of CreditCardFormEventLogger.

We use forward declaring to avoid cyclic imports.

Bug: 949269
Change-Id: Idc2a12beaac80f7b9e9fc496d66245c842eebcb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2052325
Commit-Queue: Sujie Zhu <sujiezhu@google.com>
Reviewed-by: default avatarManas Verma <manasverma@google.com>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741199}
parent 77bc6ac1
......@@ -11,6 +11,7 @@
#include "base/metrics/user_metrics_action.h"
#include "base/strings/string16.h"
#include "components/autofill/core/browser/form_data_importer.h"
#include "components/autofill/core/browser/payments/credit_card_access_manager.h"
#include "components/autofill/core/browser/validation.h"
namespace autofill {
......
......@@ -20,20 +20,10 @@
namespace autofill {
enum class UnmaskAuthFlowType;
class CreditCardFormEventLogger : public FormEventLoggerBase {
public:
// Metric for tracking which card unmask authentication method was used.
enum class UnmaskAuthFlowType {
kNone = 0,
// Only CVC prompt was shown.
kCvc = 1,
// Only WebAuthn prompt was shown.
kFido = 2,
// CVC authentication was required in addition to WebAuthn.
kCvcThenFido = 3,
// WebAuthn prompt failed and fell back to CVC prompt.
kCvcFallbackFromFido = 4,
};
enum class UnmaskAuthFlowEvent {
// Authentication prompt is shown.
kPromptShown = 0,
......
......@@ -352,8 +352,7 @@ void CreditCardAccessManager::OnSettingsPageFIDOAuthToggled(bool opt_in) {
#endif
}
CreditCardFormEventLogger::UnmaskAuthFlowType
CreditCardAccessManager::GetAuthenticationType(
UnmaskAuthFlowType CreditCardAccessManager::GetAuthenticationType(
bool get_unmask_details_returned) {
bool fido_auth_suggested =
get_unmask_details_returned && unmask_details_.unmask_auth_method ==
......@@ -373,10 +372,10 @@ CreditCardAccessManager::GetAuthenticationType(
card_is_authorized_for_fido && !card_->IsExpired(AutofillClock::Now());
if (card_is_eligible_for_fido)
return CreditCardFormEventLogger::UnmaskAuthFlowType::kFido;
return UnmaskAuthFlowType::kFido;
if (should_follow_up_cvc_with_fido_auth)
return CreditCardFormEventLogger::UnmaskAuthFlowType::kCvcThenFido;
return CreditCardFormEventLogger::UnmaskAuthFlowType::kCvc;
return UnmaskAuthFlowType::kCvcThenFido;
return UnmaskAuthFlowType::kCvc;
}
void CreditCardAccessManager::Authenticate(bool get_unmask_details_returned) {
......@@ -400,19 +399,16 @@ void CreditCardAccessManager::Authenticate(bool get_unmask_details_returned) {
// If FIDO auth was suggested, logging which authentication method was
// actually used.
if (unmask_auth_flow_type_ ==
CreditCardFormEventLogger::UnmaskAuthFlowType::kFido) {
if (unmask_auth_flow_type_ == UnmaskAuthFlowType::kFido) {
AutofillMetrics::LogCardUnmaskTypeDecision(
AutofillMetrics::CardUnmaskTypeDecisionMetric::kFidoOnly);
}
if (unmask_auth_flow_type_ ==
CreditCardFormEventLogger::UnmaskAuthFlowType::kCvcThenFido) {
if (unmask_auth_flow_type_ == UnmaskAuthFlowType::kCvcThenFido) {
AutofillMetrics::LogCardUnmaskTypeDecision(
AutofillMetrics::CardUnmaskTypeDecisionMetric::kCvcThenFido);
}
if (unmask_auth_flow_type_ ==
CreditCardFormEventLogger::UnmaskAuthFlowType::kFido) {
if (unmask_auth_flow_type_ == UnmaskAuthFlowType::kFido) {
#if defined(OS_IOS)
NOTREACHED();
#else
......@@ -465,8 +461,7 @@ void CreditCardAccessManager::OnCVCAuthenticationComplete(
// Log completed CVC authentication if auth was successful. Do not log for
// kCvcThenFido flow since that is yet to be completed.
if (response.did_succeed &&
unmask_auth_flow_type_ !=
CreditCardFormEventLogger::UnmaskAuthFlowType::kCvcThenFido) {
unmask_auth_flow_type_ != UnmaskAuthFlowType::kCvcThenFido) {
form_event_logger_->LogCardUnmaskAuthenticationPromptCompleted(
unmask_auth_flow_type_);
}
......@@ -475,13 +470,11 @@ void CreditCardAccessManager::OnCVCAuthenticationComplete(
// -- a CVC check is adequate for an opted-out user. An opted-in user,
// however, will require an additional WebAuthn check before the form can be
// filled. If CVC authentication failed, report error immediately.
if (unmask_auth_flow_type_ !=
CreditCardFormEventLogger::UnmaskAuthFlowType::kCvcThenFido ||
if (unmask_auth_flow_type_ != UnmaskAuthFlowType::kCvcThenFido ||
!response.did_succeed) {
accessor_->OnCreditCardFetched(response.did_succeed, response.card,
response.cvc);
unmask_auth_flow_type_ =
CreditCardFormEventLogger::UnmaskAuthFlowType::kNone;
unmask_auth_flow_type_ = UnmaskAuthFlowType::kNone;
}
if (!response.did_succeed || response.card_authorization_token.empty())
......@@ -516,8 +509,7 @@ void CreditCardAccessManager::OnCVCAuthenticationComplete(
->IsMaxStrikesLimitReached();
if (should_offer_fido_auth) {
ShowWebauthnOfferDialog(response.card_authorization_token);
} else if (unmask_auth_flow_type_ ==
CreditCardFormEventLogger::UnmaskAuthFlowType::kCvcThenFido) {
} else if (unmask_auth_flow_type_ == UnmaskAuthFlowType::kCvcThenFido) {
DCHECK(unmask_details_.fido_request_options.has_value());
// Save credit card for after authorization.
......@@ -549,11 +541,9 @@ void CreditCardAccessManager::OnFIDOAuthenticationComplete(
form_event_logger_->LogCardUnmaskAuthenticationPromptCompleted(
unmask_auth_flow_type_);
unmask_auth_flow_type_ =
CreditCardFormEventLogger::UnmaskAuthFlowType::kNone;
unmask_auth_flow_type_ = UnmaskAuthFlowType::kNone;
} else {
unmask_auth_flow_type_ =
CreditCardFormEventLogger::UnmaskAuthFlowType::kCvcFallbackFromFido;
unmask_auth_flow_type_ = UnmaskAuthFlowType::kCvcFallbackFromFido;
form_event_logger_->LogCardUnmaskAuthenticationPromptShown(
unmask_auth_flow_type_);
GetOrCreateCVCAuthenticator()->Authenticate(
......@@ -568,7 +558,7 @@ void CreditCardAccessManager::OnFidoAuthorizationComplete(bool did_succeed) {
form_event_logger_->LogCardUnmaskAuthenticationPromptCompleted(
unmask_auth_flow_type_);
}
unmask_auth_flow_type_ = CreditCardFormEventLogger::UnmaskAuthFlowType::kNone;
unmask_auth_flow_type_ = UnmaskAuthFlowType::kNone;
cvc_ = base::string16();
}
#endif
......
......@@ -32,6 +32,19 @@ namespace autofill {
class AutofillManager;
enum class WebauthnDialogCallbackType;
// Flow type denotes which card unmask authentication method was used.
enum class UnmaskAuthFlowType {
kNone = 0,
// Only CVC prompt was shown.
kCvc = 1,
// Only WebAuthn prompt was shown.
kFido = 2,
// CVC authentication was required in addition to WebAuthn.
kCvcThenFido = 3,
// WebAuthn prompt failed and fell back to CVC prompt.
kCvcFallbackFromFido = 4,
};
// Manages logic for accessing credit cards either stored locally or stored
// with Google Payments. Owned by AutofillManager.
#if defined(OS_IOS)
......@@ -133,8 +146,7 @@ class CreditCardAccessManager : public CreditCardCVCAuthenticator::Requester,
payments::PaymentsClient::UnmaskDetails& unmask_details);
// Determines what form of authentication is required.
CreditCardFormEventLogger::UnmaskAuthFlowType GetAuthenticationType(
bool get_unmask_details_returned);
UnmaskAuthFlowType GetAuthenticationType(bool get_unmask_details_returned);
// If OnDidGetUnmaskDetails() was invoked by PaymentsClient, then
// |get_unmask_details_returned| should be set to true. Based on the
......@@ -193,8 +205,7 @@ class CreditCardAccessManager : public CreditCardCVCAuthenticator::Requester,
void SignalCanFetchUnmaskDetails();
// The current form of authentication in progress.
CreditCardFormEventLogger::UnmaskAuthFlowType unmask_auth_flow_type_ =
CreditCardFormEventLogger::UnmaskAuthFlowType::kNone;
UnmaskAuthFlowType unmask_auth_flow_type_ = UnmaskAuthFlowType::kNone;
// Is set to true only when waiting for the callback to
// OnCVCAuthenticationComplete() to be executed.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment