Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / autofill / core / browser / webdata / autofill_webdata_service.h
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.
4
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_
6 #define COMPONENTS_AUTOFILL_CORE_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/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"
20
21 class WebDatabaseService;
22
23 namespace base {
24 class MessageLoopProxy;
25 }
26
27 namespace autofill {
28
29 class AutofillChange;
30 class AutofillEntry;
31 class AutofillProfile;
32 class AutofillWebDataBackend;
33 class AutofillWebDataBackendImpl;
34 class AutofillWebDataServiceObserverOnDBThread;
35 class AutofillWebDataServiceObserverOnUIThread;
36 class CreditCard;
37
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);
48
49   // WebDataServiceBase implementation.
50   void ShutdownOnUIThread() override;
51
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;
59
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;
66   void AddAutofillProfile(const AutofillProfile& profile) override;
67   void UpdateAutofillProfile(const AutofillProfile& profile) override;
68   void RemoveAutofillProfile(const std::string& guid) override;
69   WebDataServiceBase::Handle GetAutofillProfiles(
70       WebDataServiceConsumer* consumer) override;
71   void UpdateAutofillEntries(
72       const std::vector<AutofillEntry>& autofill_entries) override;
73   void AddCreditCard(const CreditCard& credit_card) override;
74   void UpdateCreditCard(const CreditCard& credit_card) override;
75   void RemoveCreditCard(const std::string& guid) override;
76   WebDataServiceBase::Handle GetCreditCards(
77       WebDataServiceConsumer* consumer) override;
78   void RemoveAutofillDataModifiedBetween(const base::Time& delete_begin,
79                                          const base::Time& delete_end) override;
80   void RemoveOriginURLsModifiedBetween(const base::Time& delete_begin,
81                                        const base::Time& delete_end) override;
82
83   void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer);
84   void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer);
85
86   void AddObserver(AutofillWebDataServiceObserverOnUIThread* observer);
87   void RemoveObserver(AutofillWebDataServiceObserverOnUIThread* observer);
88
89   // Returns a SupportsUserData objects that may be used to store data
90   // owned by the DB thread on this object. Should be called only from
91   // the DB thread, and will be destroyed on the DB thread soon after
92   // |ShutdownOnUIThread()| is called.
93   base::SupportsUserData* GetDBUserData();
94
95   // Takes a callback which will be called on the DB thread with a pointer to an
96   // |AutofillWebdataBackend|. This backend can be used to access or update the
97   // WebDatabase directly on the DB thread.
98   void GetAutofillBackend(
99       const base::Callback<void(AutofillWebDataBackend*)>& callback);
100
101  protected:
102   ~AutofillWebDataService() override;
103
104   virtual void NotifyAutofillMultipleChangedOnUIThread();
105
106   base::WeakPtr<AutofillWebDataService> AsWeakPtr() {
107     return weak_ptr_factory_.GetWeakPtr();
108   }
109
110  private:
111   ObserverList<AutofillWebDataServiceObserverOnUIThread> ui_observer_list_;
112
113     // The MessageLoopProxy that this class uses as its UI thread.
114   scoped_refptr<base::MessageLoopProxy> ui_thread_;
115
116   // The MessageLoopProxy that this class uses as its DB thread.
117   scoped_refptr<base::MessageLoopProxy> db_thread_;
118
119   scoped_refptr<AutofillWebDataBackendImpl> autofill_backend_;
120
121   // This factory is used on the UI thread. All vended weak pointers are
122   // invalidated in ShutdownOnUIThread().
123   base::WeakPtrFactory<AutofillWebDataService> weak_ptr_factory_;
124
125   DISALLOW_COPY_AND_ASSIGN(AutofillWebDataService);
126 };
127
128 }  // namespace autofill
129
130 #endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_