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

Unified Diff: chrome/browser/autofill/android/personal_data_manager_android.h

Issue 2338283003: [Payments] Normalize addresses before passing them to merchants. (Closed)
Patch Set: Addressed vabr@'s comments Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/android/personal_data_manager_android.h
diff --git a/chrome/browser/autofill/android/personal_data_manager_android.h b/chrome/browser/autofill/android/personal_data_manager_android.h
index a1b74730c2de34670d477820e50c8b3e34459555..4f068d707536da9085359f17d932d7a8663c38d6 100644
--- a/chrome/browser/autofill/android/personal_data_manager_android.h
+++ b/chrome/browser/autofill/android/personal_data_manager_android.h
@@ -8,16 +8,25 @@
#include "base/android/jni_weak_ref.h"
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
+#include "chrome/browser/autofill/validation_rules_storage_factory.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/personal_data_manager_observer.h"
+#include "third_party/libaddressinput/chromium/chrome_address_validator.h"
namespace autofill {
// Android wrapper of the PersonalDataManager which provides access from the
// Java layer. Note that on Android, there's only a single profile, and
// therefore a single instance of this wrapper.
-class PersonalDataManagerAndroid : public PersonalDataManagerObserver {
+class PersonalDataManagerAndroid : public PersonalDataManagerObserver,
+ public LoadRulesListener {
public:
+ // The interface for the normalization request.
+ class Delegate {
+ public:
+ virtual void OnRulesSuccessfullyLoaded() = 0;
+ };
+
PersonalDataManagerAndroid(JNIEnv* env, jobject obj);
// Returns true if personal data manager has loaded the initial data.
@@ -250,6 +259,43 @@ class PersonalDataManagerAndroid : public PersonalDataManagerObserver {
JNIEnv* env,
const base::android::JavaParamRef<jobject>& unused_obj);
+ // These functions help address normalization.
+ // --------------------
+
+ // Starts loading the address validation rules for the specified
+ // |region_code|.
+ void LoadRulesForRegion(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& unused_obj,
+ const base::android::JavaParamRef<jstring>& region_code);
+
+ // Callback of the address validator that is called when the validator has
+ // finished loading the rules for a region.
+ void OnAddressValidationRulesLoaded(const std::string& region_code,
+ bool success) override;
+
+ // Sets up the task to start the address normalization of the profile
+ // associated with the specified |jguid| when the rules associated with the
+ // |jregion_code| have finished loading.
+ void StartAddressNormalizationTask(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& unused_obj,
+ const base::android::JavaParamRef<jstring>& jguid,
+ const base::android::JavaParamRef<jstring>& jregion_code,
+ const base::android::JavaParamRef<jobject>& jdelegate);
+
+ // Normalizes the address of the profile associated with the |guid| with the
+ // rules associates with the |region_code|. Should only be called when the
+ // rules have finished loading.
+ base::android::ScopedJavaLocalRef<jobject> NormalizeAddress(
+ const std::string& guid,
+ const std::string& region_code,
+ JNIEnv* env);
+
+ void CancelPendingAddressNormalization(
gone 2016/09/28 18:04:31 Add a function comment here?
sebsg 2016/09/28 18:50:39 Done.
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& unused_obj);
+
private:
~PersonalDataManagerAndroid() override;
@@ -263,6 +309,9 @@ class PersonalDataManagerAndroid : public PersonalDataManagerObserver {
JNIEnv* env,
const std::vector<CreditCard*>& credit_cards);
+ // Returns whether the rules are loaded for the specified |region_code|.
+ bool AreRulesLoadedForRegion(const std::string& region_code);
+
// Gets the labels for the |profiles| passed as parameters. These labels are
// useful for distinguishing the profiles from one another.
//
@@ -282,6 +331,12 @@ class PersonalDataManagerAndroid : public PersonalDataManagerObserver {
// Pointer to the PersonalDataManager for the main profile.
PersonalDataManager* personal_data_manager_;
+ // The address validator used to normalize addresses.
+ AddressValidator address_validator_;
+
+ // Map associating a region code to a pending normalization.
+ std::map<std::string, Delegate*> pending_normalization_;
+
DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid);
};

Powered by Google App Engine
This is Rietveld 408576698