| 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 COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ | |
| 6 #define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/observer_list.h" | |
| 13 #include "base/supports_user_data.h" | |
| 14 #include "components/autofill/browser/webdata/autofill_webdata.h" | |
| 15 #include "components/autofill/core/common/form_field_data.h" | |
| 16 #include "components/webdata/common/web_data_results.h" | |
| 17 #include "components/webdata/common/web_data_service_base.h" | |
| 18 #include "components/webdata/common/web_data_service_consumer.h" | |
| 19 #include "components/webdata/common/web_database.h" | |
| 20 | |
| 21 class WebDatabaseService; | |
| 22 | |
| 23 namespace content { | |
| 24 class BrowserContext; | |
| 25 } | |
| 26 | |
| 27 namespace autofill { | |
| 28 | |
| 29 class AutofillChange; | |
| 30 class AutofillProfile; | |
| 31 class AutofillWebDataBackend; | |
| 32 class AutofillWebDataBackendImpl; | |
| 33 class AutofillWebDataServiceObserverOnDBThread; | |
| 34 class AutofillWebDataServiceObserverOnUIThread; | |
| 35 class CreditCard; | |
| 36 | |
| 37 // API for Autofill web data. | |
| 38 class AutofillWebDataService : public AutofillWebData, | |
| 39 public WebDataServiceBase { | |
| 40 public: | |
| 41 AutofillWebDataService(); | |
| 42 | |
| 43 AutofillWebDataService(scoped_refptr<WebDatabaseService> wdbs, | |
| 44 const ProfileErrorCallback& callback); | |
| 45 | |
| 46 // Retrieve an AutofillWebDataService for the given context. | |
| 47 // Can return NULL in some contexts. | |
| 48 static scoped_refptr<AutofillWebDataService> FromBrowserContext( | |
| 49 content::BrowserContext* context); | |
| 50 | |
| 51 // WebDataServiceBase implementation. | |
| 52 virtual void ShutdownOnUIThread() OVERRIDE; | |
| 53 | |
| 54 // AutofillWebData implementation. | |
| 55 virtual void AddFormFields( | |
| 56 const std::vector<FormFieldData>& fields) OVERRIDE; | |
| 57 virtual WebDataServiceBase::Handle GetFormValuesForElementName( | |
| 58 const base::string16& name, | |
| 59 const base::string16& prefix, | |
| 60 int limit, | |
| 61 WebDataServiceConsumer* consumer) OVERRIDE; | |
| 62 | |
| 63 virtual WebDataServiceBase::Handle HasFormElements( | |
| 64 WebDataServiceConsumer* consumer) OVERRIDE; | |
| 65 virtual void RemoveFormElementsAddedBetween( | |
| 66 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE; | |
| 67 virtual void RemoveFormValueForElementName( | |
| 68 const base::string16& name, | |
| 69 const base::string16& value) OVERRIDE; | |
| 70 virtual void AddAutofillProfile(const AutofillProfile& profile) OVERRIDE; | |
| 71 virtual void UpdateAutofillProfile(const AutofillProfile& profile) OVERRIDE; | |
| 72 virtual void RemoveAutofillProfile(const std::string& guid) OVERRIDE; | |
| 73 virtual WebDataServiceBase::Handle GetAutofillProfiles( | |
| 74 WebDataServiceConsumer* consumer) OVERRIDE; | |
| 75 virtual void AddCreditCard(const CreditCard& credit_card) OVERRIDE; | |
| 76 virtual void UpdateCreditCard(const CreditCard& credit_card) OVERRIDE; | |
| 77 virtual void RemoveCreditCard(const std::string& guid) OVERRIDE; | |
| 78 virtual WebDataServiceBase::Handle GetCreditCards( | |
| 79 WebDataServiceConsumer* consumer) OVERRIDE; | |
| 80 virtual void RemoveAutofillDataModifiedBetween( | |
| 81 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE; | |
| 82 virtual void RemoveOriginURLsModifiedBetween( | |
| 83 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE; | |
| 84 | |
| 85 void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer); | |
| 86 void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer); | |
| 87 | |
| 88 void AddObserver(AutofillWebDataServiceObserverOnUIThread* observer); | |
| 89 void RemoveObserver(AutofillWebDataServiceObserverOnUIThread* observer); | |
| 90 | |
| 91 // Returns a SupportsUserData objects that may be used to store data | |
| 92 // owned by the DB thread on this object. Should be called only from | |
| 93 // the DB thread, and will be destroyed on the DB thread soon after | |
| 94 // |ShutdownOnUIThread()| is called. | |
| 95 base::SupportsUserData* GetDBUserData(); | |
| 96 | |
| 97 // Takes a callback which will be called on the DB thread with a pointer to an | |
| 98 // |AutofillWebdataBackend|. This backend can be used to access or update the | |
| 99 // WebDatabase directly on the DB thread. | |
| 100 void GetAutofillBackend( | |
| 101 const base::Callback<void(AutofillWebDataBackend*)>& callback); | |
| 102 | |
| 103 protected: | |
| 104 virtual ~AutofillWebDataService(); | |
| 105 | |
| 106 virtual void NotifyAutofillMultipleChangedOnUIThread(); | |
| 107 | |
| 108 base::WeakPtr<AutofillWebDataService> AsWeakPtr() { | |
| 109 return weak_ptr_factory_.GetWeakPtr(); | |
| 110 } | |
| 111 | |
| 112 private: | |
| 113 ObserverList<AutofillWebDataServiceObserverOnUIThread> ui_observer_list_; | |
| 114 | |
| 115 // This factory is used on the UI thread. All vended weak pointers are | |
| 116 // invalidated in ShutdownOnUIThread(). | |
| 117 base::WeakPtrFactory<AutofillWebDataService> weak_ptr_factory_; | |
| 118 | |
| 119 scoped_refptr<AutofillWebDataBackendImpl> autofill_backend_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataService); | |
| 122 }; | |
| 123 | |
| 124 } // namespace autofill | |
| 125 | |
| 126 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ | |
| OLD | NEW |