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_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_IMPL_H _ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_IMPL_H _ |
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_IMPL_H _ | 6 #define COMPONENTS_AUTOFILL_CORE_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/ref_counted_delete_on_message_loop.h" | |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop_proxy.h" | |
Ilya Sherman
2013/10/02 23:27:01
nit: Seems like this could just be forward-declare
blundell
2013/10/03 05:23:34
Done.
| |
10 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
11 #include "base/supports_user_data.h" | 13 #include "base/supports_user_data.h" |
12 #include "components/autofill/core/browser/webdata/autofill_webdata.h" | 14 #include "components/autofill/core/browser/webdata/autofill_webdata.h" |
13 #include "components/autofill/core/browser/webdata/autofill_webdata_backend.h" | 15 #include "components/autofill/core/browser/webdata/autofill_webdata_backend.h" |
14 #include "components/autofill/core/common/form_field_data.h" | 16 #include "components/autofill/core/common/form_field_data.h" |
15 #include "components/webdata/common/web_data_results.h" | 17 #include "components/webdata/common/web_data_results.h" |
16 #include "components/webdata/common/web_data_service_base.h" | 18 #include "components/webdata/common/web_data_service_base.h" |
17 #include "components/webdata/common/web_data_service_consumer.h" | 19 #include "components/webdata/common/web_data_service_consumer.h" |
18 #include "components/webdata/common/web_database.h" | 20 #include "components/webdata/common/web_database.h" |
19 #include "content/public/browser/browser_thread.h" | |
20 | 21 |
21 class WebDataServiceBackend; | 22 class WebDataServiceBackend; |
22 | 23 |
23 namespace autofill { | 24 namespace autofill { |
24 | 25 |
25 class AutofillChange; | 26 class AutofillChange; |
26 class AutofillProfile; | 27 class AutofillProfile; |
27 class AutofillWebDataServiceObserverOnDBThread; | 28 class AutofillWebDataServiceObserverOnDBThread; |
28 class CreditCard; | 29 class CreditCard; |
29 | 30 |
30 // Backend implentation for the AutofillWebDataService. This class runs on the | 31 // Backend implentation for the AutofillWebDataService. This class runs on the |
31 // DB thread, as it handles reads and writes to the WebDatabase, and functions | 32 // DB thread, as it handles reads and writes to the WebDatabase, and functions |
32 // in it should only be called from that thread. Most functions here are just | 33 // in it should only be called from that thread. Most functions here are just |
33 // the implementations of the corresponding functions in the Autofill | 34 // the implementations of the corresponding functions in the Autofill |
34 // WebDataService. | 35 // WebDataService. |
36 // This class is destroyed on the DB thread. | |
35 class AutofillWebDataBackendImpl | 37 class AutofillWebDataBackendImpl |
36 : public base::RefCountedThreadSafe<AutofillWebDataBackendImpl, | 38 : public base::RefCountedDeleteOnMessageLoop<AutofillWebDataBackendImpl>, |
37 content::BrowserThread::DeleteOnDBThread>, | |
38 public AutofillWebDataBackend { | 39 public AutofillWebDataBackend { |
39 public: | 40 public: |
40 // |web_database_backend| is used to access the WebDatabase directly for | 41 // |web_database_backend| is used to access the WebDatabase directly for |
41 // Sync-related operations. |on_changed_callback| is a closure which can be | 42 // Sync-related operations. |ui_thread| and |db_thread| are the threads that |
42 // used to notify the UI thread of changes initiated by Sync (this callback | 43 // this class uses as its UI and DB threads respectively. |
43 // may be called multiple times). | 44 // |on_changed_callback| is a closure which can be used to notify the UI |
45 // thread of changes initiated by Sync (this callback may be called multiple | |
46 // times). | |
44 AutofillWebDataBackendImpl( | 47 AutofillWebDataBackendImpl( |
45 scoped_refptr<WebDataServiceBackend> web_database_backend, | 48 scoped_refptr<WebDataServiceBackend> web_database_backend, |
49 const scoped_refptr<base::MessageLoopProxy>& ui_thread, | |
50 const scoped_refptr<base::MessageLoopProxy>& db_thread, | |
Ilya Sherman
2013/10/02 23:27:01
Hmm, should scoped_refptrs really be passed by con
blundell
2013/10/03 05:23:34
Looking through the codebase, both get used. I'll
| |
46 const base::Closure& on_changed_callback); | 51 const base::Closure& on_changed_callback); |
47 | 52 |
48 // AutofillWebDataBackend implementation. | 53 // AutofillWebDataBackend implementation. |
49 virtual void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer) | 54 virtual void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer) |
50 OVERRIDE; | 55 OVERRIDE; |
51 virtual void RemoveObserver( | 56 virtual void RemoveObserver( |
52 AutofillWebDataServiceObserverOnDBThread* observer) OVERRIDE; | 57 AutofillWebDataServiceObserverOnDBThread* observer) OVERRIDE; |
53 virtual WebDatabase* GetDatabase() OVERRIDE; | 58 virtual WebDatabase* GetDatabase() OVERRIDE; |
54 virtual void RemoveExpiredFormElements() OVERRIDE; | 59 virtual void RemoveExpiredFormElements() OVERRIDE; |
55 virtual void NotifyOfMultipleAutofillChanges() OVERRIDE; | 60 virtual void NotifyOfMultipleAutofillChanges() OVERRIDE; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 // the database. | 135 // the database. |
131 WebDatabase::State RemoveOriginURLsModifiedBetween( | 136 WebDatabase::State RemoveOriginURLsModifiedBetween( |
132 const base::Time& delete_begin, | 137 const base::Time& delete_begin, |
133 const base::Time& delete_end, | 138 const base::Time& delete_end, |
134 WebDatabase* db); | 139 WebDatabase* db); |
135 | 140 |
136 protected: | 141 protected: |
137 virtual ~AutofillWebDataBackendImpl(); | 142 virtual ~AutofillWebDataBackendImpl(); |
138 | 143 |
139 private: | 144 private: |
140 friend struct content::BrowserThread::DeleteOnThread< | 145 friend class base::RefCountedDeleteOnMessageLoop<AutofillWebDataBackendImpl>; |
141 content::BrowserThread::DB>; | |
142 friend class base::DeleteHelper<AutofillWebDataBackendImpl>; | 146 friend class base::DeleteHelper<AutofillWebDataBackendImpl>; |
143 // We have to friend RCTS<> so WIN shared-lib build is happy | |
144 // (http://crbug/112250). | |
145 friend class base::RefCountedThreadSafe<AutofillWebDataBackendImpl, | |
146 content::BrowserThread::DeleteOnDBThread>; | |
147 | 147 |
148 // This makes the destructor public, and thus allows us to aggregate | 148 // This makes the destructor public, and thus allows us to aggregate |
149 // SupportsUserData. It is private by default to prevent incorrect | 149 // SupportsUserData. It is private by default to prevent incorrect |
150 // usage in class hierarchies where it is inherited by | 150 // usage in class hierarchies where it is inherited by |
151 // reference-counted objects. | 151 // reference-counted objects. |
152 class SupportsUserDataAggregatable : public base::SupportsUserData { | 152 class SupportsUserDataAggregatable : public base::SupportsUserData { |
153 public: | 153 public: |
154 SupportsUserDataAggregatable() {} | 154 SupportsUserDataAggregatable() {} |
155 virtual ~SupportsUserDataAggregatable() {} | 155 virtual ~SupportsUserDataAggregatable() {} |
156 private: | 156 private: |
157 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable); | 157 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable); |
158 }; | 158 }; |
159 | 159 |
160 // The MessageLoopProxy that this class uses as its UI thread. | |
161 scoped_refptr<base::MessageLoopProxy> ui_thread_; | |
162 | |
163 // The MessageLoopProxy that this class uses as its DB thread. | |
164 scoped_refptr<base::MessageLoopProxy> db_thread_; | |
165 | |
160 // Storage for user data to be accessed only on the DB thread. May | 166 // Storage for user data to be accessed only on the DB thread. May |
161 // be used e.g. for SyncableService subclasses that need to be owned | 167 // be used e.g. for SyncableService subclasses that need to be owned |
162 // by this object. Is created on first call to |GetDBUserData()|. | 168 // by this object. Is created on first call to |GetDBUserData()|. |
163 scoped_ptr<SupportsUserDataAggregatable> user_data_; | 169 scoped_ptr<SupportsUserDataAggregatable> user_data_; |
164 | 170 |
165 WebDatabase::State RemoveExpiredFormElementsImpl(WebDatabase* db); | 171 WebDatabase::State RemoveExpiredFormElementsImpl(WebDatabase* db); |
166 | 172 |
167 // Callbacks to ensure that sensitive info is destroyed if request is | 173 // Callbacks to ensure that sensitive info is destroyed if request is |
168 // cancelled. | 174 // cancelled. |
169 void DestroyAutofillProfileResult(const WDTypedResult* result); | 175 void DestroyAutofillProfileResult(const WDTypedResult* result); |
170 void DestroyAutofillCreditCardResult(const WDTypedResult* result); | 176 void DestroyAutofillCreditCardResult(const WDTypedResult* result); |
171 | 177 |
172 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_; | 178 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_; |
173 | 179 |
174 // WebDataServiceBackend allows direct access to DB. | 180 // WebDataServiceBackend allows direct access to DB. |
175 // TODO(caitkp): Make it so nobody but us needs direct DB access anymore. | 181 // TODO(caitkp): Make it so nobody but us needs direct DB access anymore. |
176 scoped_refptr<WebDataServiceBackend> web_database_backend_; | 182 scoped_refptr<WebDataServiceBackend> web_database_backend_; |
177 | 183 |
178 base::Closure on_changed_callback_; | 184 base::Closure on_changed_callback_; |
179 | 185 |
180 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackendImpl); | 186 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackendImpl); |
181 }; | 187 }; |
182 | 188 |
183 } // namespace autofill | 189 } // namespace autofill |
184 | 190 |
185 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_IMP L_H_ | 191 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_IMP L_H_ |
OLD | NEW |