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" | |
15 | 16 |
16 namespace autofill { | 17 namespace autofill { |
17 | 18 |
18 // Android wrapper of the PersonalDataManager which provides access from the | 19 // Android wrapper of the PersonalDataManager which provides access from the |
19 // Java layer. Note that on Android, there's only a single profile, and | 20 // Java layer. Note that on Android, there's only a single profile, and |
20 // therefore a single instance of this wrapper. | 21 // therefore a single instance of this wrapper. |
21 class PersonalDataManagerAndroid : public PersonalDataManagerObserver { | 22 class PersonalDataManagerAndroid |
23 : public PersonalDataManagerObserver, | |
24 public LoadRulesListener, | |
25 public base::SupportsWeakPtr<PersonalDataManagerAndroid> { | |
22 public: | 26 public: |
27 // The interface for the sub-key request. | |
28 class SubKeyRequestDelegate { | |
29 public: | |
30 virtual void OnRulesSuccessfullyLoaded() = 0; | |
31 virtual ~SubKeyRequestDelegate() {} | |
32 }; | |
33 | |
23 // Registers the JNI bindings for this class. | 34 // Registers the JNI bindings for this class. |
24 static bool Register(JNIEnv* env); | 35 static bool Register(JNIEnv* env); |
25 | 36 |
26 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); | 37 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); |
27 | 38 |
28 // Returns true if personal data manager has loaded the initial data. | 39 // Returns true if personal data manager has loaded the initial data. |
29 jboolean IsDataLoaded( | 40 jboolean IsDataLoaded( |
30 JNIEnv* env, | 41 JNIEnv* env, |
31 const base::android::JavaParamRef<jobject>& unused_obj) const; | 42 const base::android::JavaParamRef<jobject>& unused_obj) const; |
32 | 43 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 // more details see the comment header in time.h | 288 // more details see the comment header in time.h |
278 jlong GetCurrentDateForTesting( | 289 jlong GetCurrentDateForTesting( |
279 JNIEnv* env, | 290 JNIEnv* env, |
280 const base::android::JavaParamRef<jobject>& unused_obj); | 291 const base::android::JavaParamRef<jobject>& unused_obj); |
281 | 292 |
282 // These functions help address normalization. | 293 // These functions help address normalization. |
283 // -------------------- | 294 // -------------------- |
284 | 295 |
285 // Starts loading the address validation rules for the specified | 296 // Starts loading the address validation rules for the specified |
286 // |region_code|. | 297 // |region_code|. |
287 void LoadRulesForRegion( | 298 void LoadRulesForAddressNormalization( |
288 JNIEnv* env, | 299 JNIEnv* env, |
289 const base::android::JavaParamRef<jobject>& unused_obj, | 300 const base::android::JavaParamRef<jobject>& unused_obj, |
290 const base::android::JavaParamRef<jstring>& region_code); | 301 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); | |
291 | 309 |
292 // Normalizes the address of the |jprofile| synchronously if the | 310 // Normalizes the address of the |jprofile| synchronously if the |
293 // |jregion_code| rules have finished loading. Otherwise sets up the task to | 311 // |jregion_code| rules have finished loading. Otherwise sets up the task to |
294 // start the address normalization when the rules have finished loading. Also | 312 // start the address normalization when the rules have finished loading. Also |
295 // defines a time limit for the normalization, in which case the the | 313 // defines a time limit for the normalization, in which case the the |
296 // |jdelegate| will be notified. If the rules are loaded before the timeout, | 314 // |jdelegate| will be notified. If the rules are loaded before the timeout, |
297 // |jdelegate| will receive the normalized profile. | 315 // |jdelegate| will receive the normalized profile. |
298 void StartAddressNormalization( | 316 void StartAddressNormalization( |
299 JNIEnv* env, | 317 JNIEnv* env, |
300 const base::android::JavaParamRef<jobject>& unused_obj, | 318 const base::android::JavaParamRef<jobject>& unused_obj, |
301 const base::android::JavaParamRef<jobject>& jprofile, | 319 const base::android::JavaParamRef<jobject>& jprofile, |
302 const base::android::JavaParamRef<jstring>& jregion_code, | 320 const base::android::JavaParamRef<jstring>& jregion_code, |
303 jint jtimeout_seconds, | 321 jint jtimeout_seconds, |
304 const base::android::JavaParamRef<jobject>& jdelegate); | 322 const base::android::JavaParamRef<jobject>& jdelegate); |
305 | 323 |
306 // Checks whether the Autofill PersonalDataManager has profiles. | 324 // Checks whether the Autofill PersonalDataManager has profiles. |
307 jboolean HasProfiles(JNIEnv* env, | 325 jboolean HasProfiles(JNIEnv* env, |
308 const base::android::JavaParamRef<jobject>& unused_obj); | 326 const base::android::JavaParamRef<jobject>& unused_obj); |
309 | 327 |
310 // Checks whether the Autofill PersonalDataManager has credit cards. | 328 // Checks whether the Autofill PersonalDataManager has credit cards. |
311 jboolean HasCreditCards( | 329 jboolean HasCreditCards( |
312 JNIEnv* env, | 330 JNIEnv* env, |
313 const base::android::JavaParamRef<jobject>& unused_obj); | 331 const base::android::JavaParamRef<jobject>& unused_obj); |
314 | 332 |
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 | |
315 private: | 358 private: |
316 ~PersonalDataManagerAndroid() override; | 359 ~PersonalDataManagerAndroid() override; |
317 | 360 |
318 // Returns the GUIDs of the |profiles| passed as parameter. | 361 // Returns the GUIDs of the |profiles| passed as parameter. |
319 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( | 362 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( |
320 JNIEnv* env, | 363 JNIEnv* env, |
321 const std::vector<AutofillProfile*>& profiles); | 364 const std::vector<AutofillProfile*>& profiles); |
322 | 365 |
323 // Returns the GUIDs of the |credit_cards| passed as parameter. | 366 // Returns the GUIDs of the |credit_cards| passed as parameter. |
324 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( | 367 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( |
(...skipping 27 matching lines...) Expand all Loading... | |
352 JNIEnv* env, | 395 JNIEnv* env, |
353 const base::android::JavaParamRef<jobject>& jprofile, | 396 const base::android::JavaParamRef<jobject>& jprofile, |
354 bool inlude_country_in_label); | 397 bool inlude_country_in_label); |
355 | 398 |
356 // Pointer to the java counterpart. | 399 // Pointer to the java counterpart. |
357 JavaObjectWeakGlobalRef weak_java_obj_; | 400 JavaObjectWeakGlobalRef weak_java_obj_; |
358 | 401 |
359 // Pointer to the PersonalDataManager for the main profile. | 402 // Pointer to the PersonalDataManager for the main profile. |
360 PersonalDataManager* personal_data_manager_; | 403 PersonalDataManager* personal_data_manager_; |
361 | 404 |
362 // The address validator used to normalize addresses. | 405 // The address validator used to normalize address. |
gone
2017/04/05 00:14:21
grammatically weird now. why'd you switch?
Parastoo
2017/04/05 19:49:07
typo.
Done.
| |
363 payments::AddressNormalizer address_normalizer_; | 406 payments::AddressNormalizer address_normalizer_; |
364 | 407 |
408 // The address validator used for sub key request. | |
gone
2017/04/05 00:14:21
be consistent: you use "sub-key" below and "sub ke
Parastoo
2017/04/05 19:49:07
Done.
gone
2017/04/05 20:21:38
You didn't change anything here.
Parastoo
2017/04/05 20:44:32
Done.
| |
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 | |
365 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); | 415 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); |
366 }; | 416 }; |
367 | 417 |
368 } // namespace autofill | 418 } // namespace autofill |
369 | 419 |
370 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 420 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
OLD | NEW |