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

Side by Side Diff: components/autofill/browser/webdata/autofill_webdata_backend.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_backend.h" 5 #include "components/autofill/browser/webdata/autofill_webdata_backend.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_backend_delegate.h"
12 #include "components/autofill/browser/webdata/autofill_change.h" 13 #include "components/autofill/browser/webdata/autofill_change.h"
13 #include "components/autofill/browser/webdata/autofill_entry.h" 14 #include "components/autofill/browser/webdata/autofill_entry.h"
14 #include "components/autofill/browser/webdata/autofill_table.h" 15 #include "components/autofill/browser/webdata/autofill_table.h"
15 #include "components/autofill/browser/webdata/autofill_webdata_service_observer. h" 16 #include "components/autofill/browser/webdata/autofill_webdata_service_observer. h"
16 #include "components/autofill/common/form_field_data.h" 17 #include "components/autofill/common/form_field_data.h"
17 18
18 using base::Bind; 19 using base::Bind;
19 using base::Time; 20 using base::Time;
20 using content::BrowserThread; 21 using content::BrowserThread;
21 22
22 namespace autofill { 23 namespace autofill {
23 AutofillWebDataBackend::AutofillWebDataBackend() { 24
25 AutofillWebDataBackend::AutofillWebDataBackend()
26 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
24 } 27 }
25 28
26 void AutofillWebDataBackend::AddObserver( 29 void AutofillWebDataBackend::AddObserver(
27 AutofillWebDataServiceObserverOnDBThread* observer) { 30 AutofillWebDataServiceObserverOnDBThread* observer) {
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
29 db_observer_list_.AddObserver(observer); 32 db_observer_list_.AddObserver(observer);
30 } 33 }
31 34
32 void AutofillWebDataBackend::RemoveObserver( 35 void AutofillWebDataBackend::RemoveObserver(
33 AutofillWebDataServiceObserverOnDBThread* observer) { 36 AutofillWebDataServiceObserverOnDBThread* observer) {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
35 db_observer_list_.RemoveObserver(observer); 38 db_observer_list_.RemoveObserver(observer);
36 } 39 }
37 40
41 void AutofillWebDataBackend::GetDelegate(
42 const AutofillWebDataService::DelegateOnDBCallback& callback,
43 base::WeakPtr<WebDatabase> db) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
45 if (!delegate_.get())
46 delegate_.reset(new AutofillBackendDelegate(
47 db, weak_ptr_factory_.GetWeakPtr()));
48 callback.Run(delegate_.get());
49 }
50
38 AutofillWebDataBackend::~AutofillWebDataBackend() { 51 AutofillWebDataBackend::~AutofillWebDataBackend() {
52 delegate_.reset();
53 weak_ptr_factory_.InvalidateWeakPtrs();
erikwright (departed) 2013/04/25 19:06:10 Not necessary - this is done by ~WeakPtrFactory.
39 } 54 }
40 55
41 WebDatabase::State AutofillWebDataBackend::AddFormElementsImpl( 56 WebDatabase::State AutofillWebDataBackend::AddFormElementsImpl(
42 const std::vector<FormFieldData>& fields, WebDatabase* db) { 57 const std::vector<FormFieldData>& fields, WebDatabase* db) {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
44 AutofillChangeList changes; 59 AutofillChangeList changes;
45 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( 60 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues(
46 fields, &changes)) { 61 fields, &changes)) {
47 NOTREACHED(); 62 NOTREACHED();
48 return WebDatabase::COMMIT_NOT_NEEDED; 63 return WebDatabase::COMMIT_NOT_NEEDED;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 void AutofillWebDataBackend::DestroyAutofillCreditCardResult( 321 void AutofillWebDataBackend::DestroyAutofillCreditCardResult(
307 const WDTypedResult* result) { 322 const WDTypedResult* result) {
308 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); 323 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
309 const WDResult<std::vector<CreditCard*> >* r = 324 const WDResult<std::vector<CreditCard*> >* r =
310 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); 325 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
311 326
312 std::vector<CreditCard*> credit_cards = r->GetValue(); 327 std::vector<CreditCard*> credit_cards = r->GetValue();
313 STLDeleteElements(&credit_cards); 328 STLDeleteElements(&credit_cards);
314 } 329 }
315 330
316 } 331 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698