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 <list> | 8 #include <list> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <unordered_set> | 12 #include <unordered_set> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/scoped_vector.h" | |
18 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
19 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
20 #include "build/build_config.h" | 19 #include "build/build_config.h" |
21 #include "components/autofill/core/browser/autofill_profile.h" | 20 #include "components/autofill/core/browser/autofill_profile.h" |
22 #include "components/autofill/core/browser/credit_card.h" | 21 #include "components/autofill/core/browser/credit_card.h" |
23 #include "components/autofill/core/browser/field_types.h" | 22 #include "components/autofill/core/browser/field_types.h" |
24 #include "components/autofill/core/browser/suggestion.h" | 23 #include "components/autofill/core/browser/suggestion.h" |
25 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 24 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
26 #include "components/autofill/core/browser/webdata/autofill_webdata_service_obse
rver.h" | 25 #include "components/autofill/core/browser/webdata/autofill_webdata_service_obse
rver.h" |
27 #include "components/keyed_service/core/keyed_service.h" | 26 #include "components/keyed_service/core/keyed_service.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 PrefService* pref_service, | 77 PrefService* pref_service, |
79 AccountTrackerService* account_tracker, | 78 AccountTrackerService* account_tracker, |
80 SigninManagerBase* signin_manager, | 79 SigninManagerBase* signin_manager, |
81 bool is_off_the_record); | 80 bool is_off_the_record); |
82 | 81 |
83 // Called once the sync service is known to be instantiated. Note that it may | 82 // Called once the sync service is known to be instantiated. Note that it may |
84 // not be started, but it's preferences can be queried. | 83 // not be started, but it's preferences can be queried. |
85 void OnSyncServiceInitialized(syncer::SyncService* sync_service); | 84 void OnSyncServiceInitialized(syncer::SyncService* sync_service); |
86 | 85 |
87 // WebDataServiceConsumer: | 86 // WebDataServiceConsumer: |
88 void OnWebDataServiceRequestDone(WebDataServiceBase::Handle h, | 87 void OnWebDataServiceRequestDone( |
89 const WDTypedResult* result) override; | 88 WebDataServiceBase::Handle h, |
| 89 std::unique_ptr<WDTypedResult> result) override; |
90 | 90 |
91 // AutofillWebDataServiceObserverOnUIThread: | 91 // AutofillWebDataServiceObserverOnUIThread: |
92 void AutofillMultipleChanged() override; | 92 void AutofillMultipleChanged() override; |
93 void SyncStarted(syncer::ModelType model_type) override; | 93 void SyncStarted(syncer::ModelType model_type) override; |
94 | 94 |
95 // Adds a listener to be notified of PersonalDataManager events. | 95 // Adds a listener to be notified of PersonalDataManager events. |
96 virtual void AddObserver(PersonalDataManagerObserver* observer); | 96 virtual void AddObserver(PersonalDataManagerObserver* observer); |
97 | 97 |
98 // Removes |observer| as an observer of this PersonalDataManager. | 98 // Removes |observer| as an observer of this PersonalDataManager. |
99 virtual void RemoveObserver(PersonalDataManagerObserver* observer); | 99 virtual void RemoveObserver(PersonalDataManagerObserver* observer); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 bool HasPassword(); | 178 bool HasPassword(); |
179 | 179 |
180 // Returns whether the personal data has been loaded from the web database. | 180 // Returns whether the personal data has been loaded from the web database. |
181 virtual bool IsDataLoaded() const; | 181 virtual bool IsDataLoaded() const; |
182 | 182 |
183 // This PersonalDataManager owns these profiles and credit cards. Their | 183 // This PersonalDataManager owns these profiles and credit cards. Their |
184 // lifetime is until the web database is updated with new profile and credit | 184 // lifetime is until the web database is updated with new profile and credit |
185 // card information, respectively. |GetProfiles()| returns both web and | 185 // card information, respectively. |GetProfiles()| returns both web and |
186 // auxiliary profiles. |web_profiles()| returns only web profiles. | 186 // auxiliary profiles. |web_profiles()| returns only web profiles. |
187 virtual const std::vector<AutofillProfile*>& GetProfiles() const; | 187 virtual const std::vector<AutofillProfile*>& GetProfiles() const; |
188 virtual const std::vector<AutofillProfile*>& web_profiles() const; | 188 virtual std::vector<AutofillProfile*> web_profiles() const; |
189 // Returns just LOCAL_CARD cards. | 189 // Returns just LOCAL_CARD cards. |
190 virtual const std::vector<CreditCard*>& GetLocalCreditCards() const; | 190 virtual std::vector<CreditCard*> GetLocalCreditCards() const; |
191 // Returns all credit cards, server and local. | 191 // Returns all credit cards, server and local. |
192 virtual const std::vector<CreditCard*>& GetCreditCards() const; | 192 virtual const std::vector<CreditCard*>& GetCreditCards() const; |
193 | 193 |
194 // Returns true if there is some data synced from Wallet. | 194 // Returns true if there is some data synced from Wallet. |
195 bool HasServerData() const; | 195 bool HasServerData() const; |
196 | 196 |
197 // Returns the profiles to suggest to the user, ordered by frecency. | 197 // Returns the profiles to suggest to the user, ordered by frecency. |
198 const std::vector<AutofillProfile*> GetProfilesToSuggest() const; | 198 const std::vector<AutofillProfile*> GetProfilesToSuggest() const; |
199 | 199 |
200 // Loads profiles that can suggest data for |type|. |field_contents| is the | 200 // Loads profiles that can suggest data for |type|. |field_contents| is the |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 const std::string& app_locale() const { return app_locale_; } | 232 const std::string& app_locale() const { return app_locale_; } |
233 | 233 |
234 // Checks suitability of |profile| for adding to the user's set of profiles. | 234 // Checks suitability of |profile| for adding to the user's set of profiles. |
235 static bool IsValidLearnableProfile(const AutofillProfile& profile, | 235 static bool IsValidLearnableProfile(const AutofillProfile& profile, |
236 const std::string& app_locale); | 236 const std::string& app_locale); |
237 | 237 |
238 // Merges |new_profile| into one of the |existing_profiles| if possible; | 238 // Merges |new_profile| into one of the |existing_profiles| if possible; |
239 // otherwise appends |new_profile| to the end of that list. Fills | 239 // otherwise appends |new_profile| to the end of that list. Fills |
240 // |merged_profiles| with the result. Returns the |guid| of the new or updated | 240 // |merged_profiles| with the result. Returns the |guid| of the new or updated |
241 // profile. | 241 // profile. |
242 std::string MergeProfile(const AutofillProfile& new_profile, | 242 std::string MergeProfile( |
243 std::vector<AutofillProfile*> existing_profiles, | 243 const AutofillProfile& new_profile, |
244 const std::string& app_locale, | 244 std::vector<std::unique_ptr<AutofillProfile>>* existing_profiles, |
245 std::vector<AutofillProfile>* merged_profiles); | 245 const std::string& app_locale, |
| 246 std::vector<AutofillProfile>* merged_profiles); |
246 | 247 |
247 // Returns true if |country_code| is a country that the user is likely to | 248 // Returns true if |country_code| is a country that the user is likely to |
248 // be associated with the user. More concretely, it checks if there are any | 249 // be associated with the user. More concretely, it checks if there are any |
249 // addresses with this country or if the user's system timezone is in the | 250 // addresses with this country or if the user's system timezone is in the |
250 // given country. | 251 // given country. |
251 virtual bool IsCountryOfInterest(const std::string& country_code) const; | 252 virtual bool IsCountryOfInterest(const std::string& country_code) const; |
252 | 253 |
253 // Returns our best guess for the country a user is likely to use when | 254 // Returns our best guess for the country a user is likely to use when |
254 // inputting a new address. The value is calculated once and cached, so it | 255 // inputting a new address. The value is calculated once and cached, so it |
255 // will only update when Chrome is restarted. | 256 // will only update when Chrome is restarted. |
256 virtual const std::string& GetDefaultCountryCodeForNewAddress() const; | 257 virtual const std::string& GetDefaultCountryCodeForNewAddress() const; |
257 | 258 |
258 // De-dupe credit card to suggest. Full server cards are prefered over their | 259 // De-dupe credit card to suggest. Full server cards are preferred over their |
259 // local duplicates, and local cards are preferred over their masked server | 260 // local duplicates, and local cards are preferred over their masked server |
260 // card duplicate. | 261 // card duplicate. |
261 static void DedupeCreditCardToSuggest( | 262 static void DedupeCreditCardToSuggest( |
262 std::list<CreditCard*>* cards_to_suggest); | 263 std::list<CreditCard*>* cards_to_suggest); |
263 | 264 |
264 // Notifies test observers that personal data has changed. | 265 // Notifies test observers that personal data has changed. |
265 void NotifyPersonalDataChangedForTest() { | 266 void NotifyPersonalDataChangedForTest() { |
266 NotifyPersonalDataChanged(); | 267 NotifyPersonalDataChanged(); |
267 } | 268 } |
268 | 269 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 } | 388 } |
388 | 389 |
389 // The backing database that this PersonalDataManager uses. | 390 // The backing database that this PersonalDataManager uses. |
390 scoped_refptr<AutofillWebDataService> database_; | 391 scoped_refptr<AutofillWebDataService> database_; |
391 | 392 |
392 // True if personal data has been loaded from the web database. | 393 // True if personal data has been loaded from the web database. |
393 bool is_data_loaded_; | 394 bool is_data_loaded_; |
394 | 395 |
395 // The loaded web profiles. These are constructed from entries on web pages | 396 // The loaded web profiles. These are constructed from entries on web pages |
396 // and from manually editing in the settings. | 397 // and from manually editing in the settings. |
397 ScopedVector<AutofillProfile> web_profiles_; | 398 std::vector<std::unique_ptr<AutofillProfile>> web_profiles_; |
398 | 399 |
399 // Profiles read from the user's account stored on the server. | 400 // Profiles read from the user's account stored on the server. |
400 mutable ScopedVector<AutofillProfile> server_profiles_; | 401 mutable std::vector<std::unique_ptr<AutofillProfile>> server_profiles_; |
401 | 402 |
402 // Storage for web profiles. Contents are weak references. Lifetime managed | 403 // Storage for web profiles. Contents are weak references. Lifetime managed |
403 // by |web_profiles_|. | 404 // by |web_profiles_|. |
404 mutable std::vector<AutofillProfile*> profiles_; | 405 mutable std::vector<AutofillProfile*> profiles_; |
405 | 406 |
406 // Cached versions of the local and server credit cards. | 407 // Cached versions of the local and server credit cards. |
407 ScopedVector<CreditCard> local_credit_cards_; | 408 std::vector<std::unique_ptr<CreditCard>> local_credit_cards_; |
408 ScopedVector<CreditCard> server_credit_cards_; | 409 std::vector<std::unique_ptr<CreditCard>> server_credit_cards_; |
409 | 410 |
410 // A combination of local and server credit cards. The pointers are owned | 411 // A combination of local and server credit cards. The pointers are owned |
411 // by the local/sverver_credit_cards_ vectors. | 412 // by the local/sverver_credit_cards_ vectors. |
412 mutable std::vector<CreditCard*> credit_cards_; | 413 mutable std::vector<CreditCard*> credit_cards_; |
413 | 414 |
414 // When the manager makes a request from WebDataServiceBase, the database | 415 // When the manager makes a request from WebDataServiceBase, the database |
415 // is queried on another thread, we record the query handle until we | 416 // is queried on another thread, we record the query handle until we |
416 // get called back. We store handles for both profile and credit card queries | 417 // get called back. We store handles for both profile and credit card queries |
417 // so they can be loaded at the same time. | 418 // so they can be loaded at the same time. |
418 WebDataServiceBase::Handle pending_profiles_query_; | 419 WebDataServiceBase::Handle pending_profiles_query_; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 | 477 |
477 // Goes through all the |existing_profiles| and merges all similar unverified | 478 // Goes through all the |existing_profiles| and merges all similar unverified |
478 // profiles together. Also discards unverified profiles that are similar to a | 479 // profiles together. Also discards unverified profiles that are similar to a |
479 // verified profile. All the profiles except the results of the merges will be | 480 // verified profile. All the profiles except the results of the merges will be |
480 // added to |profile_guids_to_delete|. This routine should be run once per | 481 // added to |profile_guids_to_delete|. This routine should be run once per |
481 // major version. | 482 // major version. |
482 // | 483 // |
483 // This method should only be called by ApplyDedupingRoutine. It is split for | 484 // This method should only be called by ApplyDedupingRoutine. It is split for |
484 // testing purposes. | 485 // testing purposes. |
485 void DedupeProfiles( | 486 void DedupeProfiles( |
486 std::vector<AutofillProfile*>* existing_profiles, | 487 std::vector<std::unique_ptr<AutofillProfile>>* existing_profiles, |
487 std::unordered_set<AutofillProfile*>* profile_guids_to_delete); | 488 std::unordered_set<AutofillProfile*>* profile_guids_to_delete); |
488 | 489 |
489 const std::string app_locale_; | 490 const std::string app_locale_; |
490 | 491 |
491 // The default country code for new addresses. | 492 // The default country code for new addresses. |
492 mutable std::string default_country_code_; | 493 mutable std::string default_country_code_; |
493 | 494 |
494 // The PrefService that this instance uses. Must outlive this instance. | 495 // The PrefService that this instance uses. Must outlive this instance. |
495 PrefService* pref_service_; | 496 PrefService* pref_service_; |
496 | 497 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 // validation rules. | 532 // validation rules. |
532 scoped_refptr<net::URLRequestContextGetter> context_getter_; | 533 scoped_refptr<net::URLRequestContextGetter> context_getter_; |
533 #endif | 534 #endif |
534 | 535 |
535 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); | 536 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); |
536 }; | 537 }; |
537 | 538 |
538 } // namespace autofill | 539 } // namespace autofill |
539 | 540 |
540 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PERSONAL_DATA_MANAGER_H_ | 541 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PERSONAL_DATA_MANAGER_H_ |
OLD | NEW |