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

Side by Side Diff: components/autofill/browser/webdata/autofill_webdata_service.cc

Issue 14679005: Create an AutofillBackend interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Convert delegate to interface Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "components/autofill/browser/webdata/autofill_webdata_service.h" 5 #include "components/autofill/browser/webdata/autofill_webdata_service.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "components/autofill/browser/autofill_country.h" 9 #include "components/autofill/browser/autofill_country.h"
10 #include "components/autofill/browser/autofill_profile.h" 10 #include "components/autofill/browser/autofill_profile.h"
11 #include "components/autofill/browser/credit_card.h" 11 #include "components/autofill/browser/credit_card.h"
12 #include "components/autofill/browser/webdata/autofill_change.h" 12 #include "components/autofill/browser/webdata/autofill_change.h"
13 #include "components/autofill/browser/webdata/autofill_entry.h" 13 #include "components/autofill/browser/webdata/autofill_entry.h"
14 #include "components/autofill/browser/webdata/autofill_table.h" 14 #include "components/autofill/browser/webdata/autofill_table.h"
15 #include "components/autofill/browser/webdata/autofill_webdata_backend.h" 15 #include "components/autofill/browser/webdata/autofill_webdata_backend.h"
16 #include "components/autofill/browser/webdata/autofill_webdata_service_observer. h" 16 #include "components/autofill/browser/webdata/autofill_webdata_service_observer. h"
17 #include "components/autofill/common/form_field_data.h" 17 #include "components/autofill/common/form_field_data.h"
18 #include "components/webdata/common/web_data_service_backend.h"
18 #include "components/webdata/common/web_database_service.h" 19 #include "components/webdata/common/web_database_service.h"
19 20
20 using base::Bind; 21 using base::Bind;
21 using base::Time; 22 using base::Time;
22 using content::BrowserThread; 23 using content::BrowserThread;
23 24
24 namespace autofill { 25 namespace autofill {
25 26
26 // static 27 // static
27 void AutofillWebDataService::NotifyOfMultipleAutofillChanges( 28 void AutofillWebDataService::NotifyOfMultipleAutofillChanges(
28 AutofillWebDataService* web_data_service) { 29 AutofillWebDataService* web_data_service) {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
30 31
31 if (!web_data_service) 32 if (!web_data_service)
32 return; 33 return;
33 34
34 BrowserThread::PostTask( 35 BrowserThread::PostTask(
35 BrowserThread::UI, FROM_HERE, 36 BrowserThread::UI, FROM_HERE,
36 Bind(&AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread, 37 Bind(&AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread,
37 make_scoped_refptr(web_data_service))); 38 make_scoped_refptr(web_data_service)));
38 } 39 }
39 40
40 AutofillWebDataService::AutofillWebDataService( 41 AutofillWebDataService::AutofillWebDataService(
41 scoped_refptr<WebDatabaseService> wdbs, 42 scoped_refptr<WebDatabaseService> wdbs,
42 const ProfileErrorCallback& callback) 43 const ProfileErrorCallback& callback)
43 : WebDataServiceBase(wdbs, callback), 44 : WebDataServiceBase(wdbs, callback),
44 autofill_backend_(new AutofillWebDataBackend()) { 45 weak_ptr_factory_(this),
46 autofill_backend_(NULL) {
47
48 base::Closure on_changed_callback = Bind(
49 &AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread,
50 weak_ptr_factory_.GetWeakPtr());
51
52 autofill_backend_ = new AutofillWebDataBackend(
53 wdbs_->GetBackend(),
54 on_changed_callback);
45 } 55 }
46 56
47 AutofillWebDataService::AutofillWebDataService() 57 AutofillWebDataService::AutofillWebDataService()
48 : WebDataServiceBase(NULL, 58 : WebDataServiceBase(NULL,
49 WebDataServiceBase::ProfileErrorCallback()), 59 WebDataServiceBase::ProfileErrorCallback()),
50 autofill_backend_(new AutofillWebDataBackend()) { 60 weak_ptr_factory_(this),
61 autofill_backend_(new AutofillWebDataBackend(NULL, base::Closure())) {
51 } 62 }
52 63
53 void AutofillWebDataService::ShutdownOnUIThread() { 64 void AutofillWebDataService::ShutdownOnUIThread() {
65 weak_ptr_factory_.InvalidateWeakPtrs();
54 BrowserThread::PostTask( 66 BrowserThread::PostTask(
55 BrowserThread::DB, FROM_HERE, 67 BrowserThread::DB, FROM_HERE,
56 base::Bind(&AutofillWebDataService::ShutdownOnDBThread, this)); 68 base::Bind(&AutofillWebDataService::ShutdownOnDBThread, this));
57 WebDataServiceBase::ShutdownOnUIThread(); 69 WebDataServiceBase::ShutdownOnUIThread();
58 } 70 }
59 71
60 void AutofillWebDataService::AddFormFields( 72 void AutofillWebDataService::AddFormFields(
61 const std::vector<FormFieldData>& fields) { 73 const std::vector<FormFieldData>& fields) {
62 wdbs_->ScheduleDBTask(FROM_HERE, 74 wdbs_->ScheduleDBTask(FROM_HERE,
63 Bind(&AutofillWebDataBackend::AddFormElements, 75 Bind(&AutofillWebDataBackend::AddFormElements,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 ui_observer_list_.RemoveObserver(observer); 195 ui_observer_list_.RemoveObserver(observer);
184 } 196 }
185 197
186 base::SupportsUserData* AutofillWebDataService::GetDBUserData() { 198 base::SupportsUserData* AutofillWebDataService::GetDBUserData() {
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
188 if (!db_thread_user_data_) 200 if (!db_thread_user_data_)
189 db_thread_user_data_.reset(new SupportsUserDataAggregatable()); 201 db_thread_user_data_.reset(new SupportsUserDataAggregatable());
190 return db_thread_user_data_.get(); 202 return db_thread_user_data_.get();
191 } 203 }
192 204
205 void AutofillWebDataService::GetSyncableBackend(
206 const base::Callback<void(SyncableServiceBackend*)>& callback) {
207 BrowserThread::PostTask(
208 BrowserThread::DB, FROM_HERE,
Jói 2013/05/07 19:39:41 indent two more spaces, or start right after paren
Cait (Slow) 2013/05/07 20:14:56 Done.
209 base::Bind(callback, autofill_backend_));
210 }
211
193 void AutofillWebDataService::ShutdownOnDBThread() { 212 void AutofillWebDataService::ShutdownOnDBThread() {
194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
195 db_thread_user_data_.reset(); 214 db_thread_user_data_.reset();
196 } 215 }
197 216
198 AutofillWebDataService::~AutofillWebDataService() { 217 AutofillWebDataService::~AutofillWebDataService() {
199 DCHECK(!db_thread_user_data_.get()) << "Forgot to call ShutdownOnUIThread?"; 218 DCHECK(!db_thread_user_data_.get()) << "Forgot to call ShutdownOnUIThread?";
200 } 219 }
201 220
202 void AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread() { 221 void AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread() {
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
204 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnUIThread, 223 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnUIThread,
205 ui_observer_list_, 224 ui_observer_list_,
206 AutofillMultipleChanged()); 225 AutofillMultipleChanged());
207 } 226 }
208 227
209 } // namespace autofill 228 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698