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

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: Pure merge 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/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "components/autofill/browser/autofill_country.h" 10 #include "components/autofill/browser/autofill_country.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 } 43 }
44 44
45 AutofillWebDataBackendImpl::~AutofillWebDataBackendImpl() { 45 AutofillWebDataBackendImpl::~AutofillWebDataBackendImpl() {
46 } 46 }
47 47
48 WebDatabase* AutofillWebDataBackendImpl::GetDatabase() { 48 WebDatabase* AutofillWebDataBackendImpl::GetDatabase() {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
50 return web_database_backend_->database(); 50 return web_database_backend_->database();
51 } 51 }
52 52
53 void AutofillWebDataBackendImpl::RemoveExpiredFormElementsWrapper() { 53 void AutofillWebDataBackendImpl::RemoveExpiredFormElements() {
54 web_database_backend_->ExecuteWriteTask( 54 web_database_backend_->ExecuteWriteTask(
55 Bind(&AutofillWebDataBackendImpl::RemoveExpiredFormElements, this)); 55 Bind(&AutofillWebDataBackendImpl::RemoveExpiredFormElementsImpl,
56 this));
56 } 57 }
57 58
58 void AutofillWebDataBackendImpl::NotifyOfMultipleAutofillChanges() { 59 void AutofillWebDataBackendImpl::NotifyOfMultipleAutofillChanges() {
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
60 BrowserThread::PostTask(BrowserThread::UI, 61 BrowserThread::PostTask(BrowserThread::UI,
61 FROM_HERE, 62 FROM_HERE,
62 on_changed_callback_); 63 on_changed_callback_);
63 } 64 }
64 65
65 WebDatabase::State AutofillWebDataBackendImpl::AddFormElements( 66 WebDatabase::State AutofillWebDataBackendImpl::AddFormElements(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // will be done on the DB thread, and not the UI thread. 119 // will be done on the DB thread, and not the UI thread.
119 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, 120 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
120 db_observer_list_, 121 db_observer_list_,
121 AutofillEntriesChanged(changes)); 122 AutofillEntriesChanged(changes));
122 } 123 }
123 return WebDatabase::COMMIT_NEEDED; 124 return WebDatabase::COMMIT_NEEDED;
124 } 125 }
125 return WebDatabase::COMMIT_NOT_NEEDED; 126 return WebDatabase::COMMIT_NOT_NEEDED;
126 } 127 }
127 128
128 WebDatabase::State AutofillWebDataBackendImpl::RemoveExpiredFormElements(
129 WebDatabase* db) {
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
131 AutofillChangeList changes;
132
133 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) {
134 if (!changes.empty()) {
135 // Post the notifications including the list of affected keys.
136 // This is sent here so that work resulting from this notification
137 // will be done on the DB thread, and not the UI thread.
138 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
139 db_observer_list_,
140 AutofillEntriesChanged(changes));
141 }
142 return WebDatabase::COMMIT_NEEDED;
143 }
144 return WebDatabase::COMMIT_NOT_NEEDED;
145 }
146
147 WebDatabase::State AutofillWebDataBackendImpl::RemoveFormValueForElementName( 129 WebDatabase::State AutofillWebDataBackendImpl::RemoveFormValueForElementName(
148 const base::string16& name, const base::string16& value, WebDatabase* db) { 130 const base::string16& name, const base::string16& value, WebDatabase* db) {
149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
150 132
151 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { 133 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) {
152 AutofillChangeList changes; 134 AutofillChangeList changes;
153 changes.push_back( 135 changes.push_back(
154 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value))); 136 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value)));
155 137
156 // Post the notifications including the list of affected keys. 138 // Post the notifications including the list of affected keys.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 db_observer_list_, 324 db_observer_list_,
343 AutofillProfileChanged(change)); 325 AutofillProfileChanged(change));
344 } 326 }
345 // Note: It is the caller's responsibility to post notifications for any 327 // Note: It is the caller's responsibility to post notifications for any
346 // changes, e.g. by calling the Refresh() method of PersonalDataManager. 328 // changes, e.g. by calling the Refresh() method of PersonalDataManager.
347 return WebDatabase::COMMIT_NEEDED; 329 return WebDatabase::COMMIT_NEEDED;
348 } 330 }
349 return WebDatabase::COMMIT_NOT_NEEDED; 331 return WebDatabase::COMMIT_NOT_NEEDED;
350 } 332 }
351 333
334 WebDatabase::State AutofillWebDataBackendImpl::RemoveExpiredFormElementsImpl(
335 WebDatabase* db) {
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
337 AutofillChangeList changes;
338
339 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) {
340 if (!changes.empty()) {
341 // Post the notifications including the list of affected keys.
342 // This is sent here so that work resulting from this notification
343 // will be done on the DB thread, and not the UI thread.
344 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
345 db_observer_list_,
346 AutofillEntriesChanged(changes));
347 }
348 return WebDatabase::COMMIT_NEEDED;
349 }
350 return WebDatabase::COMMIT_NOT_NEEDED;
351 }
352
352 void AutofillWebDataBackendImpl::DestroyAutofillProfileResult( 353 void AutofillWebDataBackendImpl::DestroyAutofillProfileResult(
353 const WDTypedResult* result) { 354 const WDTypedResult* result) {
354 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); 355 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT);
355 const WDResult<std::vector<AutofillProfile*> >* r = 356 const WDResult<std::vector<AutofillProfile*> >* r =
356 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); 357 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result);
357 std::vector<AutofillProfile*> profiles = r->GetValue(); 358 std::vector<AutofillProfile*> profiles = r->GetValue();
358 STLDeleteElements(&profiles); 359 STLDeleteElements(&profiles);
359 } 360 }
360 361
361 void AutofillWebDataBackendImpl::DestroyAutofillCreditCardResult( 362 void AutofillWebDataBackendImpl::DestroyAutofillCreditCardResult(
362 const WDTypedResult* result) { 363 const WDTypedResult* result) {
363 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); 364 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
364 const WDResult<std::vector<CreditCard*> >* r = 365 const WDResult<std::vector<CreditCard*> >* r =
365 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); 366 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
366 367
367 std::vector<CreditCard*> credit_cards = r->GetValue(); 368 std::vector<CreditCard*> credit_cards = r->GetValue();
368 STLDeleteElements(&credit_cards); 369 STLDeleteElements(&credit_cards);
369 } 370 }
370 371
371 } // namespace autofill 372 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698