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 package org.chromium.chrome.browser.payments; | 5 package org.chromium.chrome.browser.payments; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.os.Handler; | |
| 9 import android.text.TextUtils; | 8 import android.text.TextUtils; |
| 10 import android.util.JsonWriter; | 9 import android.util.JsonWriter; |
| 11 | 10 |
| 12 import org.chromium.base.ApiCompatibilityUtils; | 11 import org.chromium.base.ApiCompatibilityUtils; |
| 13 import org.chromium.chrome.R; | 12 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.ChromeActivity; | 13 import org.chromium.chrome.browser.ChromeActivity; |
| 15 import org.chromium.chrome.browser.autofill.PersonalDataManager; | 14 import org.chromium.chrome.browser.autofill.PersonalDataManager; |
| 16 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 15 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| 17 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; | 16 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
| 18 import org.chromium.chrome.browser.autofill.PersonalDataManager.FullCardRequestD elegate; | 17 import org.chromium.chrome.browser.autofill.PersonalDataManager.FullCardRequestD elegate; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 == AutofillAddress.COMPLETE; | 92 == AutofillAddress.COMPLETE; |
| 94 assert mIsComplete; | 93 assert mIsComplete; |
| 95 assert mHasValidNumberAndName; | 94 assert mHasValidNumberAndName; |
| 96 assert mCallback == null; | 95 assert mCallback == null; |
| 97 mCallback = callback; | 96 mCallback = callback; |
| 98 | 97 |
| 99 mIsWaitingForBillingNormalization = true; | 98 mIsWaitingForBillingNormalization = true; |
| 100 mIsWaitingForFullCardDetails = true; | 99 mIsWaitingForFullCardDetails = true; |
| 101 | 100 |
| 102 // Start the billing address normalization. | 101 // Start the billing address normalization. |
| 103 PersonalDataManager.getInstance().normalizeAddress( | 102 PersonalDataManager.getInstance().normalizeAddress(mBillingAddress.getGU ID(), |
| 104 mBillingAddress.getGUID(), AutofillAddress.getCountryCode(mBilli ngAddress), this); | 103 AutofillAddress.getCountryCode(mBillingAddress), |
| 104 PersonalDataManager.getInstance().getNormalizationTimeoutSeconds (), this); | |
| 105 | 105 |
| 106 // Start to get the full card details. | 106 // Start to get the full card details. |
| 107 PersonalDataManager.getInstance().getFullCard(mWebContents, mCard, this) ; | 107 PersonalDataManager.getInstance().getFullCard(mWebContents, mCard, this) ; |
| 108 } | 108 } |
| 109 | 109 |
| 110 @Override | 110 @Override |
| 111 public void onFullCardDetails(CreditCard updatedCard, String cvc) { | 111 public void onFullCardDetails(CreditCard updatedCard, String cvc) { |
| 112 // Keep the cvc for after the normalization. | 112 // Keep the cvc for after the normalization. |
| 113 mSecurityCode = cvc; | 113 mSecurityCode = cvc; |
| 114 | 114 |
| 115 // The card number changes for unmasked cards. | 115 // The card number changes for unmasked cards. |
| 116 assert updatedCard.getNumber().length() > 4; | 116 assert updatedCard.getNumber().length() > 4; |
| 117 mCard.setNumber(updatedCard.getNumber()); | 117 mCard.setNumber(updatedCard.getNumber()); |
| 118 | 118 |
| 119 // Update the card's expiration date. | 119 // Update the card's expiration date. |
| 120 mCard.setMonth(updatedCard.getMonth()); | 120 mCard.setMonth(updatedCard.getMonth()); |
| 121 mCard.setYear(updatedCard.getYear()); | 121 mCard.setYear(updatedCard.getYear()); |
| 122 | 122 |
| 123 mIsWaitingForFullCardDetails = false; | 123 mIsWaitingForFullCardDetails = false; |
| 124 | 124 |
| 125 // Show the loading UI while the address gets normalized. | 125 // Show the loading UI while the address gets normalized. |
| 126 mCallback.onInstrumentDetailsLoadingWithoutUI(); | 126 mCallback.onInstrumentDetailsLoadingWithoutUI(); |
| 127 | 127 |
| 128 // Wait for the billing address normalization before sending the instrum ent details. | 128 // Wait for the billing address normalization before sending the instrum ent details. |
| 129 if (mIsWaitingForBillingNormalization) { | 129 if (mIsWaitingForBillingNormalization) return; |
|
please use gerrit instead
2017/02/21 17:15:12
Collapse 3 lines into 1:
if (!mIsWaitingForBillin
sebsg
2017/02/21 18:30:59
Done.
| |
| 130 // If the normalization is not completed yet, Start a timer to cance l it if it takes too | |
| 131 // long. | |
| 132 new Handler().postDelayed(new Runnable() { | |
| 133 @Override | |
| 134 public void run() { | |
| 135 onAddressNormalized(null); | |
| 136 } | |
| 137 }, PersonalDataManager.getInstance().getNormalizationTimeoutMS()); | |
| 138 | 130 |
| 139 return; | 131 sendIntrumentDetails(); |
|
Mathieu
2017/02/21 17:40:43
Instrument?
sebsg
2017/02/21 18:30:59
Done.
| |
| 140 } else { | |
| 141 sendIntrumentDetails(); | |
| 142 } | |
| 143 } | 132 } |
| 144 | 133 |
| 145 @Override | 134 @Override |
| 146 public void onAddressNormalized(AutofillProfile profile) { | 135 public void onAddressNormalized(AutofillProfile profile) { |
| 147 if (!mIsWaitingForBillingNormalization) return; | 136 if (!mIsWaitingForBillingNormalization) return; |
| 148 mIsWaitingForBillingNormalization = false; | 137 mIsWaitingForBillingNormalization = false; |
| 149 | 138 |
| 150 // If the normalization finished first, use the normalized address. | 139 // If the normalization finished first, use the normalized address. |
| 151 if (profile != null) mBillingAddress = profile; | 140 if (profile != null) mBillingAddress = profile; |
| 152 | 141 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 /** @return The credit card represented by this payment instrument. */ | 326 /** @return The credit card represented by this payment instrument. */ |
| 338 public CreditCard getCard() { | 327 public CreditCard getCard() { |
| 339 return mCard; | 328 return mCard; |
| 340 } | 329 } |
| 341 | 330 |
| 342 /** @return The billing address associated with this credit card. */ | 331 /** @return The billing address associated with this credit card. */ |
| 343 public AutofillProfile getBillingAddress() { | 332 public AutofillProfile getBillingAddress() { |
| 344 return mBillingAddress; | 333 return mBillingAddress; |
| 345 } | 334 } |
| 346 } | 335 } |
| OLD | NEW |