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 "components/autofill/core/browser/personal_data_manager.h" | 12 #include "components/autofill/core/browser/personal_data_manager.h" |
13 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 13 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
14 #include "components/payments/core/address_normalizer.h" | 14 #include "components/payments/core/address_normalizer.h" |
15 #include "third_party/libaddressinput/chromium/chrome_address_validator.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 sub-key request. | |
28 class SubKeyRequestDelegate { | |
29 public: | |
30 virtual void OnRulesSuccessfullyLoaded() = 0; | |
31 virtual ~SubKeyRequestDelegate() {} | |
32 }; | |
33 | |
34 // Registers the JNI bindings for this class. | 23 // Registers the JNI bindings for this class. |
35 static bool Register(JNIEnv* env); | 24 static bool Register(JNIEnv* env); |
36 | 25 |
37 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); | 26 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); |
38 | 27 |
39 // Returns true if personal data manager has loaded the initial data. | 28 // Returns true if personal data manager has loaded the initial data. |
40 jboolean IsDataLoaded( | 29 jboolean IsDataLoaded( |
41 JNIEnv* env, | 30 JNIEnv* env, |
42 const base::android::JavaParamRef<jobject>& unused_obj) const; | 31 const base::android::JavaParamRef<jobject>& unused_obj) const; |
43 | 32 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // more details see the comment header in time.h | 277 // more details see the comment header in time.h |
289 jlong GetCurrentDateForTesting( | 278 jlong GetCurrentDateForTesting( |
290 JNIEnv* env, | 279 JNIEnv* env, |
291 const base::android::JavaParamRef<jobject>& unused_obj); | 280 const base::android::JavaParamRef<jobject>& unused_obj); |
292 | 281 |
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 LoadRulesForAddressNormalization( | 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 | |
303 // Starts loading the rules for the specified |region_code| for the further | |
304 // sub-key request. | |
305 void LoadRulesForSubKeys( | |
306 JNIEnv* env, | |
307 const base::android::JavaParamRef<jobject>& unused_obj, | |
308 const base::android::JavaParamRef<jstring>& region_code); | |
309 | 291 |
310 // Normalizes the address of the |jprofile| synchronously if the | 292 // Normalizes the address of the |jprofile| synchronously if the |
311 // |jregion_code| rules have finished loading. Otherwise sets up the task to | 293 // |jregion_code| rules have finished loading. Otherwise sets up the task to |
312 // start the address normalization when the rules have finished loading. Also | 294 // start the address normalization when the rules have finished loading. Also |
313 // defines a time limit for the normalization, in which case the the | 295 // defines a time limit for the normalization, in which case the the |
314 // |jdelegate| will be notified. If the rules are loaded before the timeout, | 296 // |jdelegate| will be notified. If the rules are loaded before the timeout, |
315 // |jdelegate| will receive the normalized profile. | 297 // |jdelegate| will receive the normalized profile. |
316 void StartAddressNormalization( | 298 void StartAddressNormalization( |
317 JNIEnv* env, | 299 JNIEnv* env, |
318 const base::android::JavaParamRef<jobject>& unused_obj, | 300 const base::android::JavaParamRef<jobject>& unused_obj, |
319 const base::android::JavaParamRef<jobject>& jprofile, | 301 const base::android::JavaParamRef<jobject>& jprofile, |
320 const base::android::JavaParamRef<jstring>& jregion_code, | 302 const base::android::JavaParamRef<jstring>& jregion_code, |
321 jint jtimeout_seconds, | 303 jint jtimeout_seconds, |
322 const base::android::JavaParamRef<jobject>& jdelegate); | 304 const base::android::JavaParamRef<jobject>& jdelegate); |
323 | 305 |
324 // Checks whether the Autofill PersonalDataManager has profiles. | 306 // Checks whether the Autofill PersonalDataManager has profiles. |
325 jboolean HasProfiles(JNIEnv* env, | 307 jboolean HasProfiles(JNIEnv* env, |
326 const base::android::JavaParamRef<jobject>& unused_obj); | 308 const base::android::JavaParamRef<jobject>& unused_obj); |
327 | 309 |
328 // Checks whether the Autofill PersonalDataManager has credit cards. | 310 // Checks whether the Autofill PersonalDataManager has credit cards. |
329 jboolean HasCreditCards( | 311 jboolean HasCreditCards( |
330 JNIEnv* env, | 312 JNIEnv* env, |
331 const base::android::JavaParamRef<jobject>& unused_obj); | 313 const base::android::JavaParamRef<jobject>& unused_obj); |
332 | 314 |
333 // Gets the sub-keys for the region with |jregion_code| code, if the | |
334 // |jregion_code| rules have finished loading. Otherwise, sets up a task to | |
335 // get the sub-keys, when the rules are loaded. | |
336 void StartRegionSubKeysRequest( | |
337 JNIEnv* env, | |
338 const base::android::JavaParamRef<jobject>& unused_obj, | |
339 const base::android::JavaParamRef<jstring>& jregion_code, | |
340 const base::android::JavaParamRef<jobject>& jdelegate); | |
341 | |
342 // Gets the sub-keys of the rule associated with |jregion_code|. Should only | |
343 // be called when the rules are loaded. | |
344 base::android::ScopedJavaLocalRef<jobjectArray> GetSubKeys( | |
345 JNIEnv* env, | |
346 const std::string& jregion_code); | |
347 | |
348 // Callback of the sub-keys request. | |
349 // This is called when the sub-keys are loaded. | |
350 void OnAddressRulesLoaded(const std::string& region_code, | |
351 bool success) override; | |
352 | |
353 // Cancels the pending sub-key request task. | |
354 void CancelPendingGetSubKeys( | |
355 JNIEnv* env, | |
356 const base::android::JavaParamRef<jobject>& unused_obj); | |
357 | |
358 private: | 315 private: |
359 ~PersonalDataManagerAndroid() override; | 316 ~PersonalDataManagerAndroid() override; |
360 | 317 |
361 // Returns the GUIDs of the |profiles| passed as parameter. | 318 // Returns the GUIDs of the |profiles| passed as parameter. |
362 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( | 319 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( |
363 JNIEnv* env, | 320 JNIEnv* env, |
364 const std::vector<AutofillProfile*>& profiles); | 321 const std::vector<AutofillProfile*>& profiles); |
365 | 322 |
366 // Returns the GUIDs of the |credit_cards| passed as parameter. | 323 // Returns the GUIDs of the |credit_cards| passed as parameter. |
367 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( | 324 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( |
(...skipping 30 matching lines...) Expand all Loading... |
398 | 355 |
399 // Pointer to the java counterpart. | 356 // Pointer to the java counterpart. |
400 JavaObjectWeakGlobalRef weak_java_obj_; | 357 JavaObjectWeakGlobalRef weak_java_obj_; |
401 | 358 |
402 // Pointer to the PersonalDataManager for the main profile. | 359 // Pointer to the PersonalDataManager for the main profile. |
403 PersonalDataManager* personal_data_manager_; | 360 PersonalDataManager* personal_data_manager_; |
404 | 361 |
405 // The address validator used to normalize addresses. | 362 // The address validator used to normalize addresses. |
406 payments::AddressNormalizer address_normalizer_; | 363 payments::AddressNormalizer address_normalizer_; |
407 | 364 |
408 // The address validator used for sub-key request. | |
409 AddressValidator address_validator_; | |
410 | |
411 // The region code and the request for the pending sub-key request. | |
412 std::unique_ptr<SubKeyRequestDelegate> pending_subkey_request_; | |
413 std::string pending_subkey_region_code_; | |
414 | |
415 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); | 365 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); |
416 }; | 366 }; |
417 | 367 |
418 } // namespace autofill | 368 } // namespace autofill |
419 | 369 |
420 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 370 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
OLD | NEW |