Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: chrome/browser/autofill/android/personal_data_manager_android.h

Issue 2686613003: [Payments] Move address normalization code from android to native. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/autofill/validation_rules_storage_factory.h"
13 #include "components/autofill/core/browser/personal_data_manager.h" 12 #include "components/autofill/core/browser/personal_data_manager.h"
14 #include "components/autofill/core/browser/personal_data_manager_observer.h" 13 #include "components/autofill/core/browser/personal_data_manager_observer.h"
15 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" 14 #include "components/payments/address_validator_helper.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
23 : public PersonalDataManagerObserver, 22 : public PersonalDataManagerObserver {
24 public LoadRulesListener,
25 public base::SupportsWeakPtr<PersonalDataManagerAndroid> {
26 public: 23 public:
27 // The interface for the normalization request. 24 // The interface for the normalization request.
28 class Delegate { 25 class Delegate {
29 public: 26 public:
30 virtual void OnRulesSuccessfullyLoaded() = 0; 27 virtual void OnRulesSuccessfullyLoaded() = 0;
31 virtual ~Delegate() {} 28 virtual ~Delegate() {}
32 }; 29 };
33 30
34 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); 31 PersonalDataManagerAndroid(JNIEnv* env, jobject obj);
35 32
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // These functions help address normalization. 290 // These functions help address normalization.
294 // -------------------- 291 // --------------------
295 292
296 // Starts loading the address validation rules for the specified 293 // Starts loading the address validation rules for the specified
297 // |region_code|. 294 // |region_code|.
298 void LoadRulesForRegion( 295 void LoadRulesForRegion(
299 JNIEnv* env, 296 JNIEnv* env,
300 const base::android::JavaParamRef<jobject>& unused_obj, 297 const base::android::JavaParamRef<jobject>& unused_obj,
301 const base::android::JavaParamRef<jstring>& region_code); 298 const base::android::JavaParamRef<jstring>& region_code);
302 299
303 // Callback of the address validator that is called when the validator has
304 // finished loading the rules for a region.
305 void OnAddressValidationRulesLoaded(const std::string& region_code,
306 bool success) override;
307
308 // Normalizes the address of the profile associated with the |jguid| 300 // Normalizes the address of the profile associated with the |jguid|
309 // synchronously if the |jregion_code| rules have finished loading. Otherwise 301 // synchronously if the |jregion_code| rules have finished loading. Otherwise
310 // sets up the task to start the address normalization when the rules have 302 // sets up the task to start the address normalization when the rules have
311 // finished loading. In either case, sends the normalized profile to the 303 // finished loading. In either case, sends the normalized profile to the
312 // |jdelegate|. Returns whether the normalization will happen asynchronously. 304 // |jdelegate|.
313 jboolean StartAddressNormalization( 305 void StartAddressNormalization(
314 JNIEnv* env, 306 JNIEnv* env,
315 const base::android::JavaParamRef<jobject>& unused_obj, 307 const base::android::JavaParamRef<jobject>& unused_obj,
316 const base::android::JavaParamRef<jstring>& jguid, 308 const base::android::JavaParamRef<jstring>& jguid,
317 const base::android::JavaParamRef<jstring>& jregion_code, 309 const base::android::JavaParamRef<jstring>& jregion_code,
318 const base::android::JavaParamRef<jobject>& jdelegate); 310 const base::android::JavaParamRef<jobject>& jdelegate);
319 311
320 // Normalizes the address of the profile associated with the |guid| with the
321 // rules associates with the |region_code|. Should only be called when the
322 // rules have finished loading.
323 base::android::ScopedJavaLocalRef<jobject> NormalizeAddress(
324 const std::string& guid,
325 const std::string& region_code,
326 JNIEnv* env);
327
328 // Cancels the pending address normalization task.
329 void CancelPendingAddressNormalizations(
please use gerrit instead 2017/02/14 21:31:08 Is it OK to remove this functionality?
sebsg 2017/02/15 16:18:30 It was not currently used so I think it's ok to re
330 JNIEnv* env,
331 const base::android::JavaParamRef<jobject>& unused_obj);
332
333 // Checks whether the Autofill PersonalDataManager has profiles. 312 // Checks whether the Autofill PersonalDataManager has profiles.
334 jboolean HasProfiles(JNIEnv* env, 313 jboolean HasProfiles(JNIEnv* env,
335 const base::android::JavaParamRef<jobject>& unused_obj); 314 const base::android::JavaParamRef<jobject>& unused_obj);
336 315
337 // Checks whether the Autofill PersonalDataManager has credit cards. 316 // Checks whether the Autofill PersonalDataManager has credit cards.
338 jboolean HasCreditCards( 317 jboolean HasCreditCards(
339 JNIEnv* env, 318 JNIEnv* env,
340 const base::android::JavaParamRef<jobject>& unused_obj); 319 const base::android::JavaParamRef<jobject>& unused_obj);
341 320
342 private: 321 private:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 const base::android::JavaParamRef<jobject>& jprofile, 359 const base::android::JavaParamRef<jobject>& jprofile,
381 bool inlude_country_in_label); 360 bool inlude_country_in_label);
382 361
383 // Pointer to the java counterpart. 362 // Pointer to the java counterpart.
384 JavaObjectWeakGlobalRef weak_java_obj_; 363 JavaObjectWeakGlobalRef weak_java_obj_;
385 364
386 // Pointer to the PersonalDataManager for the main profile. 365 // Pointer to the PersonalDataManager for the main profile.
387 PersonalDataManager* personal_data_manager_; 366 PersonalDataManager* personal_data_manager_;
388 367
389 // The address validator used to normalize addresses. 368 // The address validator used to normalize addresses.
390 AddressValidator address_validator_; 369 payments::AddressValidatorHelper address_validator_helper_;
391
392 // Map associating a region code to pending normalizations.
393 std::map<std::string, std::vector<std::unique_ptr<Delegate>>>
394 pending_normalization_;
395 370
396 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); 371 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid);
397 }; 372 };
398 373
399 } // namespace autofill 374 } // namespace autofill
400 375
401 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ 376 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698