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.app.ProgressDialog; | 7 import android.app.ProgressDialog; |
8 import android.os.Handler; | 8 import android.os.Handler; |
9 import android.util.Pair; | 9 import android.util.Pair; |
10 | 10 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 // This should be called when all required fields are put in mAddres
sField. | 328 // This should be called when all required fields are put in mAddres
sField. |
329 setAddressFieldValuesFromCache(); | 329 setAddressFieldValuesFromCache(); |
330 addAddressFieldsToEditor( | 330 addAddressFieldsToEditor( |
331 mProfile.getCountryCode(), mProfile.getLanguageCode(), admin
Areas); | 331 mProfile.getCountryCode(), mProfile.getLanguageCode(), admin
Areas); |
332 mEditorDialog.show(mEditor); | 332 mEditorDialog.show(mEditor); |
333 } | 333 } |
334 } | 334 } |
335 | 335 |
336 /** Requests the list of admin areas. */ | 336 /** Requests the list of admin areas. */ |
337 private void loadAdminAreasForCountry(String countryCode) { | 337 private void loadAdminAreasForCountry(String countryCode) { |
338 // Used to check if the callback is called (for time-out). | 338 // Used to check if the callback is called (for the cancellation). |
339 mAdminAreasLoaded = false; | 339 mAdminAreasLoaded = false; |
340 | 340 |
341 onAdminAreasLoading(); | 341 // For tests, the time-out is set to 0. In this case, we should not |
| 342 // fetch the admin-areas, and show a text-field instead. |
| 343 // This is to have the tests independent of the network status. |
| 344 if (PersonalDataManager.getInstance().getRequestTimeoutMS() == 0) { |
| 345 onSubKeysReceived(null); |
| 346 return; |
| 347 } |
| 348 |
342 // In each rule, admin area keys are saved under sub-keys of country. | 349 // In each rule, admin area keys are saved under sub-keys of country. |
343 PersonalDataManager.getInstance().loadRulesForSubKeys(countryCode); | 350 PersonalDataManager.getInstance().loadRulesForSubKeys(countryCode); |
344 PersonalDataManager.getInstance().getRegionSubKeys(countryCode, this); | 351 PersonalDataManager.getInstance().getRegionSubKeys(countryCode, this); |
345 } | 352 } |
346 | 353 |
347 /** Cancels the request for the list of admin areas. */ | |
348 private void cancelAdminAreasRequest() { | |
349 if (mAdminAreasLoaded) return; | |
350 onSubKeysReceived(null); | |
351 PersonalDataManager.getInstance().cancelPendingGetSubKeys(); | |
352 } | |
353 | |
354 /** | 354 /** |
355 * In case the the admin areas are not loaded yet, or the time out is set to
0 for testing, | |
356 * starts a timer to cancel the request. | |
357 */ | |
358 public void onAdminAreasLoading() { | |
359 if (mAdminAreasLoaded) return; | |
360 // Handler().postDelayed sometimes adds an additional delay to the time-
out, | |
361 // therefore the case for time-out == 0 is checked initially. | |
362 if (PersonalDataManager.getInstance().getRequestTimeoutMS() == 0) { | |
363 cancelAdminAreasRequest(); | |
364 return; | |
365 } | |
366 new Handler().postDelayed(new Runnable() { | |
367 @Override | |
368 public void run() { | |
369 cancelAdminAreasRequest(); | |
370 } | |
371 }, PersonalDataManager.getInstance().getRequestTimeoutMS()); | |
372 } | |
373 | |
374 /** | |
375 * Adds fields to the editor model based on the country and language code of | 355 * Adds fields to the editor model based on the country and language code of |
376 * the profile that's being edited. | 356 * the profile that's being edited. |
377 */ | 357 */ |
378 private void addAddressFieldsToEditor( | 358 private void addAddressFieldsToEditor( |
379 String countryCode, String languageCode, String[] adminAreas) { | 359 String countryCode, String languageCode, String[] adminAreas) { |
380 mAddressUiComponents = | 360 mAddressUiComponents = |
381 mAutofillProfileBridge.getAddressUiComponents(countryCode, langu
ageCode); | 361 mAutofillProfileBridge.getAddressUiComponents(countryCode, langu
ageCode); |
382 // In terms of order, country must be the first field. | 362 // In terms of order, country must be the first field. |
383 mEditor.addField(mCountryField); | 363 mEditor.addField(mCountryField); |
384 for (int i = 0; i < mAddressUiComponents.size(); i++) { | 364 for (int i = 0; i < mAddressUiComponents.size(); i++) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 399 |
420 @Override | 400 @Override |
421 public boolean isLengthMaximum(@Nullable CharSequence value) { | 401 public boolean isLengthMaximum(@Nullable CharSequence value) { |
422 return false; | 402 return false; |
423 } | 403 } |
424 }; | 404 }; |
425 } | 405 } |
426 return mPhoneValidator; | 406 return mPhoneValidator; |
427 } | 407 } |
428 } | 408 } |
OLD | NEW |