Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" | 
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" | 
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" | 
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" | 
| 12 #include "chrome/browser/autofill/risk_util.h" | 12 #include "chrome/browser/autofill/risk_util.h" | 
| 13 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" | 13 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" | 
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" | 
| 15 #include "components/autofill/core/browser/autofill_metrics.h" | |
| 15 #include "components/autofill/core/common/autofill_pref_names.h" | 16 #include "components/autofill/core/common/autofill_pref_names.h" | 
| 16 #include "components/user_prefs/user_prefs.h" | 17 #include "components/user_prefs/user_prefs.h" | 
| 17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" | 
| 18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" | 
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" | 
| 20 | 21 | 
| 21 namespace autofill { | 22 namespace autofill { | 
| 22 | 23 | 
| 23 CardUnmaskPromptControllerImpl::CardUnmaskPromptControllerImpl( | 24 CardUnmaskPromptControllerImpl::CardUnmaskPromptControllerImpl( | 
| 24 content::WebContents* web_contents) | 25 content::WebContents* web_contents) | 
| 25 : web_contents_(web_contents), | 26 : web_contents_(web_contents), | 
| 26 card_unmask_view_(nullptr), | 27 card_unmask_view_(nullptr), | 
| 28 unmasking_result_(AutofillClient::TRY_AGAIN_FAILURE), | |
| 29 unmasking_initial_should_store_pan_(false), | |
| 30 unmasking_number_of_attempts_(0), | |
| 27 weak_pointer_factory_(this) { | 31 weak_pointer_factory_(this) { | 
| 28 } | 32 } | 
| 29 | 33 | 
| 30 CardUnmaskPromptControllerImpl::~CardUnmaskPromptControllerImpl() { | 34 CardUnmaskPromptControllerImpl::~CardUnmaskPromptControllerImpl() { | 
| 31 if (card_unmask_view_) | 35 if (card_unmask_view_) | 
| 32 card_unmask_view_->ControllerGone(); | 36 card_unmask_view_->ControllerGone(); | 
| 33 } | 37 } | 
| 34 | 38 | 
| 39 CardUnmaskPromptView* CardUnmaskPromptControllerImpl::CreateAndShowView() { | |
| 40 return CardUnmaskPromptView::CreateAndShow(this); | |
| 41 } | |
| 42 | |
| 35 void CardUnmaskPromptControllerImpl::ShowPrompt( | 43 void CardUnmaskPromptControllerImpl::ShowPrompt( | 
| 36 const CreditCard& card, | 44 const CreditCard& card, | 
| 37 base::WeakPtr<CardUnmaskDelegate> delegate) { | 45 base::WeakPtr<CardUnmaskDelegate> delegate) { | 
| 38 if (card_unmask_view_) | 46 if (card_unmask_view_) | 
| 39 card_unmask_view_->ControllerGone(); | 47 card_unmask_view_->ControllerGone(); | 
| 40 | 48 | 
| 41 pending_response_ = CardUnmaskDelegate::UnmaskResponse(); | 49 pending_response_ = CardUnmaskDelegate::UnmaskResponse(); | 
| 42 LoadRiskFingerprint(); | 50 LoadRiskFingerprint(); | 
| 43 card_ = card; | 51 card_ = card; | 
| 44 delegate_ = delegate; | 52 delegate_ = delegate; | 
| 45 card_unmask_view_ = CardUnmaskPromptView::CreateAndShow(this); | 53 card_unmask_view_ = CreateAndShowView(); | 
| 54 unmasking_result_ = AutofillClient::TRY_AGAIN_FAILURE; | |
| 55 unmasking_number_of_attempts_ = 0; | |
| 56 unmasking_initial_should_store_pan_ = GetStoreLocallyStartState(); | |
| 57 AutofillMetrics::LogUnmaskPromptEvent(AutofillMetrics::UNMASK_PROMPT_SHOWN); | |
| 58 } | |
| 59 | |
| 60 bool CardUnmaskPromptControllerImpl::AllowsRetry( | |
| 61 AutofillClient::GetRealPanResult result) { | |
| 62 if (result == AutofillClient::NETWORK_ERROR | |
| 63 || result == AutofillClient::PERMANENT_FAILURE) { | |
| 64 return false; | |
| 65 } | |
| 66 return true; | |
| 46 } | 67 } | 
| 47 | 68 | 
| 48 void CardUnmaskPromptControllerImpl::OnVerificationResult( | 69 void CardUnmaskPromptControllerImpl::OnVerificationResult( | 
| 49 AutofillClient::GetRealPanResult result) { | 70 AutofillClient::GetRealPanResult result) { | 
| 50 if (!card_unmask_view_) | 71 if (!card_unmask_view_) | 
| 51 return; | 72 return; | 
| 52 | 73 | 
| 53 base::string16 error_message; | 74 base::string16 error_message; | 
| 54 bool allow_retry = true; | 75 unmasking_result_ = result; | 
| 55 switch (result) { | 76 switch (result) { | 
| 56 case AutofillClient::SUCCESS: | 77 case AutofillClient::SUCCESS: | 
| 57 break; | 78 break; | 
| 58 | 79 | 
| 59 case AutofillClient::TRY_AGAIN_FAILURE: { | 80 case AutofillClient::TRY_AGAIN_FAILURE: { | 
| 60 error_message = l10n_util::GetStringUTF16( | 81 error_message = l10n_util::GetStringUTF16( | 
| 61 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN); | 82 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN); | 
| 62 break; | 83 break; | 
| 63 } | 84 } | 
| 64 | 85 | 
| 65 case AutofillClient::PERMANENT_FAILURE: { | 86 case AutofillClient::PERMANENT_FAILURE: { | 
| 66 error_message = l10n_util::GetStringUTF16( | 87 error_message = l10n_util::GetStringUTF16( | 
| 67 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_PERMANENT); | 88 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_PERMANENT); | 
| 68 allow_retry = false; | |
| 69 break; | 89 break; | 
| 70 } | 90 } | 
| 71 | 91 | 
| 72 case AutofillClient::NETWORK_ERROR: { | 92 case AutofillClient::NETWORK_ERROR: { | 
| 73 error_message = l10n_util::GetStringUTF16( | 93 error_message = l10n_util::GetStringUTF16( | 
| 74 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_NETWORK); | 94 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_NETWORK); | 
| 75 allow_retry = false; | |
| 76 break; | 95 break; | 
| 77 } | 96 } | 
| 78 } | 97 } | 
| 79 | 98 | 
| 80 card_unmask_view_->GotVerificationResult(error_message, allow_retry); | 99 AutofillMetrics::LogRealPanResult(result); | 
| 100 unmasking_allow_retry_ = AllowsRetry(result); | |
| 101 card_unmask_view_->GotVerificationResult(error_message, | |
| 102 AllowsRetry(result)); | |
| 81 } | 103 } | 
| 82 | 104 | 
| 83 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { | 105 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { | 
| 84 card_unmask_view_ = nullptr; | 106 card_unmask_view_ = nullptr; | 
| 107 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.
 
 | |
| 85 delegate_->OnUnmaskPromptClosed(); | 108 delegate_->OnUnmaskPromptClosed(); | 
| 86 } | 109 } | 
| 87 | 110 | 
| 111 void CardUnmaskPromptControllerImpl::LogEvents() { | |
| 112 if (unmasking_number_of_attempts_ == 0) { | |
| 113 AutofillMetrics::LogUnmaskPromptEvent( | |
| 114 AutofillMetrics::UNMASK_PROMPT_CLOSED_NO_ATTEMPTS); | |
| 115 return; | |
| 116 } | |
| 117 | |
| 118 bool final_should_store_pan = | |
| 119 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext()) | |
| 120 ->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState); | |
| 121 | |
| 122 if (unmasking_result_ == AutofillClient::SUCCESS) { | |
| 123 AutofillMetrics::LogUnmaskPromptEvent( | |
| 124 unmasking_number_of_attempts_ == 1 | |
| 125 ? AutofillMetrics::UNMASK_PROMPT_UNMASKED_CARD_FIRST_ATTEMPT | |
| 126 : AutofillMetrics::UNMASK_PROMPT_UNMASKED_CARD_AFTER_FAILED_ATTEMPTS); | |
| 127 if (final_should_store_pan) { | |
| 128 AutofillMetrics::LogUnmaskPromptEvent( | |
| 129 AutofillMetrics::UNMASK_PROMPT_SAVED_CARD_LOCALLY); | |
| 130 } | |
| 131 } else { | |
| 132 AutofillMetrics::LogUnmaskPromptEvent( | |
| 133 AllowsRetry(unmasking_result_) | |
| 134 ? AutofillMetrics | |
| 135 ::UNMASK_PROMPT_CLOSED_FAILED_TO_UNMASK_RETRIABLE_FAILURE | |
| 136 : AutofillMetrics | |
| 137 ::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
 
 | |
| 138 } | |
| 139 | |
| 140 // Tracking changes in local save preference. | |
| 141 { | |
| 
 
Evan Stade
2015/03/19 00:30:34
what is the purpose of this brace
 
Walter Cacau
2015/03/19 00:39:25
Done.
 
 | |
| 142 AutofillMetrics::UnmaskPromptEvent event; | |
| 143 if (unmasking_initial_should_store_pan_ && final_should_store_pan) { | |
| 144 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_OUT; | |
| 145 } else if (!unmasking_initial_should_store_pan_ | |
| 146 && !final_should_store_pan) { | |
| 147 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_IN; | |
| 148 } else if (unmasking_initial_should_store_pan_ | |
| 149 && !final_should_store_pan) { | |
| 150 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_OUT; | |
| 151 } else { | |
| 152 event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_IN; | |
| 153 } | |
| 154 AutofillMetrics::LogUnmaskPromptEvent(event); | |
| 155 } | |
| 156 } | |
| 157 | |
| 88 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( | 158 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( | 
| 89 const base::string16& cvc, | 159 const base::string16& cvc, | 
| 90 const base::string16& exp_month, | 160 const base::string16& exp_month, | 
| 91 const base::string16& exp_year, | 161 const base::string16& exp_year, | 
| 92 bool should_store_pan) { | 162 bool should_store_pan) { | 
| 163 unmasking_number_of_attempts_++; | |
| 93 card_unmask_view_->DisableAndWaitForVerification(); | 164 card_unmask_view_->DisableAndWaitForVerification(); | 
| 94 | 165 | 
| 95 DCHECK(!cvc.empty()); | 166 DCHECK(!cvc.empty()); | 
| 96 pending_response_.cvc = cvc; | 167 pending_response_.cvc = cvc; | 
| 97 if (ShouldRequestExpirationDate()) { | 168 if (ShouldRequestExpirationDate()) { | 
| 98 pending_response_.exp_month = exp_month; | 169 pending_response_.exp_month = exp_month; | 
| 99 pending_response_.exp_year = exp_year; | 170 pending_response_.exp_year = exp_year; | 
| 100 } | 171 } | 
| 101 pending_response_.should_store_pan = should_store_pan; | 172 pending_response_.should_store_pan = should_store_pan; | 
| 102 // Remember the last choice the user made (on this device). | 173 // Remember the last choice the user made (on this device). | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 } | 271 } | 
| 201 | 272 | 
| 202 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( | 273 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( | 
| 203 const std::string& risk_data) { | 274 const std::string& risk_data) { | 
| 204 pending_response_.risk_data = risk_data; | 275 pending_response_.risk_data = risk_data; | 
| 205 if (!pending_response_.cvc.empty()) | 276 if (!pending_response_.cvc.empty()) | 
| 206 delegate_->OnUnmaskResponse(pending_response_); | 277 delegate_->OnUnmaskResponse(pending_response_); | 
| 207 } | 278 } | 
| 208 | 279 | 
| 209 } // namespace autofill | 280 } // namespace autofill | 
| OLD | NEW |