Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/autofill/core/browser/full_card_request.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "components/autofill/core/browser/autofill_client.h" | |
| 11 #include "components/autofill/core/browser/autofill_metrics.h" | |
| 12 #include "components/autofill/core/browser/credit_card.h" | |
| 13 #include "components/autofill/core/browser/personal_data_manager.h" | |
| 14 | |
| 15 namespace autofill { | |
| 16 | |
| 17 FullCardRequest::FullCardRequest(net::URLRequestContextGetter* url_getter, | |
| 18 AutofillClient* autofill_client, | |
| 19 PersonalDataManager* personal_data_manager) | |
| 20 : autofill_client_(autofill_client), | |
| 21 personal_data_manager_(personal_data_manager), | |
| 22 delegate_(nullptr), | |
| 23 payments_client_(url_getter, this), | |
|
Mathieu
2016/04/22 17:58:35
could PaymentsClient be an argument to the constru
please use gerrit instead
2016/04/22 20:50:18
Done.
| |
| 24 weak_ptr_factory_(this) { | |
| 25 DCHECK(autofill_client_); | |
| 26 DCHECK(personal_data_manager_); | |
| 27 } | |
| 28 | |
| 29 FullCardRequest::~FullCardRequest() {} | |
| 30 | |
| 31 void FullCardRequest::GetFullCard(const CreditCard& card, | |
| 32 AutofillClient::UnmaskCardReason reason, | |
| 33 base::WeakPtr<Delegate> delegate) { | |
| 34 DCHECK(delegate); | |
| 35 if (delegate_) { | |
|
Mathieu
2016/04/22 17:58:35
Please add a comment since this is not immediately
please use gerrit instead
2016/04/22 20:50:18
Done.
| |
| 36 delegate->OnFullCardError(); | |
| 37 return; | |
| 38 } | |
| 39 | |
| 40 delegate_ = delegate; | |
| 41 request_.reset(new payments::PaymentsClient::UnmaskRequestDetails); | |
| 42 request_->card = card; | |
| 43 bool is_masked = card.record_type() == CreditCard::MASKED_SERVER_CARD; | |
| 44 if (is_masked) | |
| 45 payments_client_.Prepare(); | |
| 46 | |
| 47 autofill_client_->ShowUnmaskPrompt(request_->card, reason, | |
| 48 weak_ptr_factory_.GetWeakPtr()); | |
| 49 | |
| 50 if (is_masked) { | |
| 51 autofill_client_->LoadRiskData( | |
| 52 base::Bind(&FullCardRequest::OnDidGetUnmaskRiskData, | |
| 53 weak_ptr_factory_.GetWeakPtr())); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 bool FullCardRequest::IsGettingFullCard() const { | |
| 58 return !!request_; | |
| 59 } | |
| 60 | |
| 61 void FullCardRequest::OnDidGetUnmaskRiskData(const std::string& risk_data) { | |
| 62 request_->risk_data = risk_data; | |
| 63 if (!request_->user_response.cvc.empty()) { | |
| 64 real_pan_request_timestamp_ = base::Time::Now(); | |
| 65 payments_client_.UnmaskCard(*request_); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void FullCardRequest::OnUnmaskResponse(const UnmaskResponse& response) { | |
| 70 if (!response.exp_month.empty()) | |
| 71 request_->card.SetRawInfo(CREDIT_CARD_EXP_MONTH, response.exp_month); | |
| 72 | |
| 73 if (!response.exp_year.empty()) | |
| 74 request_->card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, response.exp_year); | |
| 75 | |
| 76 if (request_->card.record_type() != CreditCard::MASKED_SERVER_CARD) { | |
| 77 if (delegate_) | |
| 78 delegate_->OnFullCardDetails(request_->card, response.cvc); | |
| 79 delegate_ = nullptr; | |
| 80 autofill_client_->OnUnmaskVerificationResult(AutofillClient::SUCCESS); | |
| 81 request_.reset(); | |
| 82 return; | |
| 83 } | |
| 84 | |
| 85 request_->user_response = response; | |
| 86 if (!request_->risk_data.empty()) { | |
| 87 real_pan_request_timestamp_ = base::Time::Now(); | |
| 88 payments_client_.UnmaskCard(*request_); | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 void FullCardRequest::OnUnmaskPromptClosed() { | |
| 93 if (delegate_) | |
| 94 delegate_->OnFullCardError(); | |
| 95 | |
| 96 delegate_ = nullptr; | |
| 97 payments_client_.CancelRequest(); | |
| 98 request_.reset(); | |
| 99 } | |
| 100 | |
| 101 IdentityProvider* FullCardRequest::GetIdentityProvider() { | |
| 102 return autofill_client_->GetIdentityProvider(); | |
| 103 } | |
| 104 | |
| 105 void FullCardRequest::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, | |
| 106 const std::string& real_pan) { | |
| 107 AutofillMetrics::LogRealPanDuration( | |
| 108 base::Time::Now() - real_pan_request_timestamp_, result); | |
| 109 | |
| 110 if (!real_pan.empty()) { | |
| 111 DCHECK_EQ(AutofillClient::SUCCESS, result); | |
| 112 request_->card.set_record_type(CreditCard::FULL_SERVER_CARD); | |
| 113 request_->card.SetNumber(base::UTF8ToUTF16(real_pan)); | |
| 114 | |
| 115 if (request_->user_response.should_store_pan) | |
| 116 personal_data_manager_->UpdateServerCreditCard(request_->card); | |
| 117 | |
| 118 if (delegate_) | |
| 119 delegate_->OnFullCardDetails(request_->card, request_->user_response.cvc); | |
| 120 } else { | |
| 121 if (delegate_) | |
| 122 delegate_->OnFullCardError(); | |
| 123 } | |
| 124 | |
| 125 delegate_ = nullptr; | |
| 126 autofill_client_->OnUnmaskVerificationResult(result); | |
| 127 request_.reset(); | |
| 128 } | |
| 129 | |
| 130 void FullCardRequest::OnDidGetUploadDetails( | |
| 131 AutofillClient::PaymentsRpcResult result, | |
| 132 const base::string16& context_token, | |
| 133 std::unique_ptr<base::DictionaryValue> legal_message) { | |
| 134 NOTREACHED(); | |
| 135 } | |
| 136 | |
| 137 void FullCardRequest::OnDidUploadCard( | |
| 138 AutofillClient::PaymentsRpcResult result) { | |
| 139 NOTREACHED(); | |
| 140 } | |
| 141 | |
| 142 } // namespace autofill | |
| OLD | NEW |