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_success_(false), | |
| 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_success_ = false; | |
| 55 unmasking_number_of_attempts_ = 0; | |
| 56 unmasking_initial_should_store_pan_ = GetStoreLocallyStartState(); | |
| 57 AutofillMetrics::LogUnmaskPromptEvent(AutofillMetrics::UNMASK_PROMPT_SHOWN); | |
| 46 } | 58 } | 
| 47 | 59 | 
| 48 void CardUnmaskPromptControllerImpl::OnVerificationResult( | 60 void CardUnmaskPromptControllerImpl::OnVerificationResult( | 
| 49 AutofillClient::GetRealPanResult result) { | 61 AutofillClient::GetRealPanResult result) { | 
| 50 if (!card_unmask_view_) | 62 if (!card_unmask_view_) | 
| 51 return; | 63 return; | 
| 52 | 64 | 
| 53 base::string16 error_message; | 65 base::string16 error_message; | 
| 54 bool allow_retry = true; | 66 bool allow_retry = true; | 
| 55 switch (result) { | 67 switch (result) { | 
| 56 case AutofillClient::SUCCESS: | 68 case AutofillClient::SUCCESS: { | 
| 69 unmasking_success_ = true; | |
| 70 AutofillMetrics::LogUnmaskPromptEvent( | |
| 
 
Evan Stade
2015/03/18 21:29:07
you can move this logging down to OnUnmaskDialogCl
 
Walter Cacau
2015/03/18 23:50:05
Done.
Also extracted that code to a method to mak
 
 | |
| 71 AutofillMetrics::UNMASK_PROMPT_UNMASKED_CARD); | |
| 72 bool final_should_store_pan = | |
| 73 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext()) | |
| 74 ->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState); | |
| 75 if (final_should_store_pan) { | |
| 76 AutofillMetrics::LogUnmaskPromptEvent( | |
| 77 AutofillMetrics::UNMASK_PROMPT_SAVED_CARD_LOCALLY); | |
| 78 } | |
| 57 break; | 79 break; | 
| 80 } | |
| 58 | 81 | 
| 59 case AutofillClient::TRY_AGAIN_FAILURE: { | 82 case AutofillClient::TRY_AGAIN_FAILURE: { | 
| 60 error_message = l10n_util::GetStringUTF16( | 83 error_message = l10n_util::GetStringUTF16( | 
| 61 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN); | 84 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_TRY_AGAIN); | 
| 62 break; | 85 break; | 
| 63 } | 86 } | 
| 64 | 87 | 
| 65 case AutofillClient::PERMANENT_FAILURE: { | 88 case AutofillClient::PERMANENT_FAILURE: { | 
| 66 error_message = l10n_util::GetStringUTF16( | 89 error_message = l10n_util::GetStringUTF16( | 
| 67 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_PERMANENT); | 90 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_PERMANENT); | 
| 68 allow_retry = false; | 91 allow_retry = false; | 
| 69 break; | 92 break; | 
| 70 } | 93 } | 
| 71 | 94 | 
| 72 case AutofillClient::NETWORK_ERROR: { | 95 case AutofillClient::NETWORK_ERROR: { | 
| 73 error_message = l10n_util::GetStringUTF16( | 96 error_message = l10n_util::GetStringUTF16( | 
| 74 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_NETWORK); | 97 IDS_AUTOFILL_CARD_UNMASK_PROMPT_ERROR_NETWORK); | 
| 75 allow_retry = false; | 98 allow_retry = false; | 
| 76 break; | 99 break; | 
| 77 } | 100 } | 
| 78 } | 101 } | 
| 79 | 102 | 
| 80 card_unmask_view_->GotVerificationResult(error_message, allow_retry); | 103 card_unmask_view_->GotVerificationResult(error_message, allow_retry); | 
| 81 } | 104 } | 
| 82 | 105 | 
| 83 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { | 106 void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() { | 
| 84 card_unmask_view_ = nullptr; | 107 card_unmask_view_ = nullptr; | 
| 108 if (!unmasking_success_) { | |
| 109 if (unmasking_number_of_attempts_ > 0) { | |
| 
 
Evan Stade
2015/03/18 01:47:59
nit: use ternary operator
 
Walter Cacau
2015/03/18 17:04:54
Done.
 
 | |
| 110 AutofillMetrics::LogUnmaskPromptEvent( | |
| 111 AutofillMetrics::UNMASK_PROMPT_CLOSED_FAILED_TO_UNMASK); | |
| 112 } else { | |
| 113 AutofillMetrics::LogUnmaskPromptEvent( | |
| 114 AutofillMetrics::UNMASK_PROMPT_CLOSED_NO_ATTEMPTS); | |
| 115 } | |
| 116 } | |
| 117 if (unmasking_number_of_attempts_ > 0) { | |
| 118 bool final_should_store_pan = | |
| 119 user_prefs::UserPrefs::Get(web_contents_->GetBrowserContext()) | |
| 120 ->GetBoolean(prefs::kAutofillWalletImportStorageCheckboxState); | |
| 
 
Evan Stade
2015/03/18 01:47:59
final_should_store_pan needs to come from the para
 
Walter Cacau
2015/03/18 17:04:54
Shouldn't we care? IMHO, it is changing chrome sta
 
Evan Stade
2015/03/18 21:29:07
ok
 
 | |
| 121 if (unmasking_initial_should_store_pan_ && final_should_store_pan) { | |
| 122 AutofillMetrics::LogUnmaskPromptEvent( | |
| 
 
Evan Stade
2015/03/18 01:47:59
nit: pull out LogUnmaskPromptEvent so it looks lik
 
Walter Cacau
2015/03/18 17:04:54
Done.
 
 | |
| 123 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_OUT); | |
| 124 } else if (!unmasking_initial_should_store_pan_ | |
| 125 && !final_should_store_pan) { | |
| 126 AutofillMetrics::LogUnmaskPromptEvent( | |
| 127 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_IN); | |
| 128 } else if (unmasking_initial_should_store_pan_ && !final_should_store_pan) { | |
| 129 AutofillMetrics::LogUnmaskPromptEvent( | |
| 130 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_OUT); | |
| 131 } else { | |
| 132 AutofillMetrics::LogUnmaskPromptEvent( | |
| 133 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_IN); | |
| 134 } | |
| 135 } | |
| 85 delegate_->OnUnmaskPromptClosed(); | 136 delegate_->OnUnmaskPromptClosed(); | 
| 86 } | 137 } | 
| 87 | 138 | 
| 88 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( | 139 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( | 
| 89 const base::string16& cvc, | 140 const base::string16& cvc, | 
| 90 const base::string16& exp_month, | 141 const base::string16& exp_month, | 
| 91 const base::string16& exp_year, | 142 const base::string16& exp_year, | 
| 92 bool should_store_pan) { | 143 bool should_store_pan) { | 
| 144 unmasking_number_of_attempts_++; | |
| 93 card_unmask_view_->DisableAndWaitForVerification(); | 145 card_unmask_view_->DisableAndWaitForVerification(); | 
| 94 | 146 | 
| 95 DCHECK(!cvc.empty()); | 147 DCHECK(!cvc.empty()); | 
| 96 pending_response_.cvc = cvc; | 148 pending_response_.cvc = cvc; | 
| 97 if (ShouldRequestExpirationDate()) { | 149 if (ShouldRequestExpirationDate()) { | 
| 98 pending_response_.exp_month = exp_month; | 150 pending_response_.exp_month = exp_month; | 
| 99 pending_response_.exp_year = exp_year; | 151 pending_response_.exp_year = exp_year; | 
| 100 } | 152 } | 
| 101 pending_response_.should_store_pan = should_store_pan; | 153 pending_response_.should_store_pan = should_store_pan; | 
| 102 // Remember the last choice the user made (on this device). | 154 // Remember the last choice the user made (on this device). | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 } | 252 } | 
| 201 | 253 | 
| 202 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( | 254 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( | 
| 203 const std::string& risk_data) { | 255 const std::string& risk_data) { | 
| 204 pending_response_.risk_data = risk_data; | 256 pending_response_.risk_data = risk_data; | 
| 205 if (!pending_response_.cvc.empty()) | 257 if (!pending_response_.cvc.empty()) | 
| 206 delegate_->OnUnmaskResponse(pending_response_); | 258 delegate_->OnUnmaskResponse(pending_response_); | 
| 207 } | 259 } | 
| 208 | 260 | 
| 209 } // namespace autofill | 261 } // namespace autofill | 
| OLD | NEW |