Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: components/autofill/core/browser/webdata/autofill_webdata_backend_impl.h

Issue 25783002: Abstract content::BrowserThread usage out of AutofillWebDataBackendImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 #include "base/observer_list.h" 11 #include "base/observer_list.h"
11 #include "base/supports_user_data.h" 12 #include "base/supports_user_data.h"
12 #include "components/autofill/core/browser/webdata/autofill_webdata.h" 13 #include "components/autofill/core/browser/webdata/autofill_webdata.h"
13 #include "components/autofill/core/browser/webdata/autofill_webdata_backend.h" 14 #include "components/autofill/core/browser/webdata/autofill_webdata_backend.h"
14 #include "components/autofill/core/common/form_field_data.h" 15 #include "components/autofill/core/common/form_field_data.h"
15 #include "components/webdata/common/web_data_results.h" 16 #include "components/webdata/common/web_data_results.h"
16 #include "components/webdata/common/web_data_service_base.h" 17 #include "components/webdata/common/web_data_service_base.h"
17 #include "components/webdata/common/web_data_service_consumer.h" 18 #include "components/webdata/common/web_data_service_consumer.h"
18 #include "components/webdata/common/web_database.h" 19 #include "components/webdata/common/web_database.h"
19 #include "content/public/browser/browser_thread.h" 20
21 namespace base {
22 class MessageLoopProxy;
23 }
20 24
21 class WebDataServiceBackend; 25 class WebDataServiceBackend;
22 26
23 namespace autofill { 27 namespace autofill {
24 28
25 class AutofillChange; 29 class AutofillChange;
26 class AutofillProfile; 30 class AutofillProfile;
27 class AutofillWebDataServiceObserverOnDBThread; 31 class AutofillWebDataServiceObserverOnDBThread;
28 class CreditCard; 32 class CreditCard;
29 33
30 // Backend implentation for the AutofillWebDataService. This class runs on the 34 // Backend implentation for the AutofillWebDataService. This class runs on the
31 // DB thread, as it handles reads and writes to the WebDatabase, and functions 35 // 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 36 // in it should only be called from that thread. Most functions here are just
33 // the implementations of the corresponding functions in the Autofill 37 // the implementations of the corresponding functions in the Autofill
34 // WebDataService. 38 // WebDataService.
39 // This class is destroyed on the DB thread.
35 class AutofillWebDataBackendImpl 40 class AutofillWebDataBackendImpl
36 : public base::RefCountedThreadSafe<AutofillWebDataBackendImpl, 41 : public base::RefCountedDeleteOnMessageLoop<AutofillWebDataBackendImpl>,
37 content::BrowserThread::DeleteOnDBThread>,
38 public AutofillWebDataBackend { 42 public AutofillWebDataBackend {
39 public: 43 public:
40 // |web_database_backend| is used to access the WebDatabase directly for 44 // |web_database_backend| is used to access the WebDatabase directly for
41 // Sync-related operations. |on_changed_callback| is a closure which can be 45 // 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 46 // this class uses as its UI and DB threads respectively.
43 // may be called multiple times). 47 // |on_changed_callback| is a closure which can be used to notify the UI
48 // thread of changes initiated by Sync (this callback may be called multiple
49 // times).
44 AutofillWebDataBackendImpl( 50 AutofillWebDataBackendImpl(
45 scoped_refptr<WebDataServiceBackend> web_database_backend, 51 scoped_refptr<WebDataServiceBackend> web_database_backend,
52 scoped_refptr<base::MessageLoopProxy> ui_thread,
53 scoped_refptr<base::MessageLoopProxy> db_thread,
46 const base::Closure& on_changed_callback); 54 const base::Closure& on_changed_callback);
47 55
48 // AutofillWebDataBackend implementation. 56 // AutofillWebDataBackend implementation.
49 virtual void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer) 57 virtual void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer)
50 OVERRIDE; 58 OVERRIDE;
51 virtual void RemoveObserver( 59 virtual void RemoveObserver(
52 AutofillWebDataServiceObserverOnDBThread* observer) OVERRIDE; 60 AutofillWebDataServiceObserverOnDBThread* observer) OVERRIDE;
53 virtual WebDatabase* GetDatabase() OVERRIDE; 61 virtual WebDatabase* GetDatabase() OVERRIDE;
54 virtual void RemoveExpiredFormElements() OVERRIDE; 62 virtual void RemoveExpiredFormElements() OVERRIDE;
55 virtual void NotifyOfMultipleAutofillChanges() OVERRIDE; 63 virtual void NotifyOfMultipleAutofillChanges() OVERRIDE;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // the database. 138 // the database.
131 WebDatabase::State RemoveOriginURLsModifiedBetween( 139 WebDatabase::State RemoveOriginURLsModifiedBetween(
132 const base::Time& delete_begin, 140 const base::Time& delete_begin,
133 const base::Time& delete_end, 141 const base::Time& delete_end,
134 WebDatabase* db); 142 WebDatabase* db);
135 143
136 protected: 144 protected:
137 virtual ~AutofillWebDataBackendImpl(); 145 virtual ~AutofillWebDataBackendImpl();
138 146
139 private: 147 private:
140 friend struct content::BrowserThread::DeleteOnThread< 148 friend class base::RefCountedDeleteOnMessageLoop<AutofillWebDataBackendImpl>;
141 content::BrowserThread::DB>;
142 friend class base::DeleteHelper<AutofillWebDataBackendImpl>; 149 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 150
148 // This makes the destructor public, and thus allows us to aggregate 151 // This makes the destructor public, and thus allows us to aggregate
149 // SupportsUserData. It is private by default to prevent incorrect 152 // SupportsUserData. It is private by default to prevent incorrect
150 // usage in class hierarchies where it is inherited by 153 // usage in class hierarchies where it is inherited by
151 // reference-counted objects. 154 // reference-counted objects.
152 class SupportsUserDataAggregatable : public base::SupportsUserData { 155 class SupportsUserDataAggregatable : public base::SupportsUserData {
153 public: 156 public:
154 SupportsUserDataAggregatable() {} 157 SupportsUserDataAggregatable() {}
155 virtual ~SupportsUserDataAggregatable() {} 158 virtual ~SupportsUserDataAggregatable() {}
156 private: 159 private:
157 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable); 160 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable);
158 }; 161 };
159 162
163 // The MessageLoopProxy that this class uses as its UI thread.
164 scoped_refptr<base::MessageLoopProxy> ui_thread_;
165
166 // The MessageLoopProxy that this class uses as its DB thread.
167 scoped_refptr<base::MessageLoopProxy> db_thread_;
168
160 // Storage for user data to be accessed only on the DB thread. May 169 // 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 170 // be used e.g. for SyncableService subclasses that need to be owned
162 // by this object. Is created on first call to |GetDBUserData()|. 171 // by this object. Is created on first call to |GetDBUserData()|.
163 scoped_ptr<SupportsUserDataAggregatable> user_data_; 172 scoped_ptr<SupportsUserDataAggregatable> user_data_;
164 173
165 WebDatabase::State RemoveExpiredFormElementsImpl(WebDatabase* db); 174 WebDatabase::State RemoveExpiredFormElementsImpl(WebDatabase* db);
166 175
167 // Callbacks to ensure that sensitive info is destroyed if request is 176 // Callbacks to ensure that sensitive info is destroyed if request is
168 // cancelled. 177 // cancelled.
169 void DestroyAutofillProfileResult(const WDTypedResult* result); 178 void DestroyAutofillProfileResult(const WDTypedResult* result);
170 void DestroyAutofillCreditCardResult(const WDTypedResult* result); 179 void DestroyAutofillCreditCardResult(const WDTypedResult* result);
171 180
172 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_; 181 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_;
173 182
174 // WebDataServiceBackend allows direct access to DB. 183 // WebDataServiceBackend allows direct access to DB.
175 // TODO(caitkp): Make it so nobody but us needs direct DB access anymore. 184 // TODO(caitkp): Make it so nobody but us needs direct DB access anymore.
176 scoped_refptr<WebDataServiceBackend> web_database_backend_; 185 scoped_refptr<WebDataServiceBackend> web_database_backend_;
177 186
178 base::Closure on_changed_callback_; 187 base::Closure on_changed_callback_;
179 188
180 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackendImpl); 189 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackendImpl);
181 }; 190 };
182 191
183 } // namespace autofill 192 } // namespace autofill
184 193
185 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_IMP L_H_ 194 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_IMP L_H_
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/webdata/autofill_webdata_backend_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698