| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_WEBDATA_AUTOFILL_WEB_DATA_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_WEBDATA_AUTOFILL_WEB_DATA_SERVICE_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/observer_list.h" | |
| 12 #include "chrome/browser/api/webdata/autofill_web_data.h" | |
| 13 #include "chrome/browser/api/webdata/web_data_results.h" | |
| 14 #include "chrome/browser/api/webdata/web_data_service_base.h" | |
| 15 #include "chrome/browser/api/webdata/web_data_service_consumer.h" | |
| 16 #include "chrome/browser/webdata/web_database.h" | |
| 17 #include "components/autofill/common/form_field_data.h" | |
| 18 | |
| 19 class AutofillChange; | |
| 20 class AutofillProfile; | |
| 21 class AutofillWebDataServiceObserverOnDBThread; | |
| 22 class AutofillWebDataServiceObserverOnUIThread; | |
| 23 class CreditCard; | |
| 24 class WebDatabaseService; | |
| 25 | |
| 26 namespace content { | |
| 27 class BrowserContext; | |
| 28 } | |
| 29 | |
| 30 // API for Autofill web data. | |
| 31 class AutofillWebDataService : public AutofillWebData, | |
| 32 public WebDataServiceBase { | |
| 33 public: | |
| 34 AutofillWebDataService(); | |
| 35 | |
| 36 AutofillWebDataService(scoped_refptr<WebDatabaseService> wdbs, | |
| 37 const ProfileErrorCallback& callback); | |
| 38 | |
| 39 // Retrieve an AutofillWebDataService for the given context. | |
| 40 // Can return NULL in some contexts. | |
| 41 static scoped_refptr<AutofillWebDataService> FromBrowserContext( | |
| 42 content::BrowserContext* context); | |
| 43 | |
| 44 // Notifies listeners on the UI thread that multiple changes have been made to | |
| 45 // to Autofill records of the database. | |
| 46 // NOTE: This method is intended to be called from the DB thread. It | |
| 47 // it asynchronously notifies listeners on the UI thread. | |
| 48 // |web_data_service| may be NULL for testing purposes. | |
| 49 static void NotifyOfMultipleAutofillChanges( | |
| 50 AutofillWebDataService* web_data_service); | |
| 51 | |
| 52 // AutofillWebData implementation. | |
| 53 virtual void AddFormFields( | |
| 54 const std::vector<FormFieldData>& fields) OVERRIDE; | |
| 55 virtual WebDataServiceBase::Handle GetFormValuesForElementName( | |
| 56 const string16& name, | |
| 57 const string16& prefix, | |
| 58 int limit, | |
| 59 WebDataServiceConsumer* consumer) OVERRIDE; | |
| 60 virtual void RemoveFormElementsAddedBetween( | |
| 61 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE; | |
| 62 virtual void RemoveExpiredFormElements() OVERRIDE; | |
| 63 virtual void RemoveFormValueForElementName(const string16& name, | |
| 64 const string16& value) OVERRIDE; | |
| 65 virtual void AddAutofillProfile(const AutofillProfile& profile) OVERRIDE; | |
| 66 virtual void UpdateAutofillProfile(const AutofillProfile& profile) OVERRIDE; | |
| 67 virtual void RemoveAutofillProfile(const std::string& guid) OVERRIDE; | |
| 68 virtual WebDataServiceBase::Handle GetAutofillProfiles( | |
| 69 WebDataServiceConsumer* consumer) OVERRIDE; | |
| 70 virtual void AddCreditCard(const CreditCard& credit_card) OVERRIDE; | |
| 71 virtual void UpdateCreditCard(const CreditCard& credit_card) OVERRIDE; | |
| 72 virtual void RemoveCreditCard(const std::string& guid) OVERRIDE; | |
| 73 virtual WebDataServiceBase::Handle GetCreditCards( | |
| 74 WebDataServiceConsumer* consumer) OVERRIDE; | |
| 75 virtual void RemoveAutofillDataModifiedBetween( | |
| 76 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE; | |
| 77 | |
| 78 void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer); | |
| 79 void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer); | |
| 80 | |
| 81 void AddObserver(AutofillWebDataServiceObserverOnUIThread* observer); | |
| 82 void RemoveObserver(AutofillWebDataServiceObserverOnUIThread* observer); | |
| 83 | |
| 84 protected: | |
| 85 virtual ~AutofillWebDataService(); | |
| 86 | |
| 87 // WebDataServiceBase overrides: | |
| 88 virtual void NotifyDatabaseLoadedOnUIThread() OVERRIDE; | |
| 89 | |
| 90 private: | |
| 91 WebDatabase::State AddFormElementsImpl( | |
| 92 const std::vector<FormFieldData>& fields, WebDatabase* db); | |
| 93 scoped_ptr<WDTypedResult> GetFormValuesForElementNameImpl( | |
| 94 const string16& name, const string16& prefix, int limit, WebDatabase* db); | |
| 95 WebDatabase::State RemoveFormElementsAddedBetweenImpl( | |
| 96 const base::Time& delete_begin, const base::Time& delete_end, | |
| 97 WebDatabase* db); | |
| 98 WebDatabase::State RemoveExpiredFormElementsImpl(WebDatabase* db); | |
| 99 WebDatabase::State RemoveFormValueForElementNameImpl( | |
| 100 const string16& name, const string16& value, WebDatabase* db); | |
| 101 WebDatabase::State AddAutofillProfileImpl( | |
| 102 const AutofillProfile& profile, WebDatabase* db); | |
| 103 WebDatabase::State UpdateAutofillProfileImpl( | |
| 104 const AutofillProfile& profile, WebDatabase* db); | |
| 105 WebDatabase::State RemoveAutofillProfileImpl( | |
| 106 const std::string& guid, WebDatabase* db); | |
| 107 scoped_ptr<WDTypedResult> GetAutofillProfilesImpl(WebDatabase* db); | |
| 108 WebDatabase::State AddCreditCardImpl( | |
| 109 const CreditCard& credit_card, WebDatabase* db); | |
| 110 WebDatabase::State UpdateCreditCardImpl( | |
| 111 const CreditCard& credit_card, WebDatabase* db); | |
| 112 WebDatabase::State RemoveCreditCardImpl( | |
| 113 const std::string& guid, WebDatabase* db); | |
| 114 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db); | |
| 115 WebDatabase::State RemoveAutofillDataModifiedBetweenImpl( | |
| 116 const base::Time& delete_begin, const base::Time& delete_end, | |
| 117 WebDatabase* db); | |
| 118 | |
| 119 // Callbacks to ensure that sensitive info is destroyed if request is | |
| 120 // cancelled. | |
| 121 void DestroyAutofillProfileResult(const WDTypedResult* result); | |
| 122 void DestroyAutofillCreditCardResult(const WDTypedResult* result); | |
| 123 | |
| 124 void NotifyAutofillMultipleChangedOnUIThread(); | |
| 125 | |
| 126 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_; | |
| 127 ObserverList<AutofillWebDataServiceObserverOnUIThread> ui_observer_list_; | |
| 128 | |
| 129 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataService); | |
| 130 }; | |
| 131 | |
| 132 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_WEB_DATA_SERVICE_H_ | |
| OLD | NEW |