| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_PERSONAL_DATA_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ |
| 6 #define CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ | 6 #define CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "chrome/browser/autofill/autofill_profile.h" | 16 #include "chrome/browser/autofill/autofill_profile.h" |
| 17 #include "chrome/browser/autofill/credit_card.h" | 17 #include "chrome/browser/autofill/credit_card.h" |
| 18 #include "chrome/browser/autofill/field_types.h" | 18 #include "chrome/browser/autofill/field_types.h" |
| 19 #include "chrome/browser/api/webdata/autofill_web_data_service.h" |
| 20 #include "chrome/browser/api/webdata/web_data_service_consumer.h" |
| 21 |
| 19 #include "chrome/browser/profiles/profile_keyed_service.h" | 22 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 20 #include "chrome/browser/sync/profile_sync_service_observer.h" | 23 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 21 #include "chrome/browser/webdata/web_data_service.h" | |
| 22 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
| 24 | 26 |
| 25 class AutofillMetrics; | 27 class AutofillMetrics; |
| 26 class FormStructure; | 28 class FormStructure; |
| 27 class PersonalDataManagerObserver; | 29 class PersonalDataManagerObserver; |
| 28 class Profile; | 30 class Profile; |
| 29 | 31 |
| 30 namespace autofill_helper { | 32 namespace autofill_helper { |
| 31 void SetProfiles(int, std::vector<AutofillProfile>*); | 33 void SetProfiles(int, std::vector<AutofillProfile>*); |
| 32 void SetCreditCards(int, std::vector<CreditCard>*); | 34 void SetCreditCards(int, std::vector<CreditCard>*); |
| 33 } | 35 } |
| 34 | 36 |
| 35 // Handles loading and saving Autofill profile information to the web database. | 37 // Handles loading and saving Autofill profile information to the web database. |
| 36 // This class also stores the profiles loaded from the database for use during | 38 // This class also stores the profiles loaded from the database for use during |
| 37 // Autofill. | 39 // Autofill. |
| 38 class PersonalDataManager | 40 class PersonalDataManager |
| 39 : public WebDataServiceConsumer, | 41 : public WebDataServiceConsumer, |
| 40 public ProfileSyncServiceObserver, | 42 public ProfileSyncServiceObserver, |
| 41 public ProfileKeyedService, | 43 public ProfileKeyedService, |
| 42 public content::NotificationObserver { | 44 public content::NotificationObserver { |
| 43 public: | 45 public: |
| 44 // WebDataServiceConsumer: | 46 // WebDataServiceConsumer: |
| 45 virtual void OnWebDataServiceRequestDone( | 47 virtual void OnWebDataServiceRequestDone( |
| 46 WebDataService::Handle h, | 48 WebDataServiceBase::Handle h, |
| 47 const WDTypedResult* result) OVERRIDE; | 49 const WDTypedResult* result) OVERRIDE; |
| 48 | 50 |
| 49 // Sets the listener to be notified of PersonalDataManager events. | 51 // Sets the listener to be notified of PersonalDataManager events. |
| 50 virtual void SetObserver(PersonalDataManagerObserver* observer); | 52 virtual void SetObserver(PersonalDataManagerObserver* observer); |
| 51 | 53 |
| 52 // Removes |observer| as the observer of this PersonalDataManager. | 54 // Removes |observer| as the observer of this PersonalDataManager. |
| 53 virtual void RemoveObserver(PersonalDataManagerObserver* observer); | 55 virtual void RemoveObserver(PersonalDataManagerObserver* observer); |
| 54 | 56 |
| 55 // ProfileSyncServiceObserver: | 57 // ProfileSyncServiceObserver: |
| 56 virtual void OnStateChanged() OVERRIDE; | 58 virtual void OnStateChanged() OVERRIDE; |
| 57 | 59 |
| 58 // ProfileKeyedService: | 60 // ProfileKeyedService: |
| 59 // Cancels any pending requests to WebDataService and stops listening for Sync | 61 // Cancels any pending requests to WebDataServiceBase and stops |
| 60 // notifications. | 62 // listening for Sync notifications. |
| 61 virtual void Shutdown() OVERRIDE; | 63 virtual void Shutdown() OVERRIDE; |
| 62 | 64 |
| 63 // content::NotificationObserver: | 65 // content::NotificationObserver: |
| 64 // Observes "batch" changes made by Sync and refreshes data from the | 66 // Observes "batch" changes made by Sync and refreshes data from the |
| 65 // WebDataService in response. | 67 // WebDataServiceBase in response. |
| 66 virtual void Observe(int type, | 68 virtual void Observe(int type, |
| 67 const content::NotificationSource& source, | 69 const content::NotificationSource& source, |
| 68 const content::NotificationDetails& details) OVERRIDE; | 70 const content::NotificationDetails& details) OVERRIDE; |
| 69 | 71 |
| 70 // Scans the given |form| for importable Autofill data. If the form includes | 72 // Scans the given |form| for importable Autofill data. If the form includes |
| 71 // sufficient address data, it is immediately imported. If the form includes | 73 // sufficient address data, it is immediately imported. If the form includes |
| 72 // sufficient credit card data, it is stored into |credit_card|, so that we | 74 // sufficient credit card data, it is stored into |credit_card|, so that we |
| 73 // can prompt the user whether to save this data. | 75 // can prompt the user whether to save this data. |
| 74 // Returns |true| if sufficient address or credit card data was found. | 76 // Returns |true| if sufficient address or credit card data was found. |
| 75 bool ImportFormData(const FormStructure& form, | 77 bool ImportFormData(const FormStructure& form, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 virtual void LoadProfiles(); | 184 virtual void LoadProfiles(); |
| 183 | 185 |
| 184 // Loads the auxiliary profiles. Currently Mac only. | 186 // Loads the auxiliary profiles. Currently Mac only. |
| 185 void LoadAuxiliaryProfiles() const; | 187 void LoadAuxiliaryProfiles() const; |
| 186 | 188 |
| 187 // Loads the saved credit cards from the web database. | 189 // Loads the saved credit cards from the web database. |
| 188 virtual void LoadCreditCards(); | 190 virtual void LoadCreditCards(); |
| 189 | 191 |
| 190 // Receives the loaded profiles from the web data service and stores them in | 192 // Receives the loaded profiles from the web data service and stores them in |
| 191 // |credit_cards_|. | 193 // |credit_cards_|. |
| 192 void ReceiveLoadedProfiles(WebDataService::Handle h, | 194 void ReceiveLoadedProfiles(WebDataServiceBase::Handle h, |
| 193 const WDTypedResult* result); | 195 const WDTypedResult* result); |
| 194 | 196 |
| 195 // Receives the loaded credit cards from the web data service and stores them | 197 // Receives the loaded credit cards from the web data service and stores them |
| 196 // in |credit_cards_|. | 198 // in |credit_cards_|. |
| 197 void ReceiveLoadedCreditCards(WebDataService::Handle h, | 199 void ReceiveLoadedCreditCards(WebDataServiceBase::Handle h, |
| 198 const WDTypedResult* result); | 200 const WDTypedResult* result); |
| 199 | 201 |
| 200 // Cancels a pending query to the web database. |handle| is a pointer to the | 202 // Cancels a pending query to the web database. |handle| is a pointer to the |
| 201 // query handle. | 203 // query handle. |
| 202 void CancelPendingQuery(WebDataService::Handle* handle); | 204 void CancelPendingQuery(WebDataServiceBase::Handle* handle); |
| 203 | 205 |
| 204 // Saves |imported_profile| to the WebDB if it exists. | 206 // Saves |imported_profile| to the WebDB if it exists. |
| 205 virtual void SaveImportedProfile(const AutofillProfile& imported_profile); | 207 virtual void SaveImportedProfile(const AutofillProfile& imported_profile); |
| 206 | 208 |
| 207 // Notifies Sync about data migration if necessary. | 209 // Notifies Sync about data migration if necessary. |
| 208 void EmptyMigrationTrash(); | 210 void EmptyMigrationTrash(); |
| 209 | 211 |
| 210 // The first time this is called, logs an UMA metrics for the number of | 212 // The first time this is called, logs an UMA metrics for the number of |
| 211 // profiles the user has. On subsequent calls, does nothing. | 213 // profiles the user has. On subsequent calls, does nothing. |
| 212 void LogProfileCount() const; | 214 void LogProfileCount() const; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 230 // Auxiliary profiles. | 232 // Auxiliary profiles. |
| 231 mutable ScopedVector<AutofillProfile> auxiliary_profiles_; | 233 mutable ScopedVector<AutofillProfile> auxiliary_profiles_; |
| 232 | 234 |
| 233 // Storage for combined web and auxiliary profiles. Contents are weak | 235 // Storage for combined web and auxiliary profiles. Contents are weak |
| 234 // references. Lifetime managed by |web_profiles_| and |auxiliary_profiles_|. | 236 // references. Lifetime managed by |web_profiles_| and |auxiliary_profiles_|. |
| 235 mutable std::vector<AutofillProfile*> profiles_; | 237 mutable std::vector<AutofillProfile*> profiles_; |
| 236 | 238 |
| 237 // The loaded credit cards. | 239 // The loaded credit cards. |
| 238 ScopedVector<CreditCard> credit_cards_; | 240 ScopedVector<CreditCard> credit_cards_; |
| 239 | 241 |
| 240 // When the manager makes a request from WebDataService, the database | 242 // When the manager makes a request from WebDataServiceBase, the database |
| 241 // is queried on another thread, we record the query handle until we | 243 // is queried on another thread, we record the query handle until we |
| 242 // get called back. We store handles for both profile and credit card queries | 244 // get called back. We store handles for both profile and credit card queries |
| 243 // so they can be loaded at the same time. | 245 // so they can be loaded at the same time. |
| 244 WebDataService::Handle pending_profiles_query_; | 246 WebDataServiceBase::Handle pending_profiles_query_; |
| 245 WebDataService::Handle pending_creditcards_query_; | 247 WebDataServiceBase::Handle pending_creditcards_query_; |
| 246 | 248 |
| 247 // The observers. | 249 // The observers. |
| 248 ObserverList<PersonalDataManagerObserver> observers_; | 250 ObserverList<PersonalDataManagerObserver> observers_; |
| 249 | 251 |
| 250 private: | 252 private: |
| 251 // Kicks off asynchronous loading of profiles and credit cards. | 253 // Kicks off asynchronous loading of profiles and credit cards. |
| 252 void Init(Profile* profile); | 254 void Init(Profile* profile); |
| 253 | 255 |
| 254 // For logging UMA metrics. Overridden by metrics tests. | 256 // For logging UMA metrics. Overridden by metrics tests. |
| 255 scoped_ptr<const AutofillMetrics> metric_logger_; | 257 scoped_ptr<const AutofillMetrics> metric_logger_; |
| 256 | 258 |
| 257 // Whether we have already logged the number of profiles this session. | 259 // Whether we have already logged the number of profiles this session. |
| 258 mutable bool has_logged_profile_count_; | 260 mutable bool has_logged_profile_count_; |
| 259 | 261 |
| 260 // Manages registration lifetime for NotificationObserver implementation. | 262 // Manages registration lifetime for NotificationObserver implementation. |
| 261 content::NotificationRegistrar notification_registrar_; | 263 content::NotificationRegistrar notification_registrar_; |
| 262 | 264 |
| 263 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); | 265 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); |
| 264 }; | 266 }; |
| 265 | 267 |
| 266 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ | 268 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ |
| OLD | NEW |