| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/string16.h" | 17 #include "base/string16.h" |
| 18 #include "chrome/browser/autofill/autofill_profile.h" | 18 #include "chrome/browser/autofill/autofill_profile.h" |
| 19 #include "chrome/browser/autofill/credit_card.h" | 19 #include "chrome/browser/autofill/credit_card.h" |
| 20 #include "chrome/browser/autofill/field_types.h" | 20 #include "chrome/browser/autofill/field_types.h" |
| 21 #include "chrome/browser/sync/profile_sync_service_observer.h" | 21 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 22 #include "chrome/browser/webdata/web_data_service.h" | 22 #include "chrome/browser/webdata/web_data_service.h" |
| 23 | 23 |
| 24 class AutofillManager; | 24 class AutofillManager; |
| 25 class AutofillMetrics; | 25 class AutofillMetrics; |
| 26 class FormStructure; | 26 class FormStructure; |
| 27 class PersonalDataManagerObserver; |
| 27 class Profile; | 28 class Profile; |
| 28 | 29 |
| 29 // Handles loading and saving Autofill profile information to the web database. | 30 // Handles loading and saving Autofill profile information to the web database. |
| 30 // This class also stores the profiles loaded from the database for use during | 31 // This class also stores the profiles loaded from the database for use during |
| 31 // Autofill. | 32 // Autofill. |
| 32 class PersonalDataManager | 33 class PersonalDataManager |
| 33 : public WebDataServiceConsumer, | 34 : public WebDataServiceConsumer, |
| 34 public ProfileSyncServiceObserver, | 35 public ProfileSyncServiceObserver, |
| 35 public base::RefCountedThreadSafe<PersonalDataManager> { | 36 public base::RefCountedThreadSafe<PersonalDataManager> { |
| 36 public: | 37 public: |
| 37 // An interface the PersonalDataManager uses to notify its clients (observers) | |
| 38 // when it has finished loading personal data from the web database. Register | |
| 39 // the observer via PersonalDataManager::SetObserver. | |
| 40 class Observer { | |
| 41 public: | |
| 42 // Notifies the observer that the PersonalDataManager changed in some way. | |
| 43 virtual void OnPersonalDataChanged() = 0; | |
| 44 | |
| 45 protected: | |
| 46 virtual ~Observer() {} | |
| 47 }; | |
| 48 | |
| 49 // WebDataServiceConsumer implementation: | 38 // WebDataServiceConsumer implementation: |
| 50 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, | 39 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, |
| 51 const WDTypedResult* result); | 40 const WDTypedResult* result); |
| 52 | 41 |
| 53 // Sets the listener to be notified of PersonalDataManager events. | 42 // Sets the listener to be notified of PersonalDataManager events. |
| 54 virtual void SetObserver(PersonalDataManager::Observer* observer); | 43 virtual void SetObserver(PersonalDataManagerObserver* observer); |
| 55 | 44 |
| 56 // Removes |observer| as the observer of this PersonalDataManager. | 45 // Removes |observer| as the observer of this PersonalDataManager. |
| 57 virtual void RemoveObserver(PersonalDataManager::Observer* observer); | 46 virtual void RemoveObserver(PersonalDataManagerObserver* observer); |
| 58 | 47 |
| 59 // ProfileSyncServiceObserver: | 48 // ProfileSyncServiceObserver: |
| 60 virtual void OnStateChanged(); | 49 virtual void OnStateChanged(); |
| 61 | 50 |
| 62 // Scans the given |form| for importable Autofill data. If the form includes | 51 // Scans the given |form| for importable Autofill data. If the form includes |
| 63 // sufficient address data, it is immediately imported. If the form includes | 52 // sufficient address data, it is immediately imported. If the form includes |
| 64 // sufficient credit card data, it is stored into |credit_card|, so that we | 53 // sufficient credit card data, it is stored into |credit_card|, so that we |
| 65 // can prompt the user whether to save this data. | 54 // can prompt the user whether to save this data. |
| 66 // Returns |true| if sufficient address or credit card data was found. | 55 // Returns |true| if sufficient address or credit card data was found. |
| 67 bool ImportFormData(const FormStructure& form, | 56 bool ImportFormData(const FormStructure& form, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 ScopedVector<CreditCard> credit_cards_; | 216 ScopedVector<CreditCard> credit_cards_; |
| 228 | 217 |
| 229 // When the manager makes a request from WebDataService, the database | 218 // When the manager makes a request from WebDataService, the database |
| 230 // is queried on another thread, we record the query handle until we | 219 // is queried on another thread, we record the query handle until we |
| 231 // get called back. We store handles for both profile and credit card queries | 220 // get called back. We store handles for both profile and credit card queries |
| 232 // so they can be loaded at the same time. | 221 // so they can be loaded at the same time. |
| 233 WebDataService::Handle pending_profiles_query_; | 222 WebDataService::Handle pending_profiles_query_; |
| 234 WebDataService::Handle pending_creditcards_query_; | 223 WebDataService::Handle pending_creditcards_query_; |
| 235 | 224 |
| 236 // The observers. | 225 // The observers. |
| 237 ObserverList<Observer> observers_; | 226 ObserverList<PersonalDataManagerObserver> observers_; |
| 238 | 227 |
| 239 private: | 228 private: |
| 240 // For logging UMA metrics. Overridden by metrics tests. | 229 // For logging UMA metrics. Overridden by metrics tests. |
| 241 scoped_ptr<const AutofillMetrics> metric_logger_; | 230 scoped_ptr<const AutofillMetrics> metric_logger_; |
| 242 | 231 |
| 243 // Whether we have already logged the number of profiles this session. | 232 // Whether we have already logged the number of profiles this session. |
| 244 mutable bool has_logged_profile_count_; | 233 mutable bool has_logged_profile_count_; |
| 245 | 234 |
| 246 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); | 235 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); |
| 247 }; | 236 }; |
| 248 | 237 |
| 249 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ | 238 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ |
| OLD | NEW |