ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / components / autofill / core / browser / webdata / autofill_webdata_service.h
blob501a43c769f9a549e9dd4e31d165262391184cb5
1 // Copyright 2013 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.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_
8 #include <vector>
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/core/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"
21 class WebDatabaseService;
23 namespace base {
24 class MessageLoopProxy;
27 namespace autofill {
29 class AutofillChange;
30 class AutofillEntry;
31 class AutofillProfile;
32 class AutofillWebDataBackend;
33 class AutofillWebDataBackendImpl;
34 class AutofillWebDataServiceObserverOnDBThread;
35 class AutofillWebDataServiceObserverOnUIThread;
36 class CreditCard;
38 // API for Autofill web data.
39 class AutofillWebDataService : public AutofillWebData,
40 public WebDataServiceBase {
41 public:
42 AutofillWebDataService(scoped_refptr<base::MessageLoopProxy> ui_thread,
43 scoped_refptr<base::MessageLoopProxy> db_thread);
44 AutofillWebDataService(scoped_refptr<WebDatabaseService> wdbs,
45 scoped_refptr<base::MessageLoopProxy> ui_thread,
46 scoped_refptr<base::MessageLoopProxy> db_thread,
47 const ProfileErrorCallback& callback);
49 // WebDataServiceBase implementation.
50 void ShutdownOnUIThread() override;
52 // AutofillWebData implementation.
53 void AddFormFields(const std::vector<FormFieldData>& fields) override;
54 WebDataServiceBase::Handle GetFormValuesForElementName(
55 const base::string16& name,
56 const base::string16& prefix,
57 int limit,
58 WebDataServiceConsumer* consumer) override;
60 WebDataServiceBase::Handle HasFormElements(
61 WebDataServiceConsumer* consumer) override;
62 void RemoveFormElementsAddedBetween(const base::Time& delete_begin,
63 const base::Time& delete_end) override;
64 void RemoveFormValueForElementName(const base::string16& name,
65 const base::string16& value) override;
67 // Profiles.
68 void AddAutofillProfile(const AutofillProfile& profile) override;
69 void UpdateAutofillProfile(const AutofillProfile& profile) override;
70 void RemoveAutofillProfile(const std::string& guid) override;
71 WebDataServiceBase::Handle GetAutofillProfiles(
72 WebDataServiceConsumer* consumer) override;
74 // Server profiles.
75 WebDataServiceBase::Handle GetAutofillServerProfiles(
76 WebDataServiceConsumer* consumer) override;
78 void UpdateAutofillEntries(
79 const std::vector<AutofillEntry>& autofill_entries) override;
81 // Credit cards.
82 void AddCreditCard(const CreditCard& credit_card) override;
83 void UpdateCreditCard(const CreditCard& credit_card) override;
84 void RemoveCreditCard(const std::string& guid) override;
85 WebDataServiceBase::Handle GetCreditCards(
86 WebDataServiceConsumer* consumer) override;
88 // Server cards.
89 WebDataServiceBase::Handle GetServerCreditCards(
90 WebDataServiceConsumer* consumer) override;
91 void UnmaskServerCreditCard(const std::string& id,
92 const base::string16& full_number) override;
93 void MaskServerCreditCard(const std::string& id) override;
94 void UpdateUnmaskedCardUsageStats(const CreditCard& credit_card) override;
96 void RemoveAutofillDataModifiedBetween(const base::Time& delete_begin,
97 const base::Time& delete_end) override;
98 void RemoveOriginURLsModifiedBetween(const base::Time& delete_begin,
99 const base::Time& delete_end) override;
101 void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer);
102 void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer);
104 void AddObserver(AutofillWebDataServiceObserverOnUIThread* observer);
105 void RemoveObserver(AutofillWebDataServiceObserverOnUIThread* observer);
107 // Returns a SupportsUserData objects that may be used to store data
108 // owned by the DB thread on this object. Should be called only from
109 // the DB thread, and will be destroyed on the DB thread soon after
110 // |ShutdownOnUIThread()| is called.
111 base::SupportsUserData* GetDBUserData();
113 // Takes a callback which will be called on the DB thread with a pointer to an
114 // |AutofillWebdataBackend|. This backend can be used to access or update the
115 // WebDatabase directly on the DB thread.
116 void GetAutofillBackend(
117 const base::Callback<void(AutofillWebDataBackend*)>& callback);
119 protected:
120 ~AutofillWebDataService() override;
122 virtual void NotifyAutofillMultipleChangedOnUIThread();
124 base::WeakPtr<AutofillWebDataService> AsWeakPtr() {
125 return weak_ptr_factory_.GetWeakPtr();
128 private:
129 ObserverList<AutofillWebDataServiceObserverOnUIThread> ui_observer_list_;
131 // The MessageLoopProxy that this class uses as its UI thread.
132 scoped_refptr<base::MessageLoopProxy> ui_thread_;
134 // The MessageLoopProxy that this class uses as its DB thread.
135 scoped_refptr<base::MessageLoopProxy> db_thread_;
137 scoped_refptr<AutofillWebDataBackendImpl> autofill_backend_;
139 // This factory is used on the UI thread. All vended weak pointers are
140 // invalidated in ShutdownOnUIThread().
141 base::WeakPtrFactory<AutofillWebDataService> weak_ptr_factory_;
143 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataService);
146 } // namespace autofill
148 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_