| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/android/jni_weak_ref.h" | 11 #include "base/android/jni_weak_ref.h" |
| 12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "components/autofill/core/browser/personal_data_manager.h" | 15 #include "components/autofill/core/browser/personal_data_manager.h" |
| 16 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 16 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 17 #include "components/payments/core/address_normalizer_impl.h" | 17 #include "components/payments/core/address_normalizer_impl.h" |
| 18 #include "components/payments/core/subkey_requester.h" |
| 18 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" | 19 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" |
| 19 | 20 |
| 20 namespace autofill { | 21 namespace autofill { |
| 21 | 22 |
| 22 // Android wrapper of the PersonalDataManager which provides access from the | 23 // Android wrapper of the PersonalDataManager which provides access from the |
| 23 // Java layer. Note that on Android, there's only a single profile, and | 24 // Java layer. Note that on Android, there's only a single profile, and |
| 24 // therefore a single instance of this wrapper. | 25 // therefore a single instance of this wrapper. |
| 25 class PersonalDataManagerAndroid | 26 class PersonalDataManagerAndroid |
| 26 : public PersonalDataManagerObserver, | 27 : public PersonalDataManagerObserver, |
| 27 public LoadRulesListener, | |
| 28 public base::SupportsWeakPtr<PersonalDataManagerAndroid> { | 28 public base::SupportsWeakPtr<PersonalDataManagerAndroid> { |
| 29 public: | 29 public: |
| 30 // The interface for the sub-key request. | |
| 31 class SubKeyRequestDelegate { | |
| 32 public: | |
| 33 virtual void OnRulesSuccessfullyLoaded() = 0; | |
| 34 virtual ~SubKeyRequestDelegate() {} | |
| 35 }; | |
| 36 | |
| 37 // Registers the JNI bindings for this class. | 30 // Registers the JNI bindings for this class. |
| 38 static bool Register(JNIEnv* env); | 31 static bool Register(JNIEnv* env); |
| 39 | 32 |
| 40 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); | 33 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); |
| 41 | 34 |
| 42 // Returns true if personal data manager has loaded the initial data. | 35 // Returns true if personal data manager has loaded the initial data. |
| 43 jboolean IsDataLoaded( | 36 jboolean IsDataLoaded( |
| 44 JNIEnv* env, | 37 JNIEnv* env, |
| 45 const base::android::JavaParamRef<jobject>& unused_obj) const; | 38 const base::android::JavaParamRef<jobject>& unused_obj) const; |
| 46 | 39 |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 // -------------------- | 291 // -------------------- |
| 299 | 292 |
| 300 // Starts loading the address validation rules for the specified | 293 // Starts loading the address validation rules for the specified |
| 301 // |region_code|. | 294 // |region_code|. |
| 302 void LoadRulesForAddressNormalization( | 295 void LoadRulesForAddressNormalization( |
| 303 JNIEnv* env, | 296 JNIEnv* env, |
| 304 const base::android::JavaParamRef<jobject>& unused_obj, | 297 const base::android::JavaParamRef<jobject>& unused_obj, |
| 305 const base::android::JavaParamRef<jstring>& region_code); | 298 const base::android::JavaParamRef<jstring>& region_code); |
| 306 | 299 |
| 307 // Starts loading the rules for the specified |region_code| for the further | 300 // Starts loading the rules for the specified |region_code| for the further |
| 308 // sub-key request. | 301 // subkey request. |
| 309 void LoadRulesForSubKeys( | 302 void LoadRulesForSubKeys( |
| 310 JNIEnv* env, | 303 JNIEnv* env, |
| 311 const base::android::JavaParamRef<jobject>& unused_obj, | 304 const base::android::JavaParamRef<jobject>& unused_obj, |
| 312 const base::android::JavaParamRef<jstring>& region_code); | 305 const base::android::JavaParamRef<jstring>& region_code); |
| 313 | 306 |
| 314 // Normalizes the address of the |jprofile| synchronously if the | 307 // Normalizes the address of the |jprofile| synchronously if the |
| 315 // |jregion_code| rules have finished loading. Otherwise sets up the task to | 308 // |jregion_code| rules have finished loading. Otherwise sets up the task to |
| 316 // start the address normalization when the rules have finished loading. Also | 309 // start the address normalization when the rules have finished loading. Also |
| 317 // defines a time limit for the normalization, in which case the the | 310 // defines a time limit for the normalization, in which case the the |
| 318 // |jdelegate| will be notified. If the rules are loaded before the timeout, | 311 // |jdelegate| will be notified. If the rules are loaded before the timeout, |
| 319 // |jdelegate| will receive the normalized profile. | 312 // |jdelegate| will receive the normalized profile. |
| 320 void StartAddressNormalization( | 313 void StartAddressNormalization( |
| 321 JNIEnv* env, | 314 JNIEnv* env, |
| 322 const base::android::JavaParamRef<jobject>& unused_obj, | 315 const base::android::JavaParamRef<jobject>& unused_obj, |
| 323 const base::android::JavaParamRef<jobject>& jprofile, | 316 const base::android::JavaParamRef<jobject>& jprofile, |
| 324 const base::android::JavaParamRef<jstring>& jregion_code, | 317 const base::android::JavaParamRef<jstring>& jregion_code, |
| 325 jint jtimeout_seconds, | 318 jint jtimeout_seconds, |
| 326 const base::android::JavaParamRef<jobject>& jdelegate); | 319 const base::android::JavaParamRef<jobject>& jdelegate); |
| 327 | 320 |
| 328 // Checks whether the Autofill PersonalDataManager has profiles. | 321 // Checks whether the Autofill PersonalDataManager has profiles. |
| 329 jboolean HasProfiles(JNIEnv* env, | 322 jboolean HasProfiles(JNIEnv* env, |
| 330 const base::android::JavaParamRef<jobject>& unused_obj); | 323 const base::android::JavaParamRef<jobject>& unused_obj); |
| 331 | 324 |
| 332 // Checks whether the Autofill PersonalDataManager has credit cards. | 325 // Checks whether the Autofill PersonalDataManager has credit cards. |
| 333 jboolean HasCreditCards( | 326 jboolean HasCreditCards( |
| 334 JNIEnv* env, | 327 JNIEnv* env, |
| 335 const base::android::JavaParamRef<jobject>& unused_obj); | 328 const base::android::JavaParamRef<jobject>& unused_obj); |
| 336 | 329 |
| 337 // Gets the sub-keys for the region with |jregion_code| code, if the | 330 // Gets the subkeys for the region with |jregion_code| code, if the |
| 338 // |jregion_code| rules have finished loading. Otherwise, sets up a task to | 331 // |jregion_code| rules have finished loading. Otherwise, sets up a task to |
| 339 // get the sub-keys, when the rules are loaded. | 332 // get the subkeys, when the rules are loaded. |
| 340 void StartRegionSubKeysRequest( | 333 void StartRegionSubKeysRequest( |
| 341 JNIEnv* env, | 334 JNIEnv* env, |
| 342 const base::android::JavaParamRef<jobject>& unused_obj, | 335 const base::android::JavaParamRef<jobject>& unused_obj, |
| 343 const base::android::JavaParamRef<jstring>& jregion_code, | 336 const base::android::JavaParamRef<jstring>& jregion_code, |
| 337 jint jtimeout_seconds, |
| 344 const base::android::JavaParamRef<jobject>& jdelegate); | 338 const base::android::JavaParamRef<jobject>& jdelegate); |
| 345 | 339 |
| 346 // Gets the sub-keys of the rule associated with |jregion_code|. Should only | 340 // Cancels the pending subkey request task. |
| 347 // be called when the rules are loaded. | |
| 348 base::android::ScopedJavaLocalRef<jobjectArray> GetSubKeys( | |
| 349 JNIEnv* env, | |
| 350 const std::string& jregion_code); | |
| 351 | |
| 352 // Callback of the sub-keys request. | |
| 353 // This is called when the sub-keys are loaded. | |
| 354 void OnAddressValidationRulesLoaded(const std::string& region_code, | |
| 355 bool success) override; | |
| 356 | |
| 357 // Cancels the pending sub-key request task. | |
| 358 void CancelPendingGetSubKeys( | 341 void CancelPendingGetSubKeys( |
| 359 JNIEnv* env, | 342 JNIEnv* env, |
| 360 const base::android::JavaParamRef<jobject>& unused_obj); | 343 const base::android::JavaParamRef<jobject>& unused_obj); |
| 361 | 344 |
| 362 private: | 345 private: |
| 363 ~PersonalDataManagerAndroid() override; | 346 ~PersonalDataManagerAndroid() override; |
| 364 | 347 |
| 365 // Returns the GUIDs of the |profiles| passed as parameter. | 348 // Returns the GUIDs of the |profiles| passed as parameter. |
| 366 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( | 349 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( |
| 367 JNIEnv* env, | 350 JNIEnv* env, |
| 368 const std::vector<AutofillProfile*>& profiles); | 351 const std::vector<AutofillProfile*>& profiles); |
| 369 | 352 |
| 370 // Returns the GUIDs of the |credit_cards| passed as parameter. | 353 // Returns the GUIDs of the |credit_cards| passed as parameter. |
| 371 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( | 354 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( |
| 372 JNIEnv* env, | 355 JNIEnv* env, |
| 373 const std::vector<CreditCard*>& credit_cards); | 356 const std::vector<CreditCard*>& credit_cards); |
| 374 | 357 |
| 375 // Returns whether the rules are loaded for the specified |region_code|. | |
| 376 bool AreRulesLoadedForRegion(const std::string& region_code); | |
| 377 | |
| 378 // Gets the labels for the |profiles| passed as parameters. These labels are | 358 // Gets the labels for the |profiles| passed as parameters. These labels are |
| 379 // useful for distinguishing the profiles from one another. | 359 // useful for distinguishing the profiles from one another. |
| 380 // | 360 // |
| 381 // The labels never contain the full name and include at least 2 fields. | 361 // The labels never contain the full name and include at least 2 fields. |
| 382 // | 362 // |
| 383 // If |address_only| is true, then such fields as phone number, and email | 363 // If |address_only| is true, then such fields as phone number, and email |
| 384 // address are also omitted, but all other fields are included in the label. | 364 // address are also omitted, but all other fields are included in the label. |
| 385 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels( | 365 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels( |
| 386 JNIEnv* env, | 366 JNIEnv* env, |
| 387 bool address_only, | 367 bool address_only, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 402 | 382 |
| 403 // Pointer to the java counterpart. | 383 // Pointer to the java counterpart. |
| 404 JavaObjectWeakGlobalRef weak_java_obj_; | 384 JavaObjectWeakGlobalRef weak_java_obj_; |
| 405 | 385 |
| 406 // Pointer to the PersonalDataManager for the main profile. | 386 // Pointer to the PersonalDataManager for the main profile. |
| 407 PersonalDataManager* personal_data_manager_; | 387 PersonalDataManager* personal_data_manager_; |
| 408 | 388 |
| 409 // The address validator used to normalize addresses. | 389 // The address validator used to normalize addresses. |
| 410 payments::AddressNormalizerImpl address_normalizer_; | 390 payments::AddressNormalizerImpl address_normalizer_; |
| 411 | 391 |
| 412 // The address validator used for sub-key request. | 392 // Used for subkey request. |
| 413 AddressValidator address_validator_; | 393 payments::SubKeyRequester subkey_requester_; |
| 414 | |
| 415 // The region code and the request for the pending sub-key request. | |
| 416 std::unique_ptr<SubKeyRequestDelegate> pending_subkey_request_; | |
| 417 std::string pending_subkey_region_code_; | |
| 418 | 394 |
| 419 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); | 395 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); |
| 420 }; | 396 }; |
| 421 | 397 |
| 422 } // namespace autofill | 398 } // namespace autofill |
| 423 | 399 |
| 424 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 400 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
| OLD | NEW |