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

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

Issue 14081043: Hook up Autofill Backend interface to SyncableServices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_database_service.h" 18 #include "components/webdata/common/web_database_service.h"
19 19
20 using base::Bind; 20 using base::Bind;
21 using base::Time; 21 using base::Time;
22 using content::BrowserThread; 22 using content::BrowserThread;
23 23
24 namespace autofill { 24 namespace autofill {
25 25
26 // static
27 void AutofillWebDataService::NotifyOfMultipleAutofillChanges(
28 AutofillWebDataService* web_data_service) {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
30
31 if (!web_data_service)
32 return;
33
34 BrowserThread::PostTask(
35 BrowserThread::UI, FROM_HERE,
36 Bind(&AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread,
37 make_scoped_refptr(web_data_service)));
38 }
39
40 AutofillWebDataService::AutofillWebDataService( 26 AutofillWebDataService::AutofillWebDataService(
41 scoped_refptr<WebDatabaseService> wdbs, 27 scoped_refptr<WebDatabaseService> wdbs,
42 const ProfileErrorCallback& callback) 28 const ProfileErrorCallback& callback)
43 : WebDataServiceBase(wdbs, callback), 29 : WebDataServiceBase(wdbs, callback),
44 autofill_backend_(new AutofillWebDataBackend()) { 30 autofill_backend_(new AutofillWebDataBackend()) {
45 } 31 }
46 32
47 AutofillWebDataService::AutofillWebDataService() 33 AutofillWebDataService::AutofillWebDataService()
48 : WebDataServiceBase(NULL, 34 : WebDataServiceBase(NULL,
49 WebDataServiceBase::ProfileErrorCallback()), 35 WebDataServiceBase::ProfileErrorCallback()),
(...skipping 13 matching lines...) Expand all
63 if (!db_thread_user_data_) 49 if (!db_thread_user_data_)
64 db_thread_user_data_.reset(new SupportsUserDataAggregatable()); 50 db_thread_user_data_.reset(new SupportsUserDataAggregatable());
65 return db_thread_user_data_.get(); 51 return db_thread_user_data_.get();
66 } 52 }
67 53
68 void AutofillWebDataService::ShutdownOnDBThread() { 54 void AutofillWebDataService::ShutdownOnDBThread() {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
70 db_thread_user_data_.reset(); 56 db_thread_user_data_.reset();
71 } 57 }
72 58
59 void AutofillWebDataService::GetDelegateOnDB(
60 const DelegateOnDBCallback& del_callback) {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
62 wdbs_->GetDatabaseOnDB(
63 Bind(&AutofillWebDataBackend::GetDelegate, autofill_backend_,
64 del_callback));
65 }
66
73 void AutofillWebDataService::AddFormFields( 67 void AutofillWebDataService::AddFormFields(
74 const std::vector<FormFieldData>& fields) { 68 const std::vector<FormFieldData>& fields) {
75 wdbs_->ScheduleDBTask(FROM_HERE, 69 wdbs_->ScheduleDBTask(FROM_HERE,
76 Bind(&AutofillWebDataBackend::AddFormElementsImpl, 70 Bind(&AutofillWebDataBackend::AddFormElementsImpl,
77 autofill_backend_, fields)); 71 autofill_backend_, fields));
78 } 72 }
79 73
80 WebDataServiceBase::Handle AutofillWebDataService::GetFormValuesForElementName( 74 WebDataServiceBase::Handle AutofillWebDataService::GetFormValuesForElementName(
81 const base::string16& name, const base::string16& prefix, int limit, 75 const base::string16& name, const base::string16& prefix, int limit,
82 WebDataServiceConsumer* consumer) { 76 WebDataServiceConsumer* consumer) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 void AutofillWebDataService::RemoveAutofillDataModifiedBetween( 159 void AutofillWebDataService::RemoveAutofillDataModifiedBetween(
166 const Time& delete_begin, 160 const Time& delete_begin,
167 const Time& delete_end) { 161 const Time& delete_end) {
168 wdbs_->ScheduleDBTask( 162 wdbs_->ScheduleDBTask(
169 FROM_HERE, 163 FROM_HERE,
170 Bind(&AutofillWebDataBackend::RemoveAutofillDataModifiedBetweenImpl, 164 Bind(&AutofillWebDataBackend::RemoveAutofillDataModifiedBetweenImpl,
171 autofill_backend_, delete_begin, delete_end)); 165 autofill_backend_, delete_begin, delete_end));
172 } 166 }
173 167
174 void AutofillWebDataService::AddObserver( 168 void AutofillWebDataService::AddObserver(
175 AutofillWebDataServiceObserverOnDBThread* observer) {
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
177 if (autofill_backend_)
178 autofill_backend_->AddObserver(observer);
179 }
180
181 void AutofillWebDataService::RemoveObserver(
182 AutofillWebDataServiceObserverOnDBThread* observer) {
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
184 if (autofill_backend_)
185 autofill_backend_->RemoveObserver(observer);
186 }
187
188 void AutofillWebDataService::AddObserver(
189 AutofillWebDataServiceObserverOnUIThread* observer) { 169 AutofillWebDataServiceObserverOnUIThread* observer) {
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
191 ui_observer_list_.AddObserver(observer); 171 ui_observer_list_.AddObserver(observer);
192 } 172 }
193 173
194 void AutofillWebDataService::RemoveObserver( 174 void AutofillWebDataService::RemoveObserver(
195 AutofillWebDataServiceObserverOnUIThread* observer) { 175 AutofillWebDataServiceObserverOnUIThread* observer) {
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
197 ui_observer_list_.RemoveObserver(observer); 177 ui_observer_list_.RemoveObserver(observer);
198 } 178 }
199 179
200 AutofillWebDataService::~AutofillWebDataService() { 180 AutofillWebDataService::~AutofillWebDataService() {
201 DCHECK(!db_thread_user_data_.get()) << "Forgot to call ShutdownOnUIThread?"; 181 DCHECK(!db_thread_user_data_.get()) << "Forgot to call ShutdownOnUIThread?";
202 } 182 }
203 183
204 void AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread() { 184 void AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread() {
205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
206 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnUIThread, 186 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnUIThread,
207 ui_observer_list_, 187 ui_observer_list_,
208 AutofillMultipleChanged()); 188 AutofillMultipleChanged());
209 } 189 }
210 190
211 } // namespace autofill 191 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698