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 "chrome/browser/autofill/validation_rules_storage_factory.h" | |
11 #include "components/autofill/core/browser/personal_data_manager.h" | 12 #include "components/autofill/core/browser/personal_data_manager.h" |
12 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 13 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
14 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" | |
15 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h" | |
16 #include "third_party/libaddressinput/chromium/chrome_storage_impl.h" | |
13 | 17 |
14 namespace autofill { | 18 namespace autofill { |
15 | 19 |
16 // Android wrapper of the PersonalDataManager which provides access from the | 20 // Android wrapper of the PersonalDataManager which provides access from the |
17 // Java layer. Note that on Android, there's only a single profile, and | 21 // Java layer. Note that on Android, there's only a single profile, and |
18 // therefore a single instance of this wrapper. | 22 // therefore a single instance of this wrapper. |
19 class PersonalDataManagerAndroid : public PersonalDataManagerObserver { | 23 class PersonalDataManagerAndroid : public PersonalDataManagerObserver, |
24 public LoadRulesListener { | |
20 public: | 25 public: |
21 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); | 26 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); |
22 | 27 |
23 // Returns true if personal data manager has loaded the initial data. | 28 // Returns true if personal data manager has loaded the initial data. |
24 jboolean IsDataLoaded( | 29 jboolean IsDataLoaded( |
25 JNIEnv* env, | 30 JNIEnv* env, |
26 const base::android::JavaParamRef<jobject>& unused_obj) const; | 31 const base::android::JavaParamRef<jobject>& unused_obj) const; |
27 | 32 |
28 // These functions act on "web profiles" aka "LOCAL_PROFILE" profiles. | 33 // These functions act on "web profiles" aka "LOCAL_PROFILE" profiles. |
29 // ------------------------- | 34 // ------------------------- |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 const base::android::JavaParamRef<jobject>& unused_obj, | 248 const base::android::JavaParamRef<jobject>& unused_obj, |
244 const base::android::JavaParamRef<jstring>& jguid); | 249 const base::android::JavaParamRef<jstring>& jguid); |
245 | 250 |
246 // Returns the current date represented as an absolute point in coordinated | 251 // Returns the current date represented as an absolute point in coordinated |
247 // universal time (UTC) represented as microseconds since the Unix epoch. For | 252 // universal time (UTC) represented as microseconds since the Unix epoch. For |
248 // more details see the comment header in time.h | 253 // more details see the comment header in time.h |
249 jlong GetCurrentDateForTesting( | 254 jlong GetCurrentDateForTesting( |
250 JNIEnv* env, | 255 JNIEnv* env, |
251 const base::android::JavaParamRef<jobject>& unused_obj); | 256 const base::android::JavaParamRef<jobject>& unused_obj); |
252 | 257 |
258 // Starts loading the address validation rules for the specified | |
259 // |region_code|. | |
260 void LoadRulesForRegion( | |
261 JNIEnv* env, | |
262 const base::android::JavaParamRef<jobject>& unused_obj, | |
263 const base::android::JavaParamRef<jstring>& region_code); | |
264 | |
265 // Returns whether the rules are done loading for the specified | |
266 //|jregion_code|. | |
267 jboolean AreRulesDoneLoadingForRegion( | |
268 JNIEnv* env, | |
269 const base::android::JavaParamRef<jobject>& unused_obj, | |
270 const base::android::JavaParamRef<jstring>& jregion_code); | |
271 | |
272 // Returns whether the rules were successfully loaded for the specified | |
273 // |jregion_code|. | |
274 jboolean AreRulesSuccessfullyLoadedForRegion( | |
275 JNIEnv* env, | |
276 const base::android::JavaParamRef<jobject>& unused_obj, | |
277 const base::android::JavaParamRef<jstring>& jregion_); | |
278 | |
279 // Gets the normalized version of the profile associated with the specified | |
280 // GUID. | |
281 // | |
282 // This method will wait for up to 5 seconds for the rules to be loaded. If | |
283 // the rules are still not loaded after that time, it returns the original | |
284 // profile. | |
285 base::android::ScopedJavaLocalRef<jobject> GetNormalizedProfile( | |
please use gerrit instead
2016/09/16 22:30:42
Make async plz.
sebsg
2016/09/22 19:50:40
Done.
| |
286 JNIEnv* env, | |
287 const base::android::JavaParamRef<jobject>& unused_obj, | |
288 const base::android::JavaParamRef<jstring>& jguid, | |
289 const base::android::JavaParamRef<jstring>& jregion_code); | |
290 | |
291 // Callback of the address validator that is called when the validator has | |
292 // finished loading the rules for a region. | |
293 void OnAddressValidationRulesLoaded(const std::string& region_code, | |
294 bool success) override; | |
295 | |
296 // Sets up the mock address validator used in tests. | |
297 void SetMockAddressValidatorForTesting( | |
298 JNIEnv* env, | |
299 const base::android::JavaParamRef<jobject>& unused_obj, | |
300 jboolean load_rules_response); | |
301 | |
253 private: | 302 private: |
254 ~PersonalDataManagerAndroid() override; | 303 ~PersonalDataManagerAndroid() override; |
255 | 304 |
256 // Returns the GUIDs of the |profiles| passed as parameter. | 305 // Returns the GUIDs of the |profiles| passed as parameter. |
257 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( | 306 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( |
258 JNIEnv* env, | 307 JNIEnv* env, |
259 const std::vector<AutofillProfile*>& profiles); | 308 const std::vector<AutofillProfile*>& profiles); |
260 | 309 |
261 // Returns the GUIDs of the |credit_cards| passed as parameter. | 310 // Returns the GUIDs of the |credit_cards| passed as parameter. |
262 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( | 311 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( |
(...skipping 12 matching lines...) Expand all Loading... | |
275 bool address_only, | 324 bool address_only, |
276 bool include_name, | 325 bool include_name, |
277 std::vector<AutofillProfile*> profiles); | 326 std::vector<AutofillProfile*> profiles); |
278 | 327 |
279 // Pointer to the java counterpart. | 328 // Pointer to the java counterpart. |
280 JavaObjectWeakGlobalRef weak_java_obj_; | 329 JavaObjectWeakGlobalRef weak_java_obj_; |
281 | 330 |
282 // Pointer to the PersonalDataManager for the main profile. | 331 // Pointer to the PersonalDataManager for the main profile. |
283 PersonalDataManager* personal_data_manager_; | 332 PersonalDataManager* personal_data_manager_; |
284 | 333 |
334 // Pointer to the address validator used to normalize addresses. | |
335 std::unique_ptr<AddressValidator> address_validator_; | |
336 | |
337 // Map containing all the regions for which rules were requested along with | |
338 // a bool indicating if they have finished loading. | |
339 std::map<std::string, bool> loaded_rules_; | |
340 | |
285 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); | 341 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); |
286 }; | 342 }; |
287 | 343 |
288 } // namespace autofill | 344 } // namespace autofill |
289 | 345 |
290 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 346 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
OLD | NEW |