Index: chrome/android/java/src/org/chromium/chrome/browser/autofill/PersonalDataManager.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/PersonalDataManager.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/PersonalDataManager.java |
index 059cee3757afa2eca75e2c541bc7800c3fc1f238..16e47f4a723cc077429414947c30ee99264f8cc2 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/autofill/PersonalDataManager.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/PersonalDataManager.java |
@@ -62,6 +62,19 @@ public class PersonalDataManager { |
} |
/** |
+ * Callback for normalized addresses. |
+ */ |
+ public interface NormalizedAddressRequestDelegate { |
+ /** |
+ * Called when the address has been sucessfully normalized. |
+ * |
+ * @param profile The profile with the normalized address. |
+ */ |
+ @CalledByNative("NormalizedAddressRequestDelegate") |
+ void onAddressNormalized(AutofillProfile profile); |
+ } |
+ |
+ /** |
* Autofill address information. |
*/ |
public static class AutofillProfile { |
@@ -474,6 +487,8 @@ public class PersonalDataManager { |
return sManager; |
} |
+ private static int sNormalizationTimeoutMs = 5000; |
+ |
private final long mPersonalDataManagerAndroid; |
private final List<PersonalDataManagerObserver> mDataObservers = |
new ArrayList<PersonalDataManagerObserver>(); |
@@ -718,6 +733,41 @@ public class PersonalDataManager { |
} |
/** |
+ * Starts loading the address validation rules for the specified {@code regionCode}. |
+ * |
+ * @param regionCode The code of the region for which to load the rules. |
+ */ |
+ public void loadRulesForRegion(String regionCode) { |
+ ThreadUtils.assertOnUiThread(); |
+ nativeLoadRulesForRegion(mPersonalDataManagerAndroid, regionCode); |
+ } |
+ |
+ /** |
+ * Normalizes the address of the profile associated with the {@code guid} if the rules |
+ * associated with the {@code regionCode} are done loading. Otherwise sets up the callback to |
+ * start normalizing the address when the rules are loaded. The normalized profile will be sent |
+ * to the {@code delegate}. |
+ * |
+ * @param guid The GUID of the profile to normalize. |
+ * @param regionCode The region code indicating which rules to use for normalization. |
+ * @param delegate The object requesting the normalization. |
+ * |
+ * @return Whether the normalization will happen asynchronously. |
+ */ |
+ public boolean normalizeAddress( |
+ String guid, String regionCode, NormalizedAddressRequestDelegate delegate) { |
+ ThreadUtils.assertOnUiThread(); |
+ return nativeStartAddressNormalization( |
+ mPersonalDataManagerAndroid, guid, regionCode, delegate); |
+ } |
+ |
+ /** Cancels the pending address normalization. */ |
+ public void cancelPendingAddressNormalization() { |
+ ThreadUtils.assertOnUiThread(); |
+ nativeCancelPendingAddressNormalization(mPersonalDataManagerAndroid); |
+ } |
+ |
+ /** |
* @return Whether the Autofill feature is enabled. |
*/ |
public static boolean isAutofillEnabled() { |
@@ -754,6 +804,18 @@ public class PersonalDataManager { |
nativeSetPaymentsIntegrationEnabled(enable); |
} |
+ /** |
+ * @return The timeout value for normalization. |
+ */ |
+ public static int getNormalizationTimeoutMS() { |
+ return sNormalizationTimeoutMs; |
+ } |
+ |
+ @VisibleForTesting |
+ public static void setNormalizationTimeoutForTesting(int timeout) { |
+ sNormalizationTimeoutMs = timeout; |
+ } |
+ |
private native long nativeInit(); |
private native boolean nativeIsDataLoaded(long nativePersonalDataManagerAndroid); |
private native String[] nativeGetProfileGUIDsForSettings(long nativePersonalDataManagerAndroid); |
@@ -806,6 +868,12 @@ public class PersonalDataManager { |
long nativePersonalDataManagerAndroid, String guid); |
private native void nativeGetFullCardForPaymentRequest(long nativePersonalDataManagerAndroid, |
WebContents webContents, CreditCard card, FullCardRequestDelegate delegate); |
+ private native void nativeLoadRulesForRegion( |
+ long nativePersonalDataManagerAndroid, String regionCode); |
+ private native boolean nativeStartAddressNormalization(long nativePersonalDataManagerAndroid, |
+ String guid, String regionCode, NormalizedAddressRequestDelegate delegate); |
+ private native void nativeCancelPendingAddressNormalization( |
+ long nativePersonalDataManagerAndroid); |
private static native boolean nativeIsAutofillEnabled(); |
private static native void nativeSetAutofillEnabled(boolean enable); |
private static native boolean nativeIsAutofillManaged(); |