| 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 #ifndef CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
| 6 #define CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 6 #define CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
| 7 | 7 |
| 8 #include "base/android/jni_weak_ref.h" | 8 #include "base/android/jni_weak_ref.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "chrome/browser/autofill/validation_rules_storage_factory.h" | |
| 13 #include "components/autofill/core/browser/personal_data_manager.h" | 12 #include "components/autofill/core/browser/personal_data_manager.h" |
| 14 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 13 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 15 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" | 14 #include "components/payments/address_normalizer.h" |
| 16 | 15 |
| 17 namespace autofill { | 16 namespace autofill { |
| 18 | 17 |
| 19 // Android wrapper of the PersonalDataManager which provides access from the | 18 // Android wrapper of the PersonalDataManager which provides access from the |
| 20 // Java layer. Note that on Android, there's only a single profile, and | 19 // Java layer. Note that on Android, there's only a single profile, and |
| 21 // therefore a single instance of this wrapper. | 20 // therefore a single instance of this wrapper. |
| 22 class PersonalDataManagerAndroid | 21 class PersonalDataManagerAndroid : public PersonalDataManagerObserver { |
| 23 : public PersonalDataManagerObserver, | |
| 24 public LoadRulesListener, | |
| 25 public base::SupportsWeakPtr<PersonalDataManagerAndroid> { | |
| 26 public: | 22 public: |
| 27 // The interface for the normalization request. | |
| 28 class Delegate { | |
| 29 public: | |
| 30 virtual void OnRulesSuccessfullyLoaded() = 0; | |
| 31 virtual ~Delegate() {} | |
| 32 }; | |
| 33 | |
| 34 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); | 23 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); |
| 35 | 24 |
| 36 // Returns true if personal data manager has loaded the initial data. | 25 // Returns true if personal data manager has loaded the initial data. |
| 37 jboolean IsDataLoaded( | 26 jboolean IsDataLoaded( |
| 38 JNIEnv* env, | 27 JNIEnv* env, |
| 39 const base::android::JavaParamRef<jobject>& unused_obj) const; | 28 const base::android::JavaParamRef<jobject>& unused_obj) const; |
| 40 | 29 |
| 41 // These functions act on "web profiles" aka "LOCAL_PROFILE" profiles. | 30 // These functions act on "web profiles" aka "LOCAL_PROFILE" profiles. |
| 42 // ------------------------- | 31 // ------------------------- |
| 43 | 32 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 // These functions help address normalization. | 282 // These functions help address normalization. |
| 294 // -------------------- | 283 // -------------------- |
| 295 | 284 |
| 296 // Starts loading the address validation rules for the specified | 285 // Starts loading the address validation rules for the specified |
| 297 // |region_code|. | 286 // |region_code|. |
| 298 void LoadRulesForRegion( | 287 void LoadRulesForRegion( |
| 299 JNIEnv* env, | 288 JNIEnv* env, |
| 300 const base::android::JavaParamRef<jobject>& unused_obj, | 289 const base::android::JavaParamRef<jobject>& unused_obj, |
| 301 const base::android::JavaParamRef<jstring>& region_code); | 290 const base::android::JavaParamRef<jstring>& region_code); |
| 302 | 291 |
| 303 // Callback of the address validator that is called when the validator has | |
| 304 // finished loading the rules for a region. | |
| 305 void OnAddressValidationRulesLoaded(const std::string& region_code, | |
| 306 bool success) override; | |
| 307 | |
| 308 // Normalizes the address of the profile associated with the |jguid| | 292 // Normalizes the address of the profile associated with the |jguid| |
| 309 // synchronously if the |jregion_code| rules have finished loading. Otherwise | 293 // synchronously if the |jregion_code| rules have finished loading. Otherwise |
| 310 // sets up the task to start the address normalization when the rules have | 294 // sets up the task to start the address normalization when the rules have |
| 311 // finished loading. In either case, sends the normalized profile to the | 295 // finished loading. In either case, sends the normalized profile to the |
| 312 // |jdelegate|. Returns whether the normalization will happen asynchronously. | 296 // |jdelegate|. |
| 313 jboolean StartAddressNormalization( | 297 void StartAddressNormalization( |
| 314 JNIEnv* env, | 298 JNIEnv* env, |
| 315 const base::android::JavaParamRef<jobject>& unused_obj, | 299 const base::android::JavaParamRef<jobject>& unused_obj, |
| 316 const base::android::JavaParamRef<jstring>& jguid, | 300 const base::android::JavaParamRef<jstring>& jguid, |
| 317 const base::android::JavaParamRef<jstring>& jregion_code, | 301 const base::android::JavaParamRef<jstring>& jregion_code, |
| 318 const base::android::JavaParamRef<jobject>& jdelegate); | 302 const base::android::JavaParamRef<jobject>& jdelegate); |
| 319 | 303 |
| 320 // Normalizes the address of the profile associated with the |guid| with the | |
| 321 // rules associates with the |region_code|. Should only be called when the | |
| 322 // rules have finished loading. | |
| 323 base::android::ScopedJavaLocalRef<jobject> NormalizeAddress( | |
| 324 const std::string& guid, | |
| 325 const std::string& region_code, | |
| 326 JNIEnv* env); | |
| 327 | |
| 328 // Cancels the pending address normalization task. | |
| 329 void CancelPendingAddressNormalizations( | |
| 330 JNIEnv* env, | |
| 331 const base::android::JavaParamRef<jobject>& unused_obj); | |
| 332 | |
| 333 // Checks whether the Autofill PersonalDataManager has profiles. | 304 // Checks whether the Autofill PersonalDataManager has profiles. |
| 334 jboolean HasProfiles(JNIEnv* env, | 305 jboolean HasProfiles(JNIEnv* env, |
| 335 const base::android::JavaParamRef<jobject>& unused_obj); | 306 const base::android::JavaParamRef<jobject>& unused_obj); |
| 336 | 307 |
| 337 // Checks whether the Autofill PersonalDataManager has credit cards. | 308 // Checks whether the Autofill PersonalDataManager has credit cards. |
| 338 jboolean HasCreditCards( | 309 jboolean HasCreditCards( |
| 339 JNIEnv* env, | 310 JNIEnv* env, |
| 340 const base::android::JavaParamRef<jobject>& unused_obj); | 311 const base::android::JavaParamRef<jobject>& unused_obj); |
| 341 | 312 |
| 342 private: | 313 private: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 const base::android::JavaParamRef<jobject>& jprofile, | 351 const base::android::JavaParamRef<jobject>& jprofile, |
| 381 bool inlude_country_in_label); | 352 bool inlude_country_in_label); |
| 382 | 353 |
| 383 // Pointer to the java counterpart. | 354 // Pointer to the java counterpart. |
| 384 JavaObjectWeakGlobalRef weak_java_obj_; | 355 JavaObjectWeakGlobalRef weak_java_obj_; |
| 385 | 356 |
| 386 // Pointer to the PersonalDataManager for the main profile. | 357 // Pointer to the PersonalDataManager for the main profile. |
| 387 PersonalDataManager* personal_data_manager_; | 358 PersonalDataManager* personal_data_manager_; |
| 388 | 359 |
| 389 // The address validator used to normalize addresses. | 360 // The address validator used to normalize addresses. |
| 390 AddressValidator address_validator_; | 361 payments::AddressNormalizer address_normalizer_; |
| 391 | |
| 392 // Map associating a region code to pending normalizations. | |
| 393 std::map<std::string, std::vector<std::unique_ptr<Delegate>>> | |
| 394 pending_normalization_; | |
| 395 | 362 |
| 396 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); | 363 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); |
| 397 }; | 364 }; |
| 398 | 365 |
| 399 } // namespace autofill | 366 } // namespace autofill |
| 400 | 367 |
| 401 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 368 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
| OLD | NEW |