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

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

Powered by Google App Engine
This is Rietveld 408576698