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

Side by Side Diff: components/autofill/browser/webdata/autofill_webdata_backend.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_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_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_service_observer. h" 15 #include "components/autofill/browser/webdata/autofill_webdata_service_observer. h"
16 #include "components/autofill/common/form_field_data.h" 16 #include "components/autofill/common/form_field_data.h"
17 #include "components/webdata/common/web_data_service_backend.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 24
24 AutofillWebDataBackend::AutofillWebDataBackend() { 25 AutofillWebDataBackend::AutofillWebDataBackend(
26 scoped_refptr<WebDataServiceBackend> web_db_backend,
27 const base::Closure& on_changed_callback)
28 : web_database_backend_(web_db_backend),
29 on_changed_callback_(new base::Closure(on_changed_callback)) {
25 } 30 }
26 31
27 void AutofillWebDataBackend::AddObserver( 32 void AutofillWebDataBackend::AddObserver(
28 AutofillWebDataServiceObserverOnDBThread* observer) { 33 AutofillWebDataServiceObserverOnDBThread* observer) {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
30 db_observer_list_.AddObserver(observer); 35 db_observer_list_.AddObserver(observer);
31 } 36 }
32 37
33 void AutofillWebDataBackend::RemoveObserver( 38 void AutofillWebDataBackend::RemoveObserver(
34 AutofillWebDataServiceObserverOnDBThread* observer) { 39 AutofillWebDataServiceObserverOnDBThread* observer) {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
36 db_observer_list_.RemoveObserver(observer); 41 db_observer_list_.RemoveObserver(observer);
37 } 42 }
38 43
39 AutofillWebDataBackend::~AutofillWebDataBackend() { 44 WebDatabase* AutofillWebDataBackend::GetDatabaseOnDB() {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
46 if (!web_database_backend_)
47 return NULL;
48
49 return web_database_backend_->database();
50 }
51
52 void AutofillWebDataBackend::RemoveExpiredFormElementsWrapper() {
53 if (!web_database_backend_ || !web_database_backend_->database())
54 return;
55
56 if (RemoveExpiredFormElements(web_database_backend_->database()) ==
57 WebDatabase::COMMIT_NEEDED) {
58 web_database_backend_->database()->CommitTransaction();
59 web_database_backend_->database()->BeginTransaction();
60 }
61 }
62
63 void AutofillWebDataBackend::NotifyOfMultipleAutofillChanges() {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
65
66 if (!on_changed_callback_ .get()|| on_changed_callback_->is_null())
Jói 2013/05/07 19:39:41 no space before .get()
Cait (Slow) 2013/05/07 20:14:56 Done.
67 return;
68 BrowserThread::PostTask(
69 BrowserThread::UI,
Jói 2013/05/07 19:39:41 these can align to the parenthesis (with the first
Cait (Slow) 2013/05/07 20:14:56 Done.
70 FROM_HERE,
71 *(on_changed_callback_.get());
40 } 72 }
41 73
42 WebDatabase::State AutofillWebDataBackend::AddFormElements( 74 WebDatabase::State AutofillWebDataBackend::AddFormElements(
43 const std::vector<FormFieldData>& fields, WebDatabase* db) { 75 const std::vector<FormFieldData>& fields, WebDatabase* db) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
45 AutofillChangeList changes; 77 AutofillChangeList changes;
46 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( 78 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues(
47 fields, &changes)) { 79 fields, &changes)) {
48 NOTREACHED(); 80 NOTREACHED();
49 return WebDatabase::COMMIT_NOT_NEEDED; 81 return WebDatabase::COMMIT_NOT_NEEDED;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 db_observer_list_, 320 db_observer_list_,
289 AutofillProfileChanged(change)); 321 AutofillProfileChanged(change));
290 } 322 }
291 // Note: It is the caller's responsibility to post notifications for any 323 // Note: It is the caller's responsibility to post notifications for any
292 // changes, e.g. by calling the Refresh() method of PersonalDataManager. 324 // changes, e.g. by calling the Refresh() method of PersonalDataManager.
293 return WebDatabase::COMMIT_NEEDED; 325 return WebDatabase::COMMIT_NEEDED;
294 } 326 }
295 return WebDatabase::COMMIT_NOT_NEEDED; 327 return WebDatabase::COMMIT_NOT_NEEDED;
296 } 328 }
297 329
330 AutofillWebDataBackend::~AutofillWebDataBackend() {
331 }
332
298 void AutofillWebDataBackend::DestroyAutofillProfileResult( 333 void AutofillWebDataBackend::DestroyAutofillProfileResult(
299 const WDTypedResult* result) { 334 const WDTypedResult* result) {
300 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); 335 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT);
301 const WDResult<std::vector<AutofillProfile*> >* r = 336 const WDResult<std::vector<AutofillProfile*> >* r =
302 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); 337 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result);
303 std::vector<AutofillProfile*> profiles = r->GetValue(); 338 std::vector<AutofillProfile*> profiles = r->GetValue();
304 STLDeleteElements(&profiles); 339 STLDeleteElements(&profiles);
305 } 340 }
306 341
307 void AutofillWebDataBackend::DestroyAutofillCreditCardResult( 342 void AutofillWebDataBackend::DestroyAutofillCreditCardResult(
308 const WDTypedResult* result) { 343 const WDTypedResult* result) {
309 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); 344 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
310 const WDResult<std::vector<CreditCard*> >* r = 345 const WDResult<std::vector<CreditCard*> >* r =
311 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); 346 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
312 347
313 std::vector<CreditCard*> credit_cards = r->GetValue(); 348 std::vector<CreditCard*> credit_cards = r->GetValue();
314 STLDeleteElements(&credit_cards); 349 STLDeleteElements(&credit_cards);
315 } 350 }
316 351
317 } // namespace autofill 352 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698