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" | |
please use gerrit instead
2016/09/23 09:04:40
Includes for lines 14-16 should go into the *.cc f
sebsg
2016/09/27 18:48:38
The chrome_address_validator has to be there to im
| |
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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 JNIEnv* env, | 247 JNIEnv* env, |
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 |
please use gerrit instead
2016/09/23 09:04:40
// These functions help address normalization.
//
sebsg
2016/09/27 18:48:38
Done.
| |
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 // Callback of the address validator that is called when the validator has | |
266 // finished loading the rules for a region. | |
267 void OnAddressValidationRulesLoaded(const std::string& region_code, | |
268 bool success) override; | |
269 | |
270 // Sets up the task to start the address normalization of the profile | |
271 // associated with the specified |jguid| when the rules associated with the | |
272 // |jregion_code| have finished loading. | |
273 void StartAddressNormalizationTask( | |
274 JNIEnv* env, | |
275 const base::android::JavaParamRef<jobject>& unused_obj, | |
276 const base::android::JavaParamRef<jstring>& jguid, | |
277 const base::android::JavaParamRef<jstring>& jregion_code); | |
278 | |
279 // Cancels the pending address normalization task. | |
280 void CancelAddressNormalizationTask( | |
281 JNIEnv* env, | |
282 const base::android::JavaParamRef<jobject>& unused_obj); | |
283 | |
253 private: | 284 private: |
254 ~PersonalDataManagerAndroid() override; | 285 ~PersonalDataManagerAndroid() override; |
255 | 286 |
256 // Returns the GUIDs of the |profiles| passed as parameter. | 287 // Returns the GUIDs of the |profiles| passed as parameter. |
257 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( | 288 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( |
258 JNIEnv* env, | 289 JNIEnv* env, |
259 const std::vector<AutofillProfile*>& profiles); | 290 const std::vector<AutofillProfile*>& profiles); |
260 | 291 |
261 // Returns the GUIDs of the |credit_cards| passed as parameter. | 292 // Returns the GUIDs of the |credit_cards| passed as parameter. |
262 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( | 293 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( |
263 JNIEnv* env, | 294 JNIEnv* env, |
264 const std::vector<CreditCard*>& credit_cards); | 295 const std::vector<CreditCard*>& credit_cards); |
265 | 296 |
297 // Returns whether the rules are done loading for the specified | |
298 //|region_code|. | |
299 bool AreRulesDoneLoadingForRegion(std::string region_code); | |
please use gerrit instead
2016/09/23 09:04:40
const std::string&
... to avoid string copies,
sebsg
2016/09/27 18:48:38
Done.
| |
300 | |
301 // Returns whether the rules were successfully loaded for the specified | |
302 // |region_code|. This should only be called when the rules have finished | |
303 // loading. | |
304 bool AreRulesSuccessfullyLoadedForRegion(std::string region_code); | |
please use gerrit instead
2016/09/23 09:04:40
const std::string&
sebsg
2016/09/27 18:48:38
Done.
| |
305 | |
306 // Normalizes the address of the profile associated with the |guid| with the | |
307 // rules associates with the |region_code|. Should only be called when the | |
308 // rules have finished loading. | |
309 void NormalizeAddress(std::string guid, std::string region_code); | |
please use gerrit instead
2016/09/23 09:04:40
const std::string&
sebsg
2016/09/27 18:48:38
Done.
| |
310 | |
266 // Gets the labels for the |profiles| passed as parameters. These labels are | 311 // Gets the labels for the |profiles| passed as parameters. These labels are |
267 // useful for distinguishing the profiles from one another. | 312 // useful for distinguishing the profiles from one another. |
268 // | 313 // |
269 // The labels never contain the full name and include at least 2 fields. | 314 // The labels never contain the full name and include at least 2 fields. |
270 // | 315 // |
271 // If |address_only| is true, then such fields as phone number, and email | 316 // 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. | 317 // address are also omitted, but all other fields are included in the label. |
273 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels( | 318 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels( |
274 JNIEnv* env, | 319 JNIEnv* env, |
275 bool address_only, | 320 bool address_only, |
276 bool include_name, | 321 bool include_name, |
277 std::vector<AutofillProfile*> profiles); | 322 std::vector<AutofillProfile*> profiles); |
278 | 323 |
279 // Pointer to the java counterpart. | 324 // Pointer to the java counterpart. |
280 JavaObjectWeakGlobalRef weak_java_obj_; | 325 JavaObjectWeakGlobalRef weak_java_obj_; |
281 | 326 |
282 // Pointer to the PersonalDataManager for the main profile. | 327 // Pointer to the PersonalDataManager for the main profile. |
283 PersonalDataManager* personal_data_manager_; | 328 PersonalDataManager* personal_data_manager_; |
284 | 329 |
330 // Pointer to the address validator used to normalize addresses. | |
331 std::unique_ptr<AddressValidator> address_validator_; | |
332 | |
333 // Map containing all the regions for which rules were requested along with | |
334 // a bool indicating if they have finished loading. | |
335 std::map<std::string, bool> loaded_rules_; | |
336 | |
337 // The region code of the rules that still loading and necessary for the | |
338 // pending address normalization. | |
339 std::string pending_normalization_region_code_ = ""; | |
340 | |
341 // The guid of the profile to normalize when the rules associated with the | |
342 // |pending_normalization_region_code_| have finished loading. | |
343 std::string pending_normalization_profile_guid_ = ""; | |
344 | |
285 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); | 345 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); |
286 }; | 346 }; |
287 | 347 |
288 } // namespace autofill | 348 } // namespace autofill |
289 | 349 |
290 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 350 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
OLD | NEW |