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

Side by Side 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, 2 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 "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
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(
gone 2016/09/28 18:04:31 Add a function comment here?
sebsg 2016/09/28 18:50:39 Done.
296 JNIEnv* env,
297 const base::android::JavaParamRef<jobject>& unused_obj);
298
253 private: 299 private:
254 ~PersonalDataManagerAndroid() override; 300 ~PersonalDataManagerAndroid() override;
255 301
256 // Returns the GUIDs of the |profiles| passed as parameter. 302 // Returns the GUIDs of the |profiles| passed as parameter.
257 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( 303 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs(
258 JNIEnv* env, 304 JNIEnv* env,
259 const std::vector<AutofillProfile*>& profiles); 305 const std::vector<AutofillProfile*>& profiles);
260 306
261 // Returns the GUIDs of the |credit_cards| passed as parameter. 307 // Returns the GUIDs of the |credit_cards| passed as parameter.
262 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( 308 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs(
263 JNIEnv* env, 309 JNIEnv* env,
264 const std::vector<CreditCard*>& credit_cards); 310 const std::vector<CreditCard*>& credit_cards);
265 311
312 // Returns whether the rules are loaded for the specified |region_code|.
313 bool AreRulesLoadedForRegion(const std::string& region_code);
314
266 // Gets the labels for the |profiles| passed as parameters. These labels are 315 // Gets the labels for the |profiles| passed as parameters. These labels are
267 // useful for distinguishing the profiles from one another. 316 // useful for distinguishing the profiles from one another.
268 // 317 //
269 // The labels never contain the full name and include at least 2 fields. 318 // The labels never contain the full name and include at least 2 fields.
270 // 319 //
271 // If |address_only| is true, then such fields as phone number, and email 320 // 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. 321 // address are also omitted, but all other fields are included in the label.
273 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels( 322 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels(
274 JNIEnv* env, 323 JNIEnv* env,
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 // The address validator used to normalize addresses.
335 AddressValidator address_validator_;
336
337 // Map associating a region code to a pending normalization.
338 std::map<std::string, Delegate*> pending_normalization_;
339
285 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); 340 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid);
286 }; 341 };
287 342
288 } // namespace autofill 343 } // namespace autofill
289 344
290 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ 345 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698