OLD | NEW |
---|---|
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_) | |
Ilya Sherman
2013/05/08 00:39:06
Why is it possible for web_database_backend_ to be
Cait (Slow)
2013/05/08 19:16:01
Done.
| |
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()) | |
Ilya Sherman
2013/05/08 00:39:06
Why is it possible for web_database_backend_ or we
Cait (Slow)
2013/05/08 19:16:01
Done.
| |
54 return; | |
55 | |
56 if (RemoveExpiredFormElements(web_database_backend_->database()) == | |
57 WebDatabase::COMMIT_NEEDED) { | |
Ilya Sherman
2013/05/08 00:39:06
nit: Indent four more spaces.
Cait (Slow)
2013/05/08 19:16:01
Done.
| |
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()) | |
Ilya Sherman
2013/05/08 00:39:06
nit: Please add a space before the "||" operator.
Ilya Sherman
2013/05/08 00:39:06
Why is it possible for the callback to be null?
Cait (Slow)
2013/05/08 19:16:01
Done.
| |
67 return; | |
Ilya Sherman
2013/05/08 00:39:06
nit: Please leave a blank line after this one.
Cait (Slow)
2013/05/08 19:16:01
Done.
| |
68 BrowserThread::PostTask(BrowserThread::UI, | |
69 FROM_HERE, | |
70 *(on_changed_callback_.get()); | |
Ilya Sherman
2013/05/08 00:39:06
This line looks like it's missing a parenthesis...
Cait (Slow)
2013/05/08 19:16:01
Done.
| |
40 } | 71 } |
41 | 72 |
42 WebDatabase::State AutofillWebDataBackend::AddFormElements( | 73 WebDatabase::State AutofillWebDataBackend::AddFormElements( |
43 const std::vector<FormFieldData>& fields, WebDatabase* db) { | 74 const std::vector<FormFieldData>& fields, WebDatabase* db) { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
45 AutofillChangeList changes; | 76 AutofillChangeList changes; |
46 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( | 77 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( |
47 fields, &changes)) { | 78 fields, &changes)) { |
48 NOTREACHED(); | 79 NOTREACHED(); |
49 return WebDatabase::COMMIT_NOT_NEEDED; | 80 return WebDatabase::COMMIT_NOT_NEEDED; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 db_observer_list_, | 319 db_observer_list_, |
289 AutofillProfileChanged(change)); | 320 AutofillProfileChanged(change)); |
290 } | 321 } |
291 // Note: It is the caller's responsibility to post notifications for any | 322 // Note: It is the caller's responsibility to post notifications for any |
292 // changes, e.g. by calling the Refresh() method of PersonalDataManager. | 323 // changes, e.g. by calling the Refresh() method of PersonalDataManager. |
293 return WebDatabase::COMMIT_NEEDED; | 324 return WebDatabase::COMMIT_NEEDED; |
294 } | 325 } |
295 return WebDatabase::COMMIT_NOT_NEEDED; | 326 return WebDatabase::COMMIT_NOT_NEEDED; |
296 } | 327 } |
297 | 328 |
329 AutofillWebDataBackend::~AutofillWebDataBackend() { | |
330 } | |
Ilya Sherman
2013/05/08 00:39:06
Hrm, why did this get moved down?
Cait (Slow)
2013/05/08 19:16:01
Done.
| |
331 | |
298 void AutofillWebDataBackend::DestroyAutofillProfileResult( | 332 void AutofillWebDataBackend::DestroyAutofillProfileResult( |
299 const WDTypedResult* result) { | 333 const WDTypedResult* result) { |
300 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); | 334 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); |
301 const WDResult<std::vector<AutofillProfile*> >* r = | 335 const WDResult<std::vector<AutofillProfile*> >* r = |
302 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); | 336 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); |
303 std::vector<AutofillProfile*> profiles = r->GetValue(); | 337 std::vector<AutofillProfile*> profiles = r->GetValue(); |
304 STLDeleteElements(&profiles); | 338 STLDeleteElements(&profiles); |
305 } | 339 } |
306 | 340 |
307 void AutofillWebDataBackend::DestroyAutofillCreditCardResult( | 341 void AutofillWebDataBackend::DestroyAutofillCreditCardResult( |
308 const WDTypedResult* result) { | 342 const WDTypedResult* result) { |
309 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 343 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
310 const WDResult<std::vector<CreditCard*> >* r = | 344 const WDResult<std::vector<CreditCard*> >* r = |
311 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 345 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
312 | 346 |
313 std::vector<CreditCard*> credit_cards = r->GetValue(); | 347 std::vector<CreditCard*> credit_cards = r->GetValue(); |
314 STLDeleteElements(&credit_cards); | 348 STLDeleteElements(&credit_cards); |
315 } | 349 } |
316 | 350 |
317 } // namespace autofill | 351 } // namespace autofill |
OLD | NEW |