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" | |
13 | 15 |
14 namespace autofill { | 16 namespace autofill { |
15 | 17 |
16 // Android wrapper of the PersonalDataManager which provides access from the | 18 // Android wrapper of the PersonalDataManager which provides access from the |
17 // 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 |
18 // therefore a single instance of this wrapper. | 20 // therefore a single instance of this wrapper. |
19 class PersonalDataManagerAndroid : public PersonalDataManagerObserver { | 21 class PersonalDataManagerAndroid : public PersonalDataManagerObserver, |
22 public LoadRulesListener { | |
20 public: | 23 public: |
24 // The interface for the normalization request. | |
25 class Delegate { | |
26 public: | |
27 virtual void OnRulesSuccessfullyLoaded() = 0; | |
28 }; | |
29 | |
21 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); | 30 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); |
22 | 31 |
23 // Returns true if personal data manager has loaded the initial data. | 32 // Returns true if personal data manager has loaded the initial data. |
24 jboolean IsDataLoaded( | 33 jboolean IsDataLoaded( |
25 JNIEnv* env, | 34 JNIEnv* env, |
26 const base::android::JavaParamRef<jobject>& unused_obj) const; | 35 const base::android::JavaParamRef<jobject>& unused_obj) const; |
27 | 36 |
28 // These functions act on "web profiles" aka "LOCAL_PROFILE" profiles. | 37 // These functions act on "web profiles" aka "LOCAL_PROFILE" profiles. |
29 // ------------------------- | 38 // ------------------------- |
30 | 39 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 const base::android::JavaParamRef<jobject>& unused_obj, | 252 const base::android::JavaParamRef<jobject>& unused_obj, |
244 const base::android::JavaParamRef<jstring>& jguid); | 253 const base::android::JavaParamRef<jstring>& jguid); |
245 | 254 |
246 // Returns the current date represented as an absolute point in coordinated | 255 // Returns the current date represented as an absolute point in coordinated |
247 // universal time (UTC) represented as microseconds since the Unix epoch. For | 256 // universal time (UTC) represented as microseconds since the Unix epoch. For |
248 // more details see the comment header in time.h | 257 // more details see the comment header in time.h |
249 jlong GetCurrentDateForTesting( | 258 jlong GetCurrentDateForTesting( |
250 JNIEnv* env, | 259 JNIEnv* env, |
251 const base::android::JavaParamRef<jobject>& unused_obj); | 260 const base::android::JavaParamRef<jobject>& unused_obj); |
252 | 261 |
262 // These functions help address normalization. | |
263 // -------------------- | |
264 | |
265 // Starts loading the address validation rules for the specified | |
266 // |region_code|. | |
267 void LoadRulesForRegion( | |
268 JNIEnv* env, | |
269 const base::android::JavaParamRef<jobject>& unused_obj, | |
270 const base::android::JavaParamRef<jstring>& region_code); | |
271 | |
272 // Callback of the address validator that is called when the validator has | |
273 // finished loading the rules for a region. | |
274 void OnAddressValidationRulesLoaded(const std::string& region_code, | |
275 bool success) override; | |
276 | |
277 // Sets up the task to start the address normalization of the profile | |
278 // associated with the specified |jguid| when the rules associated with the | |
279 // |jregion_code| have finished loading. | |
280 void StartAddressNormalizationTask( | |
281 JNIEnv* env, | |
282 const base::android::JavaParamRef<jobject>& unused_obj, | |
283 const base::android::JavaParamRef<jstring>& jguid, | |
284 const base::android::JavaParamRef<jstring>& jregion_code, | |
285 const base::android::JavaParamRef<jobject>& jdelegate); | |
286 | |
287 // Normalizes the address of the profile associated with the |guid| with the | |
288 // rules associates with the |region_code|. Should only be called when the | |
289 // rules have finished loading. | |
290 base::android::ScopedJavaLocalRef<jobject> NormalizeAddress( | |
291 const std::string& guid, | |
292 const std::string& region_code, | |
293 JNIEnv* env); | |
294 | |
295 void CancelPendingAddressNormalization(JNIEnv* env, | |
296 const base::android::JavaParamRef<jobject>& unused_obj); | |
297 | |
253 private: | 298 private: |
254 ~PersonalDataManagerAndroid() override; | 299 ~PersonalDataManagerAndroid() override; |
255 | 300 |
256 // Returns the GUIDs of the |profiles| passed as parameter. | 301 // Returns the GUIDs of the |profiles| passed as parameter. |
257 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( | 302 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( |
258 JNIEnv* env, | 303 JNIEnv* env, |
259 const std::vector<AutofillProfile*>& profiles); | 304 const std::vector<AutofillProfile*>& profiles); |
260 | 305 |
261 // Returns the GUIDs of the |credit_cards| passed as parameter. | 306 // Returns the GUIDs of the |credit_cards| passed as parameter. |
262 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( | 307 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( |
263 JNIEnv* env, | 308 JNIEnv* env, |
264 const std::vector<CreditCard*>& credit_cards); | 309 const std::vector<CreditCard*>& credit_cards); |
265 | 310 |
311 // Returns whether the rules are loading for the specified |region_code|. | |
vabr (Chromium)
2016/09/28 08:41:36
nit: loading -> loaded ?
sebsg
2016/09/28 16:15:25
Done.
| |
312 bool AreRulesLoadedForRegion(const std::string& region_code); | |
313 | |
266 // Gets the labels for the |profiles| passed as parameters. These labels are | 314 // Gets the labels for the |profiles| passed as parameters. These labels are |
267 // useful for distinguishing the profiles from one another. | 315 // useful for distinguishing the profiles from one another. |
268 // | 316 // |
269 // The labels never contain the full name and include at least 2 fields. | 317 // The labels never contain the full name and include at least 2 fields. |
270 // | 318 // |
271 // If |address_only| is true, then such fields as phone number, and email | 319 // If |address_only| is true, then such fields as phone number, and email |
272 // address are also omitted, but all other fields are included in the label. | 320 // address are also omitted, but all other fields are included in the label. |
273 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels( | 321 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels( |
274 JNIEnv* env, | 322 JNIEnv* env, |
275 bool address_only, | 323 bool address_only, |
276 bool include_name, | 324 bool include_name, |
277 std::vector<AutofillProfile*> profiles); | 325 std::vector<AutofillProfile*> profiles); |
278 | 326 |
279 // Pointer to the java counterpart. | 327 // Pointer to the java counterpart. |
280 JavaObjectWeakGlobalRef weak_java_obj_; | 328 JavaObjectWeakGlobalRef weak_java_obj_; |
281 | 329 |
282 // Pointer to the PersonalDataManager for the main profile. | 330 // Pointer to the PersonalDataManager for the main profile. |
283 PersonalDataManager* personal_data_manager_; | 331 PersonalDataManager* personal_data_manager_; |
284 | 332 |
333 // Pointer to the address validator used to normalize addresses. | |
334 std::unique_ptr<AddressValidator> address_validator_; | |
335 | |
336 // Map associating a region code to a pending normalization. | |
337 std::map<std::string, Delegate*> pending_normalization_; | |
338 | |
285 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); | 339 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); |
286 }; | 340 }; |
287 | 341 |
288 } // namespace autofill | 342 } // namespace autofill |
289 | 343 |
290 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 344 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
OLD | NEW |