| 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   LogOnCloseEvents(); | 
|   85   delegate_->OnUnmaskPromptClosed(); |  108   delegate_->OnUnmaskPromptClosed(); | 
|   86 } |  109 } | 
|   87  |  110  | 
 |  111 void CardUnmaskPromptControllerImpl::LogOnCloseEvents() { | 
 |  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); | 
 |  138   } | 
 |  139  | 
 |  140   // Tracking changes in local save preference. | 
 |  141   AutofillMetrics::UnmaskPromptEvent event; | 
 |  142   if (unmasking_initial_should_store_pan_ && final_should_store_pan) { | 
 |  143     event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_OUT; | 
 |  144   } else if (!unmasking_initial_should_store_pan_ | 
 |  145              && !final_should_store_pan) { | 
 |  146     event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_IN; | 
 |  147   } else if (unmasking_initial_should_store_pan_ | 
 |  148              && !final_should_store_pan) { | 
 |  149     event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_OUT; | 
 |  150   } else { | 
 |  151     event = AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_IN; | 
 |  152   } | 
 |  153   AutofillMetrics::LogUnmaskPromptEvent(event); | 
 |  154 } | 
 |  155  | 
|   88 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( |  156 void CardUnmaskPromptControllerImpl::OnUnmaskResponse( | 
|   89     const base::string16& cvc, |  157     const base::string16& cvc, | 
|   90     const base::string16& exp_month, |  158     const base::string16& exp_month, | 
|   91     const base::string16& exp_year, |  159     const base::string16& exp_year, | 
|   92     bool should_store_pan) { |  160     bool should_store_pan) { | 
 |  161   unmasking_number_of_attempts_++; | 
|   93   card_unmask_view_->DisableAndWaitForVerification(); |  162   card_unmask_view_->DisableAndWaitForVerification(); | 
|   94  |  163  | 
|   95   DCHECK(!cvc.empty()); |  164   DCHECK(!cvc.empty()); | 
|   96   pending_response_.cvc = cvc; |  165   pending_response_.cvc = cvc; | 
|   97   if (ShouldRequestExpirationDate()) { |  166   if (ShouldRequestExpirationDate()) { | 
|   98     pending_response_.exp_month = exp_month; |  167     pending_response_.exp_month = exp_month; | 
|   99     pending_response_.exp_year = exp_year; |  168     pending_response_.exp_year = exp_year; | 
|  100   } |  169   } | 
|  101   pending_response_.should_store_pan = should_store_pan; |  170   pending_response_.should_store_pan = should_store_pan; | 
|  102   // Remember the last choice the user made (on this device). |  171   // Remember the last choice the user made (on this device). | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  200 } |  269 } | 
|  201  |  270  | 
|  202 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( |  271 void CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint( | 
|  203     const std::string& risk_data) { |  272     const std::string& risk_data) { | 
|  204   pending_response_.risk_data = risk_data; |  273   pending_response_.risk_data = risk_data; | 
|  205   if (!pending_response_.cvc.empty()) |  274   if (!pending_response_.cvc.empty()) | 
|  206     delegate_->OnUnmaskResponse(pending_response_); |  275     delegate_->OnUnmaskResponse(pending_response_); | 
|  207 } |  276 } | 
|  208  |  277  | 
|  209 }  // namespace autofill |  278 }  // namespace autofill | 
| OLD | NEW |