OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ | 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_IMPL_H_ |
6 #define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ | 6 #define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_IMPL_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" |
9 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
10 #include "components/autofill/browser/webdata/autofill_webdata.h" | 11 #include "components/autofill/browser/webdata/autofill_webdata.h" |
| 12 #include "components/autofill/browser/webdata/autofill_webdata_backend.h" |
11 #include "components/autofill/common/form_field_data.h" | 13 #include "components/autofill/common/form_field_data.h" |
12 #include "components/webdata/common/web_data_results.h" | 14 #include "components/webdata/common/web_data_results.h" |
13 #include "components/webdata/common/web_data_service_base.h" | 15 #include "components/webdata/common/web_data_service_base.h" |
14 #include "components/webdata/common/web_data_service_consumer.h" | 16 #include "components/webdata/common/web_data_service_consumer.h" |
15 #include "components/webdata/common/web_database.h" | 17 #include "components/webdata/common/web_database.h" |
16 | 18 |
| 19 class WebDataServiceBackend; |
| 20 |
17 namespace autofill { | 21 namespace autofill { |
18 | 22 |
19 class AutofillChange; | 23 class AutofillChange; |
20 class AutofillProfile; | 24 class AutofillProfile; |
21 class AutofillWebDataServiceObserverOnDBThread; | 25 class AutofillWebDataServiceObserverOnDBThread; |
22 class CreditCard; | 26 class CreditCard; |
23 | 27 |
24 // Backend implentation for the AutofillWebDataService. This class runs on the | 28 // Backend implentation for the AutofillWebDataService. This class runs on the |
25 // DB thread, as it handles reads and writes to the WebDatabase, and functions | 29 // DB thread, as it handles reads and writes to the WebDatabase, and functions |
26 // in it should only be called from that thread. Most functions here are just | 30 // in it should only be called from that thread. Most functions here are just |
27 // the implementations of the corresponding functions in the Autofill | 31 // the implementations of the corresponding functions in the Autofill |
28 // WebDataService. | 32 // WebDataService. |
29 class AutofillWebDataBackend | 33 class AutofillWebDataBackendImpl |
30 : public base::RefCountedThreadSafe<AutofillWebDataBackend, | 34 : public base::RefCountedThreadSafe<AutofillWebDataBackendImpl, |
31 content::BrowserThread::DeleteOnDBThread> { | 35 content::BrowserThread::DeleteOnDBThread>, |
| 36 public AutofillWebDataBackend { |
32 public: | 37 public: |
33 AutofillWebDataBackend(); | 38 // |web_database_backend| is used to access the WebDatabase directly for |
| 39 // Sync-related operations. |on_changed_callback| is a closure which can be |
| 40 // used to notify the UI thread of changes initiated by Sync (this callback |
| 41 // may be called multiple times). |
| 42 AutofillWebDataBackendImpl( |
| 43 scoped_refptr<WebDataServiceBackend> web_database_backend, |
| 44 const base::Closure& on_changed_callback); |
| 45 |
| 46 // AutofillWebDataBackend implementation. |
| 47 virtual void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer) |
| 48 OVERRIDE; |
| 49 virtual void RemoveObserver( |
| 50 AutofillWebDataServiceObserverOnDBThread* observer) OVERRIDE; |
| 51 virtual WebDatabase* GetDatabase() OVERRIDE; |
| 52 virtual void RemoveExpiredFormElementsWrapper() OVERRIDE; |
| 53 virtual void NotifyOfMultipleAutofillChanges() OVERRIDE; |
34 | 54 |
35 // Adds form fields to the web database. | 55 // Adds form fields to the web database. |
36 WebDatabase::State AddFormElements(const std::vector<FormFieldData>& fields, | 56 WebDatabase::State AddFormElements(const std::vector<FormFieldData>& fields, |
37 WebDatabase* db); | 57 WebDatabase* db); |
38 | 58 |
39 // Returns a vector of values which have been entered in form input fields | 59 // Returns a vector of values which have been entered in form input fields |
40 // named |name|. | 60 // named |name|. |
41 scoped_ptr<WDTypedResult> GetFormValuesForElementName( | 61 scoped_ptr<WDTypedResult> GetFormValuesForElementName( |
42 const base::string16& name, | 62 const base::string16& name, |
43 const base::string16& prefix, | 63 const base::string16& prefix, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 108 |
89 // Returns a vector of all credit cards from the web database. | 109 // Returns a vector of all credit cards from the web database. |
90 scoped_ptr<WDTypedResult> GetCreditCards(WebDatabase* db); | 110 scoped_ptr<WDTypedResult> GetCreditCards(WebDatabase* db); |
91 | 111 |
92 // Removes Autofill records from the database. | 112 // Removes Autofill records from the database. |
93 WebDatabase::State RemoveAutofillDataModifiedBetween( | 113 WebDatabase::State RemoveAutofillDataModifiedBetween( |
94 const base::Time& delete_begin, | 114 const base::Time& delete_begin, |
95 const base::Time& delete_end, | 115 const base::Time& delete_end, |
96 WebDatabase* db); | 116 WebDatabase* db); |
97 | 117 |
98 // Add an observer to be notified of changes on the DB thread. | |
99 void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer); | |
100 | |
101 // Remove an observer. | |
102 void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer); | |
103 | |
104 protected: | 118 protected: |
105 virtual ~AutofillWebDataBackend(); | 119 virtual ~AutofillWebDataBackendImpl(); |
106 | 120 |
107 private: | 121 private: |
108 friend struct content::BrowserThread::DeleteOnThread< | 122 friend struct content::BrowserThread::DeleteOnThread< |
109 content::BrowserThread::DB>; | 123 content::BrowserThread::DB>; |
110 friend class base::DeleteHelper<AutofillWebDataBackend>; | 124 friend class base::DeleteHelper<AutofillWebDataBackendImpl>; |
111 // We have to friend RCTS<> so WIN shared-lib build is happy | 125 // We have to friend RCTS<> so WIN shared-lib build is happy |
112 // (http://crbug/112250). | 126 // (http://crbug/112250). |
113 friend class base::RefCountedThreadSafe<AutofillWebDataBackend, | 127 friend class base::RefCountedThreadSafe<AutofillWebDataBackendImpl, |
114 content::BrowserThread::DeleteOnDBThread>; | 128 content::BrowserThread::DeleteOnDBThread>; |
115 | 129 |
116 // Callbacks to ensure that sensitive info is destroyed if request is | 130 // Callbacks to ensure that sensitive info is destroyed if request is |
117 // cancelled. | 131 // cancelled. |
118 void DestroyAutofillProfileResult(const WDTypedResult* result); | 132 void DestroyAutofillProfileResult(const WDTypedResult* result); |
119 void DestroyAutofillCreditCardResult(const WDTypedResult* result); | 133 void DestroyAutofillCreditCardResult(const WDTypedResult* result); |
120 | 134 |
121 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_; | 135 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_; |
122 | 136 |
123 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackend); | 137 // WebDataServiceBackend allows direct access to DB. |
| 138 // TODO(caitkp): Make it so nobody but us needs direct DB access anymore. |
| 139 scoped_refptr<WebDataServiceBackend> web_database_backend_; |
| 140 |
| 141 base::Closure on_changed_callback_; |
| 142 |
| 143 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackendImpl); |
124 }; | 144 }; |
125 | 145 |
126 } // namespace autofill | 146 } // namespace autofill |
127 | 147 |
128 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ | 148 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_IMPL_H_ |
OLD | NEW |