Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 #ifndef COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 #define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ | |
| 6 #define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | 3 |
| 10 #include "base/memory/ref_counted.h" | 4 #include "base/memory/ref_counted.h" |
| 11 #include "base/observer_list.h" | 5 #include "base/observer_list.h" |
| 12 #include "base/supports_user_data.h" | |
| 13 #include "components/autofill/browser/webdata/autofill_webdata.h" | 6 #include "components/autofill/browser/webdata/autofill_webdata.h" |
| 14 #include "components/autofill/common/form_field_data.h" | 7 #include "components/autofill/common/form_field_data.h" |
| 15 #include "components/webdata/common/web_data_results.h" | 8 #include "components/webdata/common/web_data_results.h" |
| 16 #include "components/webdata/common/web_data_service_base.h" | 9 #include "components/webdata/common/web_data_service_base.h" |
| 17 #include "components/webdata/common/web_data_service_consumer.h" | 10 #include "components/webdata/common/web_data_service_consumer.h" |
| 18 #include "components/webdata/common/web_database.h" | 11 #include "components/webdata/common/web_database.h" |
| 19 | 12 |
| 20 class WebDatabaseService; | |
| 21 | |
| 22 namespace content { | |
| 23 class BrowserContext; | |
| 24 } | |
| 25 | |
| 26 namespace autofill { | 13 namespace autofill { |
| 27 | 14 |
| 28 class AutofillChange; | 15 class AutofillChange; |
| 29 class AutofillProfile; | 16 class AutofillProfile; |
| 30 class AutofillWebDataServiceObserverOnDBThread; | 17 class AutofillWebDataServiceObserverOnDBThread; |
| 31 class AutofillWebDataServiceObserverOnUIThread; | |
| 32 class CreditCard; | 18 class CreditCard; |
| 33 | 19 |
| 34 // API for Autofill web data. | 20 // Backend implentation for the AutofillWebDataService. This class runs on the |
| 35 class AutofillWebDataService : public AutofillWebData, | 21 // DB thread, as it handles reads and writes to the WebDatabase, and functions |
| 36 public WebDataServiceBase { | 22 // in it should only be called from that thread. Most functions here are just |
| 23 // the implementations of the corresponding functions in the Autofill | |
| 24 // WebDataService. | |
| 25 class AutofillWebDataBackend | |
| 26 : public base::RefCountedThreadSafe<AutofillWebDataBackend, | |
| 27 content::BrowserThread::DeleteOnDBThread> { | |
| 37 public: | 28 public: |
| 38 AutofillWebDataService(); | 29 AutofillWebDataBackend(); |
| 39 | 30 |
| 40 AutofillWebDataService(scoped_refptr<WebDatabaseService> wdbs, | 31 // Adds form fields to the web database. |
| 41 const ProfileErrorCallback& callback); | 32 WebDatabase::State AddFormElements( |
| 33 const std::vector<FormFieldData>& fields, | |
| 34 WebDatabase* db); | |
|
Ilya Sherman
2013/04/30 23:52:11
nit: Wrap this as
WebDatabase::State AddFormEle
Cait (Slow)
2013/05/01 23:14:20
Done.
| |
| 42 | 35 |
| 43 // Retrieve an AutofillWebDataService for the given context. | 36 // Returns a vector of values which have been entered in |
| 44 // Can return NULL in some contexts. | 37 // form input fields named |name|. |
|
Ilya Sherman
2013/04/30 23:52:11
nit: Re-wrap to 80-col?
Cait (Slow)
2013/05/01 23:14:20
Done.
| |
| 45 static scoped_refptr<AutofillWebDataService> FromBrowserContext( | 38 scoped_ptr<WDTypedResult> GetFormValuesForElementName( |
| 46 content::BrowserContext* context); | |
| 47 | |
| 48 // Notifies listeners on the UI thread that multiple changes have been made to | |
| 49 // to Autofill records of the database. | |
| 50 // NOTE: This method is intended to be called from the DB thread. It | |
| 51 // it asynchronously notifies listeners on the UI thread. | |
| 52 // |web_data_service| may be NULL for testing purposes. | |
| 53 static void NotifyOfMultipleAutofillChanges( | |
| 54 AutofillWebDataService* web_data_service); | |
| 55 | |
| 56 // WebDataServiceBase implementation. | |
| 57 virtual void ShutdownOnUIThread() OVERRIDE; | |
| 58 | |
| 59 // AutofillWebData implementation. | |
| 60 virtual void AddFormFields( | |
| 61 const std::vector<FormFieldData>& fields) OVERRIDE; | |
| 62 virtual WebDataServiceBase::Handle GetFormValuesForElementName( | |
| 63 const base::string16& name, | 39 const base::string16& name, |
| 64 const base::string16& prefix, | 40 const base::string16& prefix, |
| 65 int limit, | 41 int limit, |
| 66 WebDataServiceConsumer* consumer) OVERRIDE; | 42 WebDatabase* db); |
| 67 virtual void RemoveFormElementsAddedBetween( | 43 |
| 68 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE; | 44 // Removes form elements recorded for Autocomplete from the database. |
| 69 virtual void RemoveExpiredFormElements() OVERRIDE; | 45 WebDatabase::State RemoveFormElementsAddedBetween( |
| 70 virtual void RemoveFormValueForElementName( | 46 const base::Time& delete_begin, |
| 47 const base::Time& delete_end, | |
| 48 WebDatabase* db); | |
| 49 | |
| 50 // Removes expired form elements recorded for Autocomplete from the database. | |
| 51 WebDatabase::State RemoveExpiredFormElements(WebDatabase* db); | |
| 52 | |
| 53 // Removes the Form-value |value| from the database. | |
| 54 WebDatabase::State RemoveFormValueForElementName( | |
| 71 const base::string16& name, | 55 const base::string16& name, |
| 72 const base::string16& value) OVERRIDE; | 56 const base::string16& value, |
| 73 virtual void AddAutofillProfile(const AutofillProfile& profile) OVERRIDE; | 57 WebDatabase* db); |
|
Ilya Sherman
2013/04/30 23:52:11
nit: Wrap this as
WebDatabase::State RemoveForm
Cait (Slow)
2013/05/01 23:14:20
Done.
Cait (Slow)
2013/05/01 23:14:20
Done.
| |
| 74 virtual void UpdateAutofillProfile(const AutofillProfile& profile) OVERRIDE; | |
| 75 virtual void RemoveAutofillProfile(const std::string& guid) OVERRIDE; | |
| 76 virtual WebDataServiceBase::Handle GetAutofillProfiles( | |
| 77 WebDataServiceConsumer* consumer) OVERRIDE; | |
| 78 virtual void AddCreditCard(const CreditCard& credit_card) OVERRIDE; | |
| 79 virtual void UpdateCreditCard(const CreditCard& credit_card) OVERRIDE; | |
| 80 virtual void RemoveCreditCard(const std::string& guid) OVERRIDE; | |
| 81 virtual WebDataServiceBase::Handle GetCreditCards( | |
| 82 WebDataServiceConsumer* consumer) OVERRIDE; | |
| 83 virtual void RemoveAutofillDataModifiedBetween( | |
| 84 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE; | |
| 85 | 58 |
| 59 // Adds an Autofill profile to the web database. | |
| 60 WebDatabase::State AddAutofillProfile( | |
| 61 const AutofillProfile& profile, | |
| 62 WebDatabase* db); | |
| 63 | |
| 64 // Updates an Autofill profile in the web database. | |
| 65 WebDatabase::State UpdateAutofillProfile( | |
| 66 const AutofillProfile& profile, | |
| 67 WebDatabase* db); | |
| 68 | |
| 69 // Removes an Autofill profile from the web database. | |
| 70 WebDatabase::State RemoveAutofillProfile( | |
| 71 const std::string& guid, | |
| 72 WebDatabase* db); | |
| 73 | |
| 74 // Returns all Autofill profiles from the web database. | |
| 75 scoped_ptr<WDTypedResult> GetAutofillProfiles(WebDatabase* db); | |
| 76 | |
| 77 // Adds a credit card to the web database. | |
| 78 WebDatabase::State AddCreditCard( | |
| 79 const CreditCard& credit_card, | |
| 80 WebDatabase* db); | |
| 81 | |
| 82 // Updates a credit card in the web database. | |
| 83 WebDatabase::State UpdateCreditCard( | |
| 84 const CreditCard& credit_card, | |
| 85 WebDatabase* db); | |
| 86 | |
| 87 // Removes a credit card from the web database. | |
| 88 WebDatabase::State RemoveCreditCard( | |
| 89 const std::string& guid, | |
| 90 WebDatabase* db); | |
| 91 | |
| 92 // Returns a vector of all credit cards from the web database. | |
| 93 scoped_ptr<WDTypedResult> GetCreditCards(WebDatabase* db); | |
| 94 | |
| 95 // Removes Autofill records from the database. | |
| 96 WebDatabase::State RemoveAutofillDataModifiedBetween( | |
| 97 const base::Time& delete_begin, | |
| 98 const base::Time& delete_end, | |
| 99 WebDatabase* db); | |
| 100 | |
| 101 // Add an observer to be notified of changes on the DB thread. | |
| 86 void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer); | 102 void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer); |
| 103 | |
| 104 // Remove an observer. | |
| 87 void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer); | 105 void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer); |
| 88 | 106 |
| 89 void AddObserver(AutofillWebDataServiceObserverOnUIThread* observer); | |
| 90 void RemoveObserver(AutofillWebDataServiceObserverOnUIThread* observer); | |
| 91 | |
| 92 // Returns a SupportsUserData objects that may be used to store data | |
| 93 // owned by the DB thread on this object. Should be called only from | |
| 94 // the DB thread, and will be destroyed on the DB thread soon after | |
| 95 // |ShutdownOnUIThread()| is called. | |
| 96 base::SupportsUserData* GetDBUserData(); | |
| 97 | |
| 98 protected: | 107 protected: |
| 99 virtual ~AutofillWebDataService(); | 108 virtual ~AutofillWebDataBackend(); |
| 100 | |
| 101 virtual void ShutdownOnDBThread(); | |
| 102 | 109 |
| 103 private: | 110 private: |
| 104 WebDatabase::State AddFormElementsImpl( | 111 friend struct content::BrowserThread::DeleteOnThread< |
| 105 const std::vector<FormFieldData>& fields, WebDatabase* db); | 112 content::BrowserThread::DB>; |
| 106 scoped_ptr<WDTypedResult> GetFormValuesForElementNameImpl( | 113 friend class base::DeleteHelper<AutofillWebDataBackend>; |
| 107 const base::string16& name, const base::string16& prefix, int limit, | 114 // We have to friend RCTS<> so WIN shared-lib build is happy |
| 108 WebDatabase* db); | 115 // (http://crbug/112250). |
| 109 WebDatabase::State RemoveFormElementsAddedBetweenImpl( | 116 friend class base::RefCountedThreadSafe<AutofillWebDataBackend, |
| 110 const base::Time& delete_begin, const base::Time& delete_end, | 117 content::BrowserThread::DeleteOnDBThread>; |
| 111 WebDatabase* db); | |
| 112 WebDatabase::State RemoveExpiredFormElementsImpl(WebDatabase* db); | |
| 113 WebDatabase::State RemoveFormValueForElementNameImpl( | |
| 114 const base::string16& name, const base::string16& value, WebDatabase* db); | |
| 115 WebDatabase::State AddAutofillProfileImpl( | |
| 116 const AutofillProfile& profile, WebDatabase* db); | |
| 117 WebDatabase::State UpdateAutofillProfileImpl( | |
| 118 const AutofillProfile& profile, WebDatabase* db); | |
| 119 WebDatabase::State RemoveAutofillProfileImpl( | |
| 120 const std::string& guid, WebDatabase* db); | |
| 121 scoped_ptr<WDTypedResult> GetAutofillProfilesImpl(WebDatabase* db); | |
| 122 WebDatabase::State AddCreditCardImpl( | |
| 123 const CreditCard& credit_card, WebDatabase* db); | |
| 124 WebDatabase::State UpdateCreditCardImpl( | |
| 125 const CreditCard& credit_card, WebDatabase* db); | |
| 126 WebDatabase::State RemoveCreditCardImpl( | |
| 127 const std::string& guid, WebDatabase* db); | |
| 128 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db); | |
| 129 WebDatabase::State RemoveAutofillDataModifiedBetweenImpl( | |
| 130 const base::Time& delete_begin, const base::Time& delete_end, | |
| 131 WebDatabase* db); | |
| 132 | 118 |
| 133 // Callbacks to ensure that sensitive info is destroyed if request is | 119 // Callbacks to ensure that sensitive info is destroyed if request is |
| 134 // cancelled. | 120 // cancelled. |
| 135 void DestroyAutofillProfileResult(const WDTypedResult* result); | 121 void DestroyAutofillProfileResult(const WDTypedResult* result); |
| 136 void DestroyAutofillCreditCardResult(const WDTypedResult* result); | 122 void DestroyAutofillCreditCardResult(const WDTypedResult* result); |
| 137 | 123 |
| 138 void NotifyAutofillMultipleChangedOnUIThread(); | 124 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_; |
| 139 | 125 |
| 140 // This makes the destructor public, and thus allows us to aggregate | 126 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackend); |
| 141 // SupportsUserData. It is private by default to prevent incorrect | |
| 142 // usage in class hierarchies where it is inherited by | |
| 143 // reference-counted objects. | |
| 144 class SupportsUserDataAggregatable : public base::SupportsUserData { | |
| 145 public: | |
| 146 SupportsUserDataAggregatable() {} | |
| 147 virtual ~SupportsUserDataAggregatable() {} | |
| 148 private: | |
| 149 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable); | |
| 150 }; | |
| 151 | |
| 152 // Storage for user data to be accessed only on the DB thread. May | |
| 153 // be used e.g. for SyncableService subclasses that need to be owned | |
| 154 // by this object. Is created on first call to |GetDBUserData()|. | |
| 155 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_; | |
| 156 | |
| 157 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_; | |
| 158 ObserverList<AutofillWebDataServiceObserverOnUIThread> ui_observer_list_; | |
| 159 | |
| 160 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataService); | |
| 161 }; | 127 }; |
| 162 | 128 |
| 163 } // namespace autofill | 129 } // namespace autofill |
| 164 | 130 |
| 165 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ | 131 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ |
| OLD | NEW |