| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| 415 // Goes through the |existing_profiles| to find similar profiles to |
| 416 // |profile_to_merge|. If a similar profile is found |profile_to_merge| is |
| 417 // merged into it, its GUID gets added to |profile_guids_to_delete| and the |
| 418 // result becomes the new |profile_to_merge|. The process continues until the |
| 419 // end of |existing_profiles| is reached. |
| 420 // |
| 421 // Note: This method is exposed for testability and should not be called |
| 422 // directly in the code except in FindMergeAndDeleteDuplicateProfiles. Please |
| 423 // use that method instead. |
| 424 void FindAndMergeDuplicateProfiles( |
| 425 const std::vector<AutofillProfile*>& existing_profiles, |
| 426 AutofillProfile* profile_to_merge, |
| 427 std::vector<std::string>* profile_guids_to_delete); |
| 428 |
| 400 const std::string app_locale_; | 429 const std::string app_locale_; |
| 401 | 430 |
| 402 // The default country code for new addresses. | 431 // The default country code for new addresses. |
| 403 mutable std::string default_country_code_; | 432 mutable std::string default_country_code_; |
| 404 | 433 |
| 405 // The PrefService that this instance uses. Must outlive this instance. | 434 // The PrefService that this instance uses. Must outlive this instance. |
| 406 PrefService* pref_service_; | 435 PrefService* pref_service_; |
| 407 | 436 |
| 408 // The AccountTrackerService that this instance uses. Must outlive this | 437 // The AccountTrackerService that this instance uses. Must outlive this |
| 409 // instance. | 438 // instance. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 428 | 457 |
| 429 // An observer to listen for changes to prefs::kAutofillWalletImportEnabled. | 458 // An observer to listen for changes to prefs::kAutofillWalletImportEnabled. |
| 430 std::unique_ptr<BooleanPrefMember> wallet_enabled_pref_; | 459 std::unique_ptr<BooleanPrefMember> wallet_enabled_pref_; |
| 431 | 460 |
| 432 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); | 461 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); |
| 433 }; | 462 }; |
| 434 | 463 |
| 435 } // namespace autofill | 464 } // namespace autofill |
| 436 | 465 |
| 437 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PERSONAL_DATA_MANAGER_H_ | 466 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PERSONAL_DATA_MANAGER_H_ |
| OLD | NEW |