Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "components/autofill/core/browser/payments/full_card_request.h" | 5 #include "components/autofill/core/browser/payments/full_card_request.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 autofill_client_->LoadRiskData( | 61 autofill_client_->LoadRiskData( |
| 62 base::Bind(&FullCardRequest::OnDidGetUnmaskRiskData, | 62 base::Bind(&FullCardRequest::OnDidGetUnmaskRiskData, |
| 63 weak_ptr_factory_.GetWeakPtr())); | 63 weak_ptr_factory_.GetWeakPtr())); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool FullCardRequest::IsGettingFullCard() const { | 67 bool FullCardRequest::IsGettingFullCard() const { |
| 68 return !!request_; | 68 return !!request_; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // TODO(crbug.com/656981): Update the credit card expiration on file. | 71 // TODO(crbug.com/656981): Update the credit card expiration on file. |
|
please use gerrit instead
2016/10/26 15:23:04
Remove the todo
sebsg
2016/10/26 17:17:32
Done.
| |
| 72 void FullCardRequest::OnUnmaskResponse(const UnmaskResponse& response) { | 72 void FullCardRequest::OnUnmaskResponse(const UnmaskResponse& response) { |
| 73 if (!response.exp_month.empty()) | 73 if (request_->card.record_type() == CreditCard::LOCAL_CARD) { |
| 74 request_->card.SetRawInfo(CREDIT_CARD_EXP_MONTH, response.exp_month); | 74 // It's a local card. Update the cached version and update the database. |
| 75 // Then update the response. | |
| 76 CreditCard* credit_card = | |
| 77 personal_data_manager_->GetCreditCardByGUID(request_->card.guid()); | |
| 75 | 78 |
| 76 if (!response.exp_year.empty()) | 79 if (!response.exp_month.empty()) |
| 77 request_->card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, response.exp_year); | 80 credit_card->SetRawInfo(CREDIT_CARD_EXP_MONTH, response.exp_month); |
| 78 | 81 |
| 79 if (request_->card.record_type() == CreditCard::LOCAL_CARD && | 82 if (!response.exp_year.empty()) |
| 80 !request_->card.guid().empty() && | 83 credit_card->SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, response.exp_year); |
| 81 (!response.exp_month.empty() || !response.exp_year.empty())) { | 84 |
| 82 personal_data_manager_->UpdateCreditCard(request_->card); | 85 // Update the cached card here so the new data is availble before the |
| 86 // database update and refresh of the cache is completed. | |
| 87 if (!response.exp_month.empty() || !response.exp_year.empty()) { | |
| 88 personal_data_manager_->UpdateCreditCard(*credit_card); | |
|
please use gerrit instead
2016/10/26 15:23:04
Can we update the cache inside of UpdateCreditCard
sebsg
2016/10/26 17:17:32
Done.
| |
| 89 | |
| 90 request_->card = *credit_card; | |
| 91 } | |
| 92 } else { | |
| 93 // It's not a local card, update the response. | |
| 94 if (!response.exp_month.empty()) | |
| 95 request_->card.SetRawInfo(CREDIT_CARD_EXP_MONTH, response.exp_month); | |
| 96 | |
| 97 if (!response.exp_year.empty()) { | |
| 98 request_->card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, | |
| 99 response.exp_year); | |
| 100 } | |
| 83 } | 101 } |
| 84 | 102 |
| 85 if (!should_unmask_card_) { | 103 if (!should_unmask_card_) { |
| 86 if (delegate_) | 104 if (delegate_) |
| 87 delegate_->OnFullCardRequestSucceeded(request_->card, response.cvc); | 105 delegate_->OnFullCardRequestSucceeded(request_->card, response.cvc); |
| 88 Reset(); | 106 Reset(); |
| 89 autofill_client_->OnUnmaskVerificationResult(AutofillClient::SUCCESS); | 107 autofill_client_->OnUnmaskVerificationResult(AutofillClient::SUCCESS); |
| 90 return; | 108 return; |
| 91 } | 109 } |
| 92 | 110 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 void FullCardRequest::Reset() { | 177 void FullCardRequest::Reset() { |
| 160 weak_ptr_factory_.InvalidateWeakPtrs(); | 178 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 161 payments_client_->CancelRequest(); | 179 payments_client_->CancelRequest(); |
| 162 delegate_ = nullptr; | 180 delegate_ = nullptr; |
| 163 request_.reset(); | 181 request_.reset(); |
| 164 should_unmask_card_ = false; | 182 should_unmask_card_ = false; |
| 165 } | 183 } |
| 166 | 184 |
| 167 } // namespace payments | 185 } // namespace payments |
| 168 } // namespace autofill | 186 } // namespace autofill |
| OLD | NEW |