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

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

Issue 14081043: Hook up Autofill Backend interface to SyncableServices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments 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_backend_impl.h" 5 #include "components/autofill/browser/webdata/autofill_webdata_backend_impl.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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 AutofillWebDataBackendImpl::~AutofillWebDataBackendImpl() { 44 AutofillWebDataBackendImpl::~AutofillWebDataBackendImpl() {
45 } 45 }
46 46
47 WebDatabase* AutofillWebDataBackendImpl::GetDatabase() { 47 WebDatabase* AutofillWebDataBackendImpl::GetDatabase() {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
49 return web_database_backend_->database(); 49 return web_database_backend_->database();
50 } 50 }
51 51
52 void AutofillWebDataBackendImpl::RemoveExpiredFormElementsWrapper() { 52 void AutofillWebDataBackendImpl::RemoveExpiredFormElements() {
53 web_database_backend_->ExecuteWriteTask( 53 web_database_backend_->ExecuteWriteTask(
54 Bind(&AutofillWebDataBackendImpl::RemoveExpiredFormElements, this)); 54 Bind(&AutofillWebDataBackendImpl::RemoveExpiredFormElementsImpl,
55 this));
55 } 56 }
56 57
57 void AutofillWebDataBackendImpl::NotifyOfMultipleAutofillChanges() { 58 void AutofillWebDataBackendImpl::NotifyOfMultipleAutofillChanges() {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
59 BrowserThread::PostTask(BrowserThread::UI, 60 BrowserThread::PostTask(BrowserThread::UI,
60 FROM_HERE, 61 FROM_HERE,
61 on_changed_callback_); 62 on_changed_callback_);
62 } 63 }
63 64
64 WebDatabase::State AutofillWebDataBackendImpl::AddFormElements( 65 WebDatabase::State AutofillWebDataBackendImpl::AddFormElements(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // will be done on the DB thread, and not the UI thread. 117 // will be done on the DB thread, and not the UI thread.
117 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, 118 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
118 db_observer_list_, 119 db_observer_list_,
119 AutofillEntriesChanged(changes)); 120 AutofillEntriesChanged(changes));
120 } 121 }
121 return WebDatabase::COMMIT_NEEDED; 122 return WebDatabase::COMMIT_NEEDED;
122 } 123 }
123 return WebDatabase::COMMIT_NOT_NEEDED; 124 return WebDatabase::COMMIT_NOT_NEEDED;
124 } 125 }
125 126
126 WebDatabase::State AutofillWebDataBackendImpl::RemoveExpiredFormElements(
127 WebDatabase* db) {
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
129 AutofillChangeList changes;
130
131 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) {
132 if (!changes.empty()) {
133 // Post the notifications including the list of affected keys.
134 // This is sent here so that work resulting from this notification
135 // will be done on the DB thread, and not the UI thread.
136 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
137 db_observer_list_,
138 AutofillEntriesChanged(changes));
139 }
140 return WebDatabase::COMMIT_NEEDED;
141 }
142 return WebDatabase::COMMIT_NOT_NEEDED;
143 }
144
145 WebDatabase::State AutofillWebDataBackendImpl::RemoveFormValueForElementName( 127 WebDatabase::State AutofillWebDataBackendImpl::RemoveFormValueForElementName(
146 const base::string16& name, const base::string16& value, WebDatabase* db) { 128 const base::string16& name, const base::string16& value, WebDatabase* db) {
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
148 130
149 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { 131 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) {
150 AutofillChangeList changes; 132 AutofillChangeList changes;
151 changes.push_back( 133 changes.push_back(
152 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value))); 134 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value)));
153 135
154 // Post the notifications including the list of affected keys. 136 // Post the notifications including the list of affected keys.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 db_observer_list_, 300 db_observer_list_,
319 AutofillProfileChanged(change)); 301 AutofillProfileChanged(change));
320 } 302 }
321 // Note: It is the caller's responsibility to post notifications for any 303 // Note: It is the caller's responsibility to post notifications for any
322 // changes, e.g. by calling the Refresh() method of PersonalDataManager. 304 // changes, e.g. by calling the Refresh() method of PersonalDataManager.
323 return WebDatabase::COMMIT_NEEDED; 305 return WebDatabase::COMMIT_NEEDED;
324 } 306 }
325 return WebDatabase::COMMIT_NOT_NEEDED; 307 return WebDatabase::COMMIT_NOT_NEEDED;
326 } 308 }
327 309
310 WebDatabase::State AutofillWebDataBackendImpl::RemoveExpiredFormElementsImpl(
311 WebDatabase* db) {
312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
313 AutofillChangeList changes;
314
315 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) {
316 if (!changes.empty()) {
317 // Post the notifications including the list of affected keys.
318 // This is sent here so that work resulting from this notification
319 // will be done on the DB thread, and not the UI thread.
320 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
321 db_observer_list_,
322 AutofillEntriesChanged(changes));
323 }
324 return WebDatabase::COMMIT_NEEDED;
325 }
326 return WebDatabase::COMMIT_NOT_NEEDED;
327 }
328
328 void AutofillWebDataBackendImpl::DestroyAutofillProfileResult( 329 void AutofillWebDataBackendImpl::DestroyAutofillProfileResult(
329 const WDTypedResult* result) { 330 const WDTypedResult* result) {
330 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); 331 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT);
331 const WDResult<std::vector<AutofillProfile*> >* r = 332 const WDResult<std::vector<AutofillProfile*> >* r =
332 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); 333 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result);
333 std::vector<AutofillProfile*> profiles = r->GetValue(); 334 std::vector<AutofillProfile*> profiles = r->GetValue();
334 STLDeleteElements(&profiles); 335 STLDeleteElements(&profiles);
335 } 336 }
336 337
337 void AutofillWebDataBackendImpl::DestroyAutofillCreditCardResult( 338 void AutofillWebDataBackendImpl::DestroyAutofillCreditCardResult(
338 const WDTypedResult* result) { 339 const WDTypedResult* result) {
339 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); 340 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
340 const WDResult<std::vector<CreditCard*> >* r = 341 const WDResult<std::vector<CreditCard*> >* r =
341 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); 342 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
342 343
343 std::vector<CreditCard*> credit_cards = r->GetValue(); 344 std::vector<CreditCard*> credit_cards = r->GetValue();
344 STLDeleteElements(&credit_cards); 345 STLDeleteElements(&credit_cards);
345 } 346 }
346 347
347 } // namespace autofill 348 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698