OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.autofill; | 5 package org.chromium.chrome.browser.autofill; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 | 8 |
9 import org.chromium.base.ThreadUtils; | 9 import org.chromium.base.ThreadUtils; |
10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 | 479 |
480 public List<AutofillProfile> getAddressOnlyProfiles() { | 480 public List<AutofillProfile> getAddressOnlyProfiles() { |
481 return getProfilesWithAddressOnlyLabels(true); | 481 return getProfilesWithAddressOnlyLabels(true); |
482 } | 482 } |
483 | 483 |
484 private List<AutofillProfile> getProfilesWithAddressOnlyLabels(boolean addre ssOnly) { | 484 private List<AutofillProfile> getProfilesWithAddressOnlyLabels(boolean addre ssOnly) { |
485 ThreadUtils.assertOnUiThread(); | 485 ThreadUtils.assertOnUiThread(); |
486 | 486 |
487 String[] profileLabels = nativeGetProfileLabels(mPersonalDataManagerAndr oid, addressOnly); | 487 String[] profileLabels = nativeGetProfileLabels(mPersonalDataManagerAndr oid, addressOnly); |
488 | 488 |
489 int profileCount = nativeGetProfileCount(mPersonalDataManagerAndroid); | 489 String[] profileGUIDs = nativeGetProfileGUIDsToSuggest(mPersonalDataMana gerAndroid); |
Mathieu
2016/05/20 13:57:08
Why do we need to get the GUIDs before the profile
sebsg
2016/05/24 17:27:32
I was unsure myself. Here is what I asked in anoth
Mathieu
2016/05/24 17:54:48
It does seem difficult. I'm fine with this solutio
| |
490 List<AutofillProfile> profiles = new ArrayList<AutofillProfile>(profileC ount); | 490 |
491 for (int i = 0; i < profileCount; i++) { | 491 List<AutofillProfile> profiles = new ArrayList<AutofillProfile>(profileG UIDs.length); |
492 AutofillProfile profile = nativeGetProfileByIndex(mPersonalDataManag erAndroid, i); | 492 for (int i = 0; i < profileGUIDs.length; i++) { |
493 AutofillProfile profile = | |
494 nativeGetProfileByGUID(mPersonalDataManagerAndroid, profileG UIDs[i]); | |
493 profile.setLabel(profileLabels[i]); | 495 profile.setLabel(profileLabels[i]); |
494 profiles.add(profile); | 496 profiles.add(profile); |
495 } | 497 } |
496 | 498 |
497 return profiles; | 499 return profiles; |
498 } | 500 } |
499 | 501 |
500 public AutofillProfile getProfile(String guid) { | 502 public AutofillProfile getProfile(String guid) { |
501 ThreadUtils.assertOnUiThread(); | 503 ThreadUtils.assertOnUiThread(); |
502 return nativeGetProfileByGUID(mPersonalDataManagerAndroid, guid); | 504 return nativeGetProfileByGUID(mPersonalDataManagerAndroid, guid); |
503 } | 505 } |
504 | 506 |
505 public void deleteProfile(String guid) { | 507 public void deleteProfile(String guid) { |
506 ThreadUtils.assertOnUiThread(); | 508 ThreadUtils.assertOnUiThread(); |
507 nativeRemoveByGUID(mPersonalDataManagerAndroid, guid); | 509 nativeRemoveByGUID(mPersonalDataManagerAndroid, guid); |
508 } | 510 } |
509 | 511 |
510 public String setProfile(AutofillProfile profile) { | 512 public String setProfile(AutofillProfile profile) { |
511 ThreadUtils.assertOnUiThread(); | 513 ThreadUtils.assertOnUiThread(); |
512 return nativeSetProfile(mPersonalDataManagerAndroid, profile); | 514 return nativeSetProfile(mPersonalDataManagerAndroid, profile); |
513 } | 515 } |
514 | 516 |
515 public List<CreditCard> getCreditCards() { | 517 public List<CreditCard> getCreditCards() { |
516 ThreadUtils.assertOnUiThread(); | 518 ThreadUtils.assertOnUiThread(); |
517 int count = nativeGetCreditCardCount(mPersonalDataManagerAndroid); | 519 |
518 List<CreditCard> cards = new ArrayList<CreditCard>(count); | 520 String[] creditCardGUIDs = nativeGetCreditCardGUIDsToSuggest(mPersonalDa taManagerAndroid); |
519 for (int i = 0; i < count; i++) { | 521 |
520 cards.add(nativeGetCreditCardByIndex(mPersonalDataManagerAndroid, i) ); | 522 List<CreditCard> cards = new ArrayList<CreditCard>(creditCardGUIDs.lengt h); |
523 for (int i = 0; i < creditCardGUIDs.length; i++) { | |
524 cards.add(nativeGetCreditCardByGUID(mPersonalDataManagerAndroid, cre ditCardGUIDs[i])); | |
521 } | 525 } |
522 return cards; | 526 return cards; |
523 } | 527 } |
524 | 528 |
525 public CreditCard getCreditCard(String guid) { | 529 public CreditCard getCreditCard(String guid) { |
526 ThreadUtils.assertOnUiThread(); | 530 ThreadUtils.assertOnUiThread(); |
527 return nativeGetCreditCardByGUID(mPersonalDataManagerAndroid, guid); | 531 return nativeGetCreditCardByGUID(mPersonalDataManagerAndroid, guid); |
528 } | 532 } |
529 | 533 |
530 public String setCreditCard(CreditCard card) { | 534 public String setCreditCard(CreditCard card) { |
531 ThreadUtils.assertOnUiThread(); | 535 ThreadUtils.assertOnUiThread(); |
532 return nativeSetCreditCard(mPersonalDataManagerAndroid, card); | 536 return nativeSetCreditCard(mPersonalDataManagerAndroid, card); |
533 } | 537 } |
534 | 538 |
535 public void deleteCreditCard(String guid) { | 539 public void deleteCreditCard(String guid) { |
536 ThreadUtils.assertOnUiThread(); | 540 ThreadUtils.assertOnUiThread(); |
537 nativeRemoveByGUID(mPersonalDataManagerAndroid, guid); | 541 nativeRemoveByGUID(mPersonalDataManagerAndroid, guid); |
538 } | 542 } |
539 | 543 |
540 public void clearUnmaskedCache(String guid) { | 544 public void clearUnmaskedCache(String guid) { |
541 nativeClearUnmaskedCache(mPersonalDataManagerAndroid, guid); | 545 nativeClearUnmaskedCache(mPersonalDataManagerAndroid, guid); |
542 } | 546 } |
543 | 547 |
544 public void getFullCard(WebContents webContents, String guid, | 548 public void getFullCard(WebContents webContents, String guid, |
545 FullCardRequestDelegate delegate) { | 549 FullCardRequestDelegate delegate) { |
546 nativeGetFullCardForPaymentRequest( | 550 nativeGetFullCardForPaymentRequest( |
547 mPersonalDataManagerAndroid, webContents, guid, delegate); | 551 mPersonalDataManagerAndroid, webContents, guid, delegate); |
548 } | 552 } |
549 | 553 |
554 @VisibleForTesting | |
555 public void setProfileUseStatsForTest(String guid, int count, int date) { | |
556 ThreadUtils.assertOnUiThread(); | |
557 nativeSetProfileUseStatsForTest(mPersonalDataManagerAndroid, guid, count , date); | |
558 } | |
559 | |
560 @VisibleForTesting | |
561 public void setCreditCardUseStatsForTest(String guid, int count, int date) { | |
Mathieu
2016/05/20 13:57:08
nit: ForTesting
sebsg
2016/05/24 17:27:32
Done.
| |
562 ThreadUtils.assertOnUiThread(); | |
563 nativeSetCreditCardUseStatsForTest(mPersonalDataManagerAndroid, guid, co unt, date); | |
564 } | |
565 | |
550 /** | 566 /** |
551 * @return Whether the Autofill feature is enabled. | 567 * @return Whether the Autofill feature is enabled. |
552 */ | 568 */ |
553 public static boolean isAutofillEnabled() { | 569 public static boolean isAutofillEnabled() { |
554 return nativeIsAutofillEnabled(); | 570 return nativeIsAutofillEnabled(); |
555 } | 571 } |
556 | 572 |
557 /** | 573 /** |
558 * Enables or disables the Autofill feature. | 574 * Enables or disables the Autofill feature. |
559 * @param enable True to disable Autofill, false otherwise. | 575 * @param enable True to disable Autofill, false otherwise. |
(...skipping 19 matching lines...) Expand all Loading... | |
579 /** | 595 /** |
580 * Enables or disables the Payments integration. | 596 * Enables or disables the Payments integration. |
581 * @param enable True to enable Payments data import. | 597 * @param enable True to enable Payments data import. |
582 */ | 598 */ |
583 public static void setPaymentsIntegrationEnabled(boolean enable) { | 599 public static void setPaymentsIntegrationEnabled(boolean enable) { |
584 nativeSetPaymentsIntegrationEnabled(enable); | 600 nativeSetPaymentsIntegrationEnabled(enable); |
585 } | 601 } |
586 | 602 |
587 private native long nativeInit(); | 603 private native long nativeInit(); |
588 private native int nativeGetProfileCount(long nativePersonalDataManagerAndro id); | 604 private native int nativeGetProfileCount(long nativePersonalDataManagerAndro id); |
605 private native String[] nativeGetProfileGUIDsToSuggest(long nativePersonalDa taManagerAndroid); | |
589 private native String[] nativeGetProfileLabels(long nativePersonalDataManage rAndroid, | 606 private native String[] nativeGetProfileLabels(long nativePersonalDataManage rAndroid, |
590 boolean addressOnly); | 607 boolean addressOnly); |
591 private native AutofillProfile nativeGetProfileByIndex(long nativePersonalDa taManagerAndroid, | |
592 int index); | |
593 private native AutofillProfile nativeGetProfileByGUID(long nativePersonalDat aManagerAndroid, | 608 private native AutofillProfile nativeGetProfileByGUID(long nativePersonalDat aManagerAndroid, |
594 String guid); | 609 String guid); |
595 private native String nativeSetProfile(long nativePersonalDataManagerAndroid , | 610 private native String nativeSetProfile(long nativePersonalDataManagerAndroid , |
596 AutofillProfile profile); | 611 AutofillProfile profile); |
612 private native String[] nativeGetCreditCardGUIDsToSuggest( | |
613 long nativePersonalDataManagerAndroid); | |
597 private native int nativeGetCreditCardCount(long nativePersonalDataManagerAn droid); | 614 private native int nativeGetCreditCardCount(long nativePersonalDataManagerAn droid); |
598 private native CreditCard nativeGetCreditCardByIndex(long nativePersonalData ManagerAndroid, | |
599 int index); | |
600 private native CreditCard nativeGetCreditCardByGUID(long nativePersonalDataM anagerAndroid, | 615 private native CreditCard nativeGetCreditCardByGUID(long nativePersonalDataM anagerAndroid, |
601 String guid); | 616 String guid); |
602 private native String nativeSetCreditCard(long nativePersonalDataManagerAndr oid, | 617 private native String nativeSetCreditCard(long nativePersonalDataManagerAndr oid, |
603 CreditCard card); | 618 CreditCard card); |
604 private native void nativeRemoveByGUID(long nativePersonalDataManagerAndroid , String guid); | 619 private native void nativeRemoveByGUID(long nativePersonalDataManagerAndroid , String guid); |
620 private native void nativeSetProfileUseStatsForTest( | |
621 long nativePersonalDataManagerAndroid, String guid, int count, int d ate); | |
622 private native void nativeSetCreditCardUseStatsForTest( | |
623 long nativePersonalDataManagerAndroid, String guid, int count, int d ate); | |
605 private native void nativeClearUnmaskedCache( | 624 private native void nativeClearUnmaskedCache( |
606 long nativePersonalDataManagerAndroid, String guid); | 625 long nativePersonalDataManagerAndroid, String guid); |
607 private native void nativeGetFullCardForPaymentRequest(long nativePersonalDa taManagerAndroid, | 626 private native void nativeGetFullCardForPaymentRequest(long nativePersonalDa taManagerAndroid, |
608 WebContents webContents, String guid, FullCardRequestDelegate delega te); | 627 WebContents webContents, String guid, FullCardRequestDelegate delega te); |
609 private static native boolean nativeIsAutofillEnabled(); | 628 private static native boolean nativeIsAutofillEnabled(); |
610 private static native void nativeSetAutofillEnabled(boolean enable); | 629 private static native void nativeSetAutofillEnabled(boolean enable); |
611 private static native boolean nativeIsAutofillManaged(); | 630 private static native boolean nativeIsAutofillManaged(); |
612 private static native boolean nativeIsPaymentsIntegrationEnabled(); | 631 private static native boolean nativeIsPaymentsIntegrationEnabled(); |
613 private static native void nativeSetPaymentsIntegrationEnabled(boolean enabl e); | 632 private static native void nativeSetPaymentsIntegrationEnabled(boolean enabl e); |
614 private static native String nativeToCountryCode(String countryName); | 633 private static native String nativeToCountryCode(String countryName); |
615 } | 634 } |
OLD | NEW |