Chromium Code Reviews| Index: chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.cc |
| diff --git a/chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.cc b/chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.cc |
| index abd616f0cb3be6b12478acfb72beb9bfae2360c8..e08e2277681cea3b6c031a58a77704dba8bddae2 100644 |
| --- a/chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.cc |
| +++ b/chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.cc |
| @@ -12,6 +12,7 @@ |
| #include "chrome/browser/autofill/risk_util.h" |
| #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" |
| #include "chrome/grit/generated_resources.h" |
| +#include "components/autofill/core/browser/autofill_metrics.h" |
| #include "components/autofill/core/common/autofill_pref_names.h" |
| #include "components/user_prefs/user_prefs.h" |
| #include "content/public/browser/web_contents.h" |
| @@ -24,6 +25,9 @@ CardUnmaskPromptControllerImpl::CardUnmaskPromptControllerImpl( |
| content::WebContents* web_contents) |
| : web_contents_(web_contents), |
| card_unmask_view_(nullptr), |
| + unmasking_result_(AutofillClient::TRY_AGAIN_FAILURE), |
| + unmasking_initial_should_store_pan_(false), |
| + unmasking_number_of_attempts_(0), |
| weak_pointer_factory_(this) { |
| } |
| @@ -32,6 +36,10 @@ CardUnmaskPromptControllerImpl::~CardUnmaskPromptControllerImpl() { |
| card_unmask_view_->ControllerGone(); |
| } |
| +CardUnmaskPromptView* CardUnmaskPromptControllerImpl::CreateAndShowView() { |
| + return CardUnmaskPromptView::CreateAndShow(this); |
| +} |
| + |
| void CardUnmaskPromptControllerImpl::ShowPrompt( |
| const CreditCard& card, |
| base::WeakPtr<CardUnmaskDelegate> delegate) { |
| @@ -42,7 +50,20 @@ void CardUnmaskPromptControllerImpl::ShowPrompt( |
| LoadRiskFingerprint(); |
| card_ = card; |
| delegate_ = delegate; |
| - card_unmask_view_ = CardUnmaskPromptView::CreateAndShow(this); |
| + card_unmask_view_ = CreateAndShowView(); |
| + unmasking_result_ = AutofillClient::TRY_AGAIN_FAILURE; |
| + unmasking_number_of_attempts_ = 0; |
| + unmasking_initial_should_store_pan_ = GetStoreLocallyStartState(); |
| + AutofillMetrics::LogUnmaskPromptEvent(AutofillMetrics::UNMASK_PROMPT_SHOWN); |
| +} |
| + |
| +bool CardUnmaskPromptControllerImpl::AllowsRetry( |
| + AutofillClient::GetRealPanResult result) { |
| + if (result == AutofillClient::NETWORK_ERROR |
| + || result == AutofillClient::PERMANENT_FAILURE) { |
| + return false; |
| + } |
| + return true; |
| } |
| void CardUnmaskPromptControllerImpl::OnVerificationResult( |
| @@ -51,7 +72,7 @@ void CardUnmaskPromptControllerImpl::OnVerificationResult( |
| return; |
| base::string16 error_message; |
| - bool allow_retry = true; |
| + unmasking_result_ = result; |
| switch (result) { |
| case AutofillClient::SUCCESS: |
| break; |
| @@ -65,31 +86,81 @@ void CardUnmaskPromptControllerImpl::OnVerificationResult( |
| case AutofillClient::PERMANENT_FAILURE: { |
| error_message = l10n_util::GetStringUTF16( |
| IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_PERMANENT); |
| - allow_retry = false; |
| break; |
| } |
| case AutofillClient::NETWORK_ERROR: { |
| error_message = l10n_util::GetStringUTF16( |
| IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_NETWORK); |
| - allow_retry = false; |
| break; |
| } |
| } |
| - card_unmask_view_->GotVerificationResult(error_message, allow_retry); |
| + AutofillMetrics::LogRealPanResult(result); |
| + unmasking_allow_retry_ = AllowsRetry(result); |
| + card_unmask_view_->GotVerificationResult(error_message, |
| + AllowsRetry(result)); |
| } |
| void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { |
| card_unmask_view_ = nullptr; |
| + LogEvents(); |
|
Evan Stade
2015/03/19 00:30:34
nit: I'd call this LogOnCloseEvents or something
Walter Cacau
2015/03/19 00:39:24
Done.
|
| delegate_->OnUnmaskPromptClosed(); |
| } |
| +void CardUnmaskPromptControllerImpl::LogEvents() { |
| + if (unmasking_number_of_attempts_ == 0) { |
| + AutofillMetrics::LogUnmaskPromptEvent( |
| + AutofillMetrics::UNMASK_PROMPT_CLOSED_NO_ATTEMPTS); |
| + return; |
| + } |
| + |
| + bool final_should_store_pan = |
| + user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext()) |
| + ->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState); |
| + |
| + if (unmasking_result_ == AutofillClient::SUCCESS) { |
| + AutofillMetrics::LogUnmaskPromptEvent( |
| + unmasking_number_of_attempts_ == 1 |
| + ? AutofillMetrics::UNMASK_PROMPT_UNMASKED_CARD_FIRST_ATTEMPT |
| + : AutofillMetrics::UNMASK_PROMPT_UNMASKED_CARD_AFTER_FAILED_ATTEMPTS); |
| + if (final_should_store_pan) { |
| + AutofillMetrics::LogUnmaskPromptEvent( |
| + AutofillMetrics::UNMASK_PROMPT_SAVED_CARD_LOCALLY); |
| + } |
| + } else { |
| + AutofillMetrics::LogUnmaskPromptEvent( |
| + AllowsRetry(unmasking_result_) |
| + ? AutofillMetrics |
| + ::UNMASK_PROMPT_CLOSED_FAILED_TO_UNMASK_RETRIABLE_FAILURE |
| + : AutofillMetrics |
| + ::UNMASK_PROMPT_CLOSED_FAILED_TO_UNMASK_NON_RETRIABLE_FAILURE); |
|
Evan Stade
2015/03/19 00:30:34
this still doesn't log the exact error type
Walter Cacau
2015/03/19 00:39:25
AutofillMetrics::LogRealPanResult(result); takes c
Evan Stade
2015/03/19 01:06:57
ok
|
| + } |
| + |
| + // Tracking changes in local save preference. |
| + { |
|
Evan Stade
2015/03/19 00:30:34
what is the purpose of this brace
Walter Cacau
2015/03/19 00:39:25
Done.
|
| + AutofillMetrics::UnmaskPromptEvent event; |
| + if (unmasking_initial_should_store_pan_ && final_should_store_pan) { |
| + event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_OUT; |
| + } else if (!unmasking_initial_should_store_pan_ |
| + && !final_should_store_pan) { |
| + event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_IN; |
| + } else if (unmasking_initial_should_store_pan_ |
| + && !final_should_store_pan) { |
| + event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_OUT; |
| + } else { |
| + event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_IN; |
| + } |
| + AutofillMetrics::LogUnmaskPromptEvent(event); |
| + } |
| +} |
| + |
| void CardUnmaskPromptControllerImpl::OnUnmaskResponse( |
| const base::string16& cvc, |
| const base::string16& exp_month, |
| const base::string16& exp_year, |
| bool should_store_pan) { |
| + unmasking_number_of_attempts_++; |
| card_unmask_view_->DisableAndWaitForVerification(); |
| DCHECK(!cvc.empty()); |