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

Side by Side Diff: components/autofill/core/browser/personal_data_manager.h

Issue 1989173005: [Autofill] Dedupe similar profiles on insertion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 COMPONENTS_AUTOFILL_CORE_BROWSER_PERSONAL_DATA_MANAGER_H_ 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_PERSONAL_DATA_MANAGER_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_PERSONAL_DATA_MANAGER_H_ 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_PERSONAL_DATA_MANAGER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 const std::string& app_locale() const { return app_locale_; } 207 const std::string& app_locale() const { return app_locale_; }
208 208
209 // Checks suitability of |profile| for adding to the user's set of profiles. 209 // Checks suitability of |profile| for adding to the user's set of profiles.
210 static bool IsValidLearnableProfile(const AutofillProfile& profile, 210 static bool IsValidLearnableProfile(const AutofillProfile& profile,
211 const std::string& app_locale); 211 const std::string& app_locale);
212 212
213 // Merges |new_profile| into one of the |existing_profiles| if possible; 213 // Merges |new_profile| into one of the |existing_profiles| if possible;
214 // otherwise appends |new_profile| to the end of that list. Fills 214 // otherwise appends |new_profile| to the end of that list. Fills
215 // |merged_profiles| with the result. Returns the |guid| of the new or updated 215 // |merged_profiles| with the result. Returns the |guid| of the new or updated
216 // profile. 216 // profile.
217 static std::string MergeProfile( 217 std::string MergeProfile(const AutofillProfile& new_profile,
218 const AutofillProfile& new_profile, 218 std::vector<AutofillProfile*> existing_profiles,
219 std::vector<AutofillProfile*> existing_profiles, 219 const std::string& app_locale,
220 const std::string& app_locale, 220 std::vector<AutofillProfile>* merged_profiles);
221 std::vector<AutofillProfile>* merged_profiles);
222 221
223 // Returns true if |country_code| is a country that the user is likely to 222 // Returns true if |country_code| is a country that the user is likely to
224 // be associated with the user. More concretely, it checks if there are any 223 // be associated with the user. More concretely, it checks if there are any
225 // addresses with this country or if the user's system timezone is in the 224 // addresses with this country or if the user's system timezone is in the
226 // given country. 225 // given country.
227 virtual bool IsCountryOfInterest(const std::string& country_code) const; 226 virtual bool IsCountryOfInterest(const std::string& country_code) const;
228 227
229 // Returns our best guess for the country a user is likely to use when 228 // Returns our best guess for the country a user is likely to use when
230 // inputting a new address. The value is calculated once and cached, so it 229 // inputting a new address. The value is calculated once and cached, so it
231 // will only update when Chrome is restarted. 230 // will only update when Chrome is restarted.
232 virtual const std::string& GetDefaultCountryCodeForNewAddress() const; 231 virtual const std::string& GetDefaultCountryCodeForNewAddress() const;
233 232
234 // De-dupe credit card to suggest. Full server cards are prefered over their 233 // De-dupe credit card to suggest. Full server cards are prefered over their
235 // local duplicates, and local cards are preferred over their masked server 234 // local duplicates, and local cards are preferred over their masked server
236 // card duplicate. 235 // card duplicate.
237 static void DedupeCreditCardToSuggest( 236 static void DedupeCreditCardToSuggest(
238 std::list<const CreditCard*>* cards_to_suggest); 237 std::list<const CreditCard*>* cards_to_suggest);
239 238
240 protected: 239 protected:
241 // Only PersonalDataManagerFactory and certain tests can create instances of 240 // Only PersonalDataManagerFactory and certain tests can create instances of
242 // PersonalDataManager. 241 // PersonalDataManager.
243 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FirstMiddleLast); 242 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FirstMiddleLast);
244 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, AutofillIsEnabledAtStartup); 243 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, AutofillIsEnabledAtStartup);
244 FRIEND_TEST_ALL_PREFIXES(PersonalDataManagerTest,
245 FindAndMergeDuplicateProfiles_ProfilesToDelete);
246 FRIEND_TEST_ALL_PREFIXES(PersonalDataManagerTest,
247 FindAndMergeDuplicateProfiles_MergedProfileValues);
245 friend class autofill::AutofillInteractiveTest; 248 friend class autofill::AutofillInteractiveTest;
246 friend class autofill::AutofillTest; 249 friend class autofill::AutofillTest;
247 friend class autofill::PersonalDataManagerFactory; 250 friend class autofill::PersonalDataManagerFactory;
248 friend class PersonalDataManagerTest; 251 friend class PersonalDataManagerTest;
249 #if defined(OS_IOS) 252 #if defined(OS_IOS)
250 // TODO(crbug.com/513344): Remove this once Chrome on iOS is unforked. 253 // TODO(crbug.com/513344): Remove this once Chrome on iOS is unforked.
251 friend class ::PersonalDataManagerFactory; 254 friend class ::PersonalDataManagerFactory;
252 #endif 255 #endif
253 friend class ProfileSyncServiceAutofillTest; 256 friend class ProfileSyncServiceAutofillTest;
254 friend class ::RemoveAutofillTester; 257 friend class ::RemoveAutofillTester;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 const std::vector<AutofillProfile*>& GetProfiles( 393 const std::vector<AutofillProfile*>& GetProfiles(
391 bool record_metrics) const; 394 bool record_metrics) const;
392 395
393 // Returns credit card suggestions based on the |cards_to_suggest| and the 396 // Returns credit card suggestions based on the |cards_to_suggest| and the
394 // |type| and |field_contents| of the credit card field. 397 // |type| and |field_contents| of the credit card field.
395 std::vector<Suggestion> GetSuggestionsForCards( 398 std::vector<Suggestion> GetSuggestionsForCards(
396 const AutofillType& type, 399 const AutofillType& type,
397 const base::string16& field_contents, 400 const base::string16& field_contents,
398 const std::list<const CreditCard*>& cards_to_suggest) const; 401 const std::list<const CreditCard*>& cards_to_suggest) const;
399 402
403 // Goes through the |existing_profiles| to find similar profiles to
404 // |profile_to_merge|. If a similar profile is found |profile_to_merge| is
405 // merged into it, gets deleted and the result becomes the new
406 // |profile_to_merge|. The process continues until the end of
407 // |existing_profiles| is reached.
408 //
409 // |existing_profiles| should be sorted by frecency to ensure that the more
410 // relevant profiles get merged into the less relevant ones.
411 void FindMergeAndDeleteDuplicateProfiles(
412 const std::vector<AutofillProfile*>& existing_profiles,
413 AutofillProfile* profile_to_merge,
414 const std::string& app_locale);
415
416 // Goes through the |existing_profiles| to find similar profiles to
417 // |profile_to_merge|. If a similar profile is found |profile_to_merge| is
418 // merged into it, its GUID gets added to |profile_guids_to_delete| and the
419 // result becomes the new |profile_to_merge|. The process continues until the
420 // end of |existing_profiles| is reached.
421 void FindAndMergeDuplicateProfiles(
Roger McFarlane (Chromium) 2016/06/08 18:55:38 a comment that this is exposed for testability.
sebsg 2016/06/08 21:58:46 Done.
422 const std::vector<AutofillProfile*>& existing_profiles,
423 AutofillProfile* profile_to_merge,
424 std::vector<std::string>* profile_guids_to_delete,
425 const std::string& app_locale);
426
400 const std::string app_locale_; 427 const std::string app_locale_;
401 428
402 // The default country code for new addresses. 429 // The default country code for new addresses.
403 mutable std::string default_country_code_; 430 mutable std::string default_country_code_;
404 431
405 // The PrefService that this instance uses. Must outlive this instance. 432 // The PrefService that this instance uses. Must outlive this instance.
406 PrefService* pref_service_; 433 PrefService* pref_service_;
407 434
408 // The AccountTrackerService that this instance uses. Must outlive this 435 // The AccountTrackerService that this instance uses. Must outlive this
409 // instance. 436 // instance.
(...skipping 18 matching lines...) Expand all
428 455
429 // An observer to listen for changes to prefs::kAutofillWalletImportEnabled. 456 // An observer to listen for changes to prefs::kAutofillWalletImportEnabled.
430 std::unique_ptr<BooleanPrefMember> wallet_enabled_pref_; 457 std::unique_ptr<BooleanPrefMember> wallet_enabled_pref_;
431 458
432 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); 459 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager);
433 }; 460 };
434 461
435 } // namespace autofill 462 } // namespace autofill
436 463
437 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PERSONAL_DATA_MANAGER_H_ 464 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PERSONAL_DATA_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698