| 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 "chrome/browser/webdata/web_data_service.h" | 5 #include "chrome/browser/webdata/web_data_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 372 } |
| 373 | 373 |
| 374 //////////////////////////////////////////////////////////////////////////////// | 374 //////////////////////////////////////////////////////////////////////////////// |
| 375 // | 375 // |
| 376 // Keywords implementation. | 376 // Keywords implementation. |
| 377 // | 377 // |
| 378 //////////////////////////////////////////////////////////////////////////////// | 378 //////////////////////////////////////////////////////////////////////////////// |
| 379 | 379 |
| 380 WebDatabase::State WebDataService::AddKeywordImpl( | 380 WebDatabase::State WebDataService::AddKeywordImpl( |
| 381 const TemplateURLData& data, WebDatabase* db) { | 381 const TemplateURLData& data, WebDatabase* db) { |
| 382 db->GetKeywordTable()->AddKeyword(data); | 382 KeywordTable::FromWebDatabase(db)->AddKeyword(data); |
| 383 return WebDatabase::COMMIT_NEEDED; | 383 return WebDatabase::COMMIT_NEEDED; |
| 384 } | 384 } |
| 385 | 385 |
| 386 WebDatabase::State WebDataService::RemoveKeywordImpl( | 386 WebDatabase::State WebDataService::RemoveKeywordImpl( |
| 387 TemplateURLID id, WebDatabase* db) { | 387 TemplateURLID id, WebDatabase* db) { |
| 388 DCHECK(id); | 388 DCHECK(id); |
| 389 db->GetKeywordTable()->RemoveKeyword(id); | 389 KeywordTable::FromWebDatabase(db)->RemoveKeyword(id); |
| 390 return WebDatabase::COMMIT_NEEDED; | 390 return WebDatabase::COMMIT_NEEDED; |
| 391 } | 391 } |
| 392 | 392 |
| 393 WebDatabase::State WebDataService::UpdateKeywordImpl( | 393 WebDatabase::State WebDataService::UpdateKeywordImpl( |
| 394 const TemplateURLData& data, WebDatabase* db) { | 394 const TemplateURLData& data, WebDatabase* db) { |
| 395 if (!db->GetKeywordTable()->UpdateKeyword(data)) { | 395 if (!KeywordTable::FromWebDatabase(db)->UpdateKeyword(data)) { |
| 396 NOTREACHED(); | 396 NOTREACHED(); |
| 397 return WebDatabase::COMMIT_NOT_NEEDED; | 397 return WebDatabase::COMMIT_NOT_NEEDED; |
| 398 } | 398 } |
| 399 return WebDatabase::COMMIT_NEEDED; | 399 return WebDatabase::COMMIT_NEEDED; |
| 400 } | 400 } |
| 401 | 401 |
| 402 scoped_ptr<WDTypedResult> WebDataService::GetKeywordsImpl(WebDatabase* db) { | 402 scoped_ptr<WDTypedResult> WebDataService::GetKeywordsImpl(WebDatabase* db) { |
| 403 WDKeywordsResult result; | 403 WDKeywordsResult result; |
| 404 db->GetKeywordTable()->GetKeywords(&result.keywords); | 404 KeywordTable::FromWebDatabase(db)->GetKeywords(&result.keywords); |
| 405 result.default_search_provider_id = | 405 result.default_search_provider_id = |
| 406 db->GetKeywordTable()->GetDefaultSearchProviderID(); | 406 KeywordTable::FromWebDatabase(db)->GetDefaultSearchProviderID(); |
| 407 result.builtin_keyword_version = | 407 result.builtin_keyword_version = |
| 408 db->GetKeywordTable()->GetBuiltinKeywordVersion(); | 408 KeywordTable::FromWebDatabase(db)->GetBuiltinKeywordVersion(); |
| 409 return scoped_ptr<WDTypedResult>( | 409 return scoped_ptr<WDTypedResult>( |
| 410 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); | 410 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); |
| 411 } | 411 } |
| 412 | 412 |
| 413 WebDatabase::State WebDataService::SetDefaultSearchProviderImpl( | 413 WebDatabase::State WebDataService::SetDefaultSearchProviderImpl( |
| 414 TemplateURLID id, WebDatabase* db) { | 414 TemplateURLID id, WebDatabase* db) { |
| 415 if (!db->GetKeywordTable()->SetDefaultSearchProviderID(id)) { | 415 if (!KeywordTable::FromWebDatabase(db)->SetDefaultSearchProviderID(id)) { |
| 416 NOTREACHED(); | 416 NOTREACHED(); |
| 417 return WebDatabase::COMMIT_NOT_NEEDED; | 417 return WebDatabase::COMMIT_NOT_NEEDED; |
| 418 } | 418 } |
| 419 return WebDatabase::COMMIT_NEEDED; | 419 return WebDatabase::COMMIT_NEEDED; |
| 420 } | 420 } |
| 421 | 421 |
| 422 WebDatabase::State WebDataService::SetBuiltinKeywordVersionImpl( | 422 WebDatabase::State WebDataService::SetBuiltinKeywordVersionImpl( |
| 423 int version, WebDatabase* db) { | 423 int version, WebDatabase* db) { |
| 424 if (!db->GetKeywordTable()->SetBuiltinKeywordVersion(version)) { | 424 if (!KeywordTable::FromWebDatabase(db)->SetBuiltinKeywordVersion(version)) { |
| 425 NOTREACHED(); | 425 NOTREACHED(); |
| 426 return WebDatabase::COMMIT_NOT_NEEDED; | 426 return WebDatabase::COMMIT_NOT_NEEDED; |
| 427 } | 427 } |
| 428 return WebDatabase::COMMIT_NEEDED; | 428 return WebDatabase::COMMIT_NEEDED; |
| 429 } | 429 } |
| 430 | 430 |
| 431 //////////////////////////////////////////////////////////////////////////////// | 431 //////////////////////////////////////////////////////////////////////////////// |
| 432 // | 432 // |
| 433 // Web Apps implementation. | 433 // Web Apps implementation. |
| 434 // | 434 // |
| 435 //////////////////////////////////////////////////////////////////////////////// | 435 //////////////////////////////////////////////////////////////////////////////// |
| 436 | 436 |
| 437 WebDatabase::State WebDataService::SetWebAppImageImpl( | 437 WebDatabase::State WebDataService::SetWebAppImageImpl( |
| 438 const GURL& app_url, const SkBitmap& image, WebDatabase* db) { | 438 const GURL& app_url, const SkBitmap& image, WebDatabase* db) { |
| 439 db->GetWebAppsTable()->SetWebAppImage(app_url, image); | 439 WebAppsTable::FromWebDatabase(db)->SetWebAppImage(app_url, image); |
| 440 return WebDatabase::COMMIT_NEEDED; | 440 return WebDatabase::COMMIT_NEEDED; |
| 441 } | 441 } |
| 442 | 442 |
| 443 WebDatabase::State WebDataService::SetWebAppHasAllImagesImpl( | 443 WebDatabase::State WebDataService::SetWebAppHasAllImagesImpl( |
| 444 const GURL& app_url, bool has_all_images, WebDatabase* db) { | 444 const GURL& app_url, bool has_all_images, WebDatabase* db) { |
| 445 db->GetWebAppsTable()-> | 445 WebAppsTable::FromWebDatabase(db)->SetWebAppHasAllImages(app_url, |
| 446 SetWebAppHasAllImages(app_url, has_all_images); | 446 has_all_images); |
| 447 return WebDatabase::COMMIT_NEEDED; | 447 return WebDatabase::COMMIT_NEEDED; |
| 448 } | 448 } |
| 449 | 449 |
| 450 WebDatabase::State WebDataService::RemoveWebAppImpl( | 450 WebDatabase::State WebDataService::RemoveWebAppImpl( |
| 451 const GURL& app_url, WebDatabase* db) { | 451 const GURL& app_url, WebDatabase* db) { |
| 452 db->GetWebAppsTable()->RemoveWebApp(app_url); | 452 WebAppsTable::FromWebDatabase(db)->RemoveWebApp(app_url); |
| 453 return WebDatabase::COMMIT_NEEDED; | 453 return WebDatabase::COMMIT_NEEDED; |
| 454 } | 454 } |
| 455 | 455 |
| 456 scoped_ptr<WDTypedResult> WebDataService::GetWebAppImagesImpl( | 456 scoped_ptr<WDTypedResult> WebDataService::GetWebAppImagesImpl( |
| 457 const GURL& app_url, WebDatabase* db) { | 457 const GURL& app_url, WebDatabase* db) { |
| 458 WDAppImagesResult result; | 458 WDAppImagesResult result; |
| 459 result.has_all_images = db->GetWebAppsTable()->GetWebAppHasAllImages(app_url); | 459 result.has_all_images = |
| 460 db->GetWebAppsTable()->GetWebAppImages(app_url, &result.images); | 460 WebAppsTable::FromWebDatabase(db)->GetWebAppHasAllImages(app_url); |
| 461 WebAppsTable::FromWebDatabase(db)->GetWebAppImages(app_url, &result.images); |
| 461 return scoped_ptr<WDTypedResult>( | 462 return scoped_ptr<WDTypedResult>( |
| 462 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); | 463 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); |
| 463 } | 464 } |
| 464 | 465 |
| 465 //////////////////////////////////////////////////////////////////////////////// | 466 //////////////////////////////////////////////////////////////////////////////// |
| 466 // | 467 // |
| 467 // Token Service implementation. | 468 // Token Service implementation. |
| 468 // | 469 // |
| 469 //////////////////////////////////////////////////////////////////////////////// | 470 //////////////////////////////////////////////////////////////////////////////// |
| 470 | 471 |
| 471 WebDatabase::State WebDataService::RemoveAllTokensImpl(WebDatabase* db) { | 472 WebDatabase::State WebDataService::RemoveAllTokensImpl(WebDatabase* db) { |
| 472 if (db->GetTokenServiceTable()->RemoveAllTokens()) { | 473 if (TokenServiceTable::FromWebDatabase(db)->RemoveAllTokens()) { |
| 473 return WebDatabase::COMMIT_NEEDED; | 474 return WebDatabase::COMMIT_NEEDED; |
| 474 } | 475 } |
| 475 return WebDatabase::COMMIT_NOT_NEEDED; | 476 return WebDatabase::COMMIT_NOT_NEEDED; |
| 476 } | 477 } |
| 477 | 478 |
| 478 WebDatabase::State WebDataService::SetTokenForServiceImpl( | 479 WebDatabase::State WebDataService::SetTokenForServiceImpl( |
| 479 const std::string& service, const std::string& token, WebDatabase* db) { | 480 const std::string& service, const std::string& token, WebDatabase* db) { |
| 480 if (db->GetTokenServiceTable()->SetTokenForService(service, token)) { | 481 if (TokenServiceTable::FromWebDatabase(db)->SetTokenForService(service, |
| 482 token)) { |
| 481 return WebDatabase::COMMIT_NEEDED; | 483 return WebDatabase::COMMIT_NEEDED; |
| 482 } | 484 } |
| 483 return WebDatabase::COMMIT_NOT_NEEDED; | 485 return WebDatabase::COMMIT_NOT_NEEDED; |
| 484 } | 486 } |
| 485 | 487 |
| 486 scoped_ptr<WDTypedResult> WebDataService::GetAllTokensImpl(WebDatabase* db) { | 488 scoped_ptr<WDTypedResult> WebDataService::GetAllTokensImpl(WebDatabase* db) { |
| 487 std::map<std::string, std::string> map; | 489 std::map<std::string, std::string> map; |
| 488 db->GetTokenServiceTable()->GetAllTokens(&map); | 490 TokenServiceTable::FromWebDatabase(db)->GetAllTokens(&map); |
| 489 return scoped_ptr<WDTypedResult>( | 491 return scoped_ptr<WDTypedResult>( |
| 490 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); | 492 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); |
| 491 } | 493 } |
| 492 | 494 |
| 493 //////////////////////////////////////////////////////////////////////////////// | 495 //////////////////////////////////////////////////////////////////////////////// |
| 494 // | 496 // |
| 495 // Autofill implementation. | 497 // Autofill implementation. |
| 496 // | 498 // |
| 497 //////////////////////////////////////////////////////////////////////////////// | 499 //////////////////////////////////////////////////////////////////////////////// |
| 498 | 500 |
| 499 WebDatabase::State WebDataService::AddFormElementsImpl( | 501 WebDatabase::State WebDataService::AddFormElementsImpl( |
| 500 const std::vector<FormFieldData>& fields, WebDatabase* db) { | 502 const std::vector<FormFieldData>& fields, WebDatabase* db) { |
| 501 AutofillChangeList changes; | 503 AutofillChangeList changes; |
| 502 if (!db->GetAutofillTable()->AddFormFieldValues(fields, &changes)) { | 504 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( |
| 505 fields, &changes)) { |
| 503 NOTREACHED(); | 506 NOTREACHED(); |
| 504 return WebDatabase::COMMIT_NOT_NEEDED; | 507 return WebDatabase::COMMIT_NOT_NEEDED; |
| 505 } | 508 } |
| 506 | 509 |
| 507 // Post the notifications including the list of affected keys. | 510 // Post the notifications including the list of affected keys. |
| 508 // This is sent here so that work resulting from this notification will be | 511 // This is sent here so that work resulting from this notification will be |
| 509 // done on the DB thread, and not the UI thread. | 512 // done on the DB thread, and not the UI thread. |
| 510 content::NotificationService::current()->Notify( | 513 content::NotificationService::current()->Notify( |
| 511 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 514 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 512 content::Source<WebDataService>(this), | 515 content::Source<WebDataService>(this), |
| 513 content::Details<AutofillChangeList>(&changes)); | 516 content::Details<AutofillChangeList>(&changes)); |
| 514 | 517 |
| 515 return WebDatabase::COMMIT_NEEDED; | 518 return WebDatabase::COMMIT_NEEDED; |
| 516 } | 519 } |
| 517 | 520 |
| 518 scoped_ptr<WDTypedResult> WebDataService::GetFormValuesForElementNameImpl( | 521 scoped_ptr<WDTypedResult> WebDataService::GetFormValuesForElementNameImpl( |
| 519 const string16& name, const string16& prefix, int limit, WebDatabase* db) { | 522 const string16& name, const string16& prefix, int limit, WebDatabase* db) { |
| 520 std::vector<string16> values; | 523 std::vector<string16> values; |
| 521 db->GetAutofillTable()->GetFormValuesForElementName( | 524 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( |
| 522 name, prefix, &values, limit); | 525 name, prefix, &values, limit); |
| 523 return scoped_ptr<WDTypedResult>( | 526 return scoped_ptr<WDTypedResult>( |
| 524 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); | 527 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); |
| 525 } | 528 } |
| 526 | 529 |
| 527 WebDatabase::State WebDataService::RemoveFormElementsAddedBetweenImpl( | 530 WebDatabase::State WebDataService::RemoveFormElementsAddedBetweenImpl( |
| 528 const base::Time& delete_begin, const base::Time& delete_end, | 531 const base::Time& delete_begin, const base::Time& delete_end, |
| 529 WebDatabase* db) { | 532 WebDatabase* db) { |
| 530 AutofillChangeList changes; | 533 AutofillChangeList changes; |
| 531 | 534 |
| 532 if (db->GetAutofillTable()->RemoveFormElementsAddedBetween( | 535 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( |
| 533 delete_begin, delete_end, &changes)) { | 536 delete_begin, delete_end, &changes)) { |
| 534 if (!changes.empty()) { | 537 if (!changes.empty()) { |
| 535 // Post the notifications including the list of affected keys. | 538 // Post the notifications including the list of affected keys. |
| 536 // This is sent here so that work resulting from this notification | 539 // This is sent here so that work resulting from this notification |
| 537 // will be done on the DB thread, and not the UI thread. | 540 // will be done on the DB thread, and not the UI thread. |
| 538 content::NotificationService::current()->Notify( | 541 content::NotificationService::current()->Notify( |
| 539 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 542 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 540 content::Source<WebDataService>(this), | 543 content::Source<WebDataService>(this), |
| 541 content::Details<AutofillChangeList>(&changes)); | 544 content::Details<AutofillChangeList>(&changes)); |
| 542 } | 545 } |
| 543 return WebDatabase::COMMIT_NEEDED; | 546 return WebDatabase::COMMIT_NEEDED; |
| 544 } | 547 } |
| 545 return WebDatabase::COMMIT_NOT_NEEDED; | 548 return WebDatabase::COMMIT_NOT_NEEDED; |
| 546 } | 549 } |
| 547 | 550 |
| 548 WebDatabase::State WebDataService::RemoveExpiredFormElementsImpl( | 551 WebDatabase::State WebDataService::RemoveExpiredFormElementsImpl( |
| 549 WebDatabase* db) { | 552 WebDatabase* db) { |
| 550 AutofillChangeList changes; | 553 AutofillChangeList changes; |
| 551 | 554 |
| 552 if (db->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { | 555 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { |
| 553 if (!changes.empty()) { | 556 if (!changes.empty()) { |
| 554 // Post the notifications including the list of affected keys. | 557 // Post the notifications including the list of affected keys. |
| 555 // This is sent here so that work resulting from this notification | 558 // This is sent here so that work resulting from this notification |
| 556 // will be done on the DB thread, and not the UI thread. | 559 // will be done on the DB thread, and not the UI thread. |
| 557 content::NotificationService::current()->Notify( | 560 content::NotificationService::current()->Notify( |
| 558 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 561 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 559 content::Source<WebDataService>(this), | 562 content::Source<WebDataService>(this), |
| 560 content::Details<AutofillChangeList>(&changes)); | 563 content::Details<AutofillChangeList>(&changes)); |
| 561 } | 564 } |
| 562 return WebDatabase::COMMIT_NEEDED; | 565 return WebDatabase::COMMIT_NEEDED; |
| 563 } | 566 } |
| 564 return WebDatabase::COMMIT_NOT_NEEDED; | 567 return WebDatabase::COMMIT_NOT_NEEDED; |
| 565 } | 568 } |
| 566 | 569 |
| 567 WebDatabase::State WebDataService::RemoveFormValueForElementNameImpl( | 570 WebDatabase::State WebDataService::RemoveFormValueForElementNameImpl( |
| 568 const string16& name, const string16& value, WebDatabase* db) { | 571 const string16& name, const string16& value, WebDatabase* db) { |
| 569 | 572 |
| 570 if (db->GetAutofillTable()->RemoveFormElement(name, value)) { | 573 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { |
| 571 AutofillChangeList changes; | 574 AutofillChangeList changes; |
| 572 changes.push_back(AutofillChange(AutofillChange::REMOVE, | 575 changes.push_back(AutofillChange(AutofillChange::REMOVE, |
| 573 AutofillKey(name, value))); | 576 AutofillKey(name, value))); |
| 574 | 577 |
| 575 // Post the notifications including the list of affected keys. | 578 // Post the notifications including the list of affected keys. |
| 576 content::NotificationService::current()->Notify( | 579 content::NotificationService::current()->Notify( |
| 577 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 580 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 578 content::Source<WebDataService>(this), | 581 content::Source<WebDataService>(this), |
| 579 content::Details<AutofillChangeList>(&changes)); | 582 content::Details<AutofillChangeList>(&changes)); |
| 580 | 583 |
| 581 return WebDatabase::COMMIT_NEEDED; | 584 return WebDatabase::COMMIT_NEEDED; |
| 582 } | 585 } |
| 583 return WebDatabase::COMMIT_NOT_NEEDED; | 586 return WebDatabase::COMMIT_NOT_NEEDED; |
| 584 } | 587 } |
| 585 | 588 |
| 586 WebDatabase::State WebDataService::AddAutofillProfileImpl( | 589 WebDatabase::State WebDataService::AddAutofillProfileImpl( |
| 587 const AutofillProfile& profile, WebDatabase* db) { | 590 const AutofillProfile& profile, WebDatabase* db) { |
| 588 if (!db->GetAutofillTable()->AddAutofillProfile(profile)) { | 591 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { |
| 589 NOTREACHED(); | 592 NOTREACHED(); |
| 590 return WebDatabase::COMMIT_NOT_NEEDED; | 593 return WebDatabase::COMMIT_NOT_NEEDED; |
| 591 } | 594 } |
| 592 | 595 |
| 593 // Send GUID-based notification. | 596 // Send GUID-based notification. |
| 594 AutofillProfileChange change(AutofillProfileChange::ADD, | 597 AutofillProfileChange change(AutofillProfileChange::ADD, |
| 595 profile.guid(), &profile); | 598 profile.guid(), &profile); |
| 596 content::NotificationService::current()->Notify( | 599 content::NotificationService::current()->Notify( |
| 597 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 600 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 598 content::Source<WebDataService>(this), | 601 content::Source<WebDataService>(this), |
| 599 content::Details<AutofillProfileChange>(&change)); | 602 content::Details<AutofillProfileChange>(&change)); |
| 600 | 603 |
| 601 return WebDatabase::COMMIT_NEEDED; | 604 return WebDatabase::COMMIT_NEEDED; |
| 602 } | 605 } |
| 603 | 606 |
| 604 WebDatabase::State WebDataService::UpdateAutofillProfileImpl( | 607 WebDatabase::State WebDataService::UpdateAutofillProfileImpl( |
| 605 const AutofillProfile& profile, WebDatabase* db) { | 608 const AutofillProfile& profile, WebDatabase* db) { |
| 606 // Only perform the update if the profile exists. It is currently | 609 // Only perform the update if the profile exists. It is currently |
| 607 // valid to try to update a missing profile. We simply drop the write and | 610 // valid to try to update a missing profile. We simply drop the write and |
| 608 // the caller will detect this on the next refresh. | 611 // the caller will detect this on the next refresh. |
| 609 AutofillProfile* original_profile = NULL; | 612 AutofillProfile* original_profile = NULL; |
| 610 if (!db->GetAutofillTable()->GetAutofillProfile(profile.guid(), | 613 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), |
| 611 &original_profile)) { | 614 &original_profile)) { |
| 612 return WebDatabase::COMMIT_NOT_NEEDED; | 615 return WebDatabase::COMMIT_NOT_NEEDED; |
| 613 } | 616 } |
| 614 scoped_ptr<AutofillProfile> scoped_profile(original_profile); | 617 scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
| 615 | 618 |
| 616 if (!db->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) { | 619 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( |
| 620 profile)) { |
| 617 NOTREACHED(); | 621 NOTREACHED(); |
| 618 return WebDatabase::COMMIT_NEEDED; | 622 return WebDatabase::COMMIT_NEEDED; |
| 619 } | 623 } |
| 620 | 624 |
| 621 // Send GUID-based notification. | 625 // Send GUID-based notification. |
| 622 AutofillProfileChange change(AutofillProfileChange::UPDATE, | 626 AutofillProfileChange change(AutofillProfileChange::UPDATE, |
| 623 profile.guid(), &profile); | 627 profile.guid(), &profile); |
| 624 content::NotificationService::current()->Notify( | 628 content::NotificationService::current()->Notify( |
| 625 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 629 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 626 content::Source<WebDataService>(this), | 630 content::Source<WebDataService>(this), |
| 627 content::Details<AutofillProfileChange>(&change)); | 631 content::Details<AutofillProfileChange>(&change)); |
| 628 | 632 |
| 629 return WebDatabase::COMMIT_NEEDED; | 633 return WebDatabase::COMMIT_NEEDED; |
| 630 } | 634 } |
| 631 | 635 |
| 632 WebDatabase::State WebDataService::RemoveAutofillProfileImpl( | 636 WebDatabase::State WebDataService::RemoveAutofillProfileImpl( |
| 633 const std::string& guid, WebDatabase* db) { | 637 const std::string& guid, WebDatabase* db) { |
| 634 AutofillProfile* profile = NULL; | 638 AutofillProfile* profile = NULL; |
| 635 if (!db->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { | 639 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { |
| 636 NOTREACHED(); | 640 NOTREACHED(); |
| 637 return WebDatabase::COMMIT_NOT_NEEDED; | 641 return WebDatabase::COMMIT_NOT_NEEDED; |
| 638 } | 642 } |
| 639 scoped_ptr<AutofillProfile> scoped_profile(profile); | 643 scoped_ptr<AutofillProfile> scoped_profile(profile); |
| 640 | 644 |
| 641 if (!db->GetAutofillTable()->RemoveAutofillProfile(guid)) { | 645 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { |
| 642 NOTREACHED(); | 646 NOTREACHED(); |
| 643 return WebDatabase::COMMIT_NOT_NEEDED; | 647 return WebDatabase::COMMIT_NOT_NEEDED; |
| 644 } | 648 } |
| 645 | 649 |
| 646 // Send GUID-based notification. | 650 // Send GUID-based notification. |
| 647 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); | 651 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
| 648 content::NotificationService::current()->Notify( | 652 content::NotificationService::current()->Notify( |
| 649 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 653 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 650 content::Source<WebDataService>(this), | 654 content::Source<WebDataService>(this), |
| 651 content::Details<AutofillProfileChange>(&change)); | 655 content::Details<AutofillProfileChange>(&change)); |
| 652 | 656 |
| 653 return WebDatabase::COMMIT_NEEDED; | 657 return WebDatabase::COMMIT_NEEDED; |
| 654 } | 658 } |
| 655 | 659 |
| 656 scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl( | 660 scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl( |
| 657 WebDatabase* db) { | 661 WebDatabase* db) { |
| 658 std::vector<AutofillProfile*> profiles; | 662 std::vector<AutofillProfile*> profiles; |
| 659 db->GetAutofillTable()->GetAutofillProfiles(&profiles); | 663 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); |
| 660 return scoped_ptr<WDTypedResult>( | 664 return scoped_ptr<WDTypedResult>( |
| 661 new WDDestroyableResult<std::vector<AutofillProfile*> >( | 665 new WDDestroyableResult<std::vector<AutofillProfile*> >( |
| 662 AUTOFILL_PROFILES_RESULT, | 666 AUTOFILL_PROFILES_RESULT, |
| 663 profiles, | 667 profiles, |
| 664 base::Bind(&WebDataService::DestroyAutofillProfileResult, | 668 base::Bind(&WebDataService::DestroyAutofillProfileResult, |
| 665 base::Unretained(this)))); | 669 base::Unretained(this)))); |
| 666 } | 670 } |
| 667 | 671 |
| 668 WebDatabase::State WebDataService::AddCreditCardImpl( | 672 WebDatabase::State WebDataService::AddCreditCardImpl( |
| 669 const CreditCard& credit_card, WebDatabase* db) { | 673 const CreditCard& credit_card, WebDatabase* db) { |
| 670 if (!db->GetAutofillTable()->AddCreditCard(credit_card)) { | 674 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { |
| 671 NOTREACHED(); | 675 NOTREACHED(); |
| 672 return WebDatabase::COMMIT_NOT_NEEDED; | 676 return WebDatabase::COMMIT_NOT_NEEDED; |
| 673 } | 677 } |
| 674 | 678 |
| 675 // Send GUID-based notification. | 679 // Send GUID-based notification. |
| 676 AutofillCreditCardChange change(AutofillCreditCardChange::ADD, | 680 AutofillCreditCardChange change(AutofillCreditCardChange::ADD, |
| 677 credit_card.guid(), &credit_card); | 681 credit_card.guid(), &credit_card); |
| 678 content::NotificationService::current()->Notify( | 682 content::NotificationService::current()->Notify( |
| 679 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | 683 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 680 content::Source<WebDataService>(this), | 684 content::Source<WebDataService>(this), |
| 681 content::Details<AutofillCreditCardChange>(&change)); | 685 content::Details<AutofillCreditCardChange>(&change)); |
| 682 | 686 |
| 683 return WebDatabase::COMMIT_NEEDED; | 687 return WebDatabase::COMMIT_NEEDED; |
| 684 } | 688 } |
| 685 | 689 |
| 686 WebDatabase::State WebDataService::UpdateCreditCardImpl( | 690 WebDatabase::State WebDataService::UpdateCreditCardImpl( |
| 687 const CreditCard& credit_card, WebDatabase* db) { | 691 const CreditCard& credit_card, WebDatabase* db) { |
| 688 // It is currently valid to try to update a missing profile. We simply drop | 692 // It is currently valid to try to update a missing profile. We simply drop |
| 689 // the write and the caller will detect this on the next refresh. | 693 // the write and the caller will detect this on the next refresh. |
| 690 CreditCard* original_credit_card = NULL; | 694 CreditCard* original_credit_card = NULL; |
| 691 if (!db->GetAutofillTable()->GetCreditCard(credit_card.guid(), | 695 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), |
| 692 &original_credit_card)) { | 696 &original_credit_card)) { |
| 693 return WebDatabase::COMMIT_NOT_NEEDED; | 697 return WebDatabase::COMMIT_NOT_NEEDED; |
| 694 } | 698 } |
| 695 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); | 699 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); |
| 696 | 700 |
| 697 if (!db->GetAutofillTable()->UpdateCreditCard(credit_card)) { | 701 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { |
| 698 NOTREACHED(); | 702 NOTREACHED(); |
| 699 return WebDatabase::COMMIT_NOT_NEEDED; | 703 return WebDatabase::COMMIT_NOT_NEEDED; |
| 700 } | 704 } |
| 701 | 705 |
| 702 // Send GUID-based notification. | 706 // Send GUID-based notification. |
| 703 AutofillCreditCardChange change(AutofillCreditCardChange::UPDATE, | 707 AutofillCreditCardChange change(AutofillCreditCardChange::UPDATE, |
| 704 credit_card.guid(), &credit_card); | 708 credit_card.guid(), &credit_card); |
| 705 content::NotificationService::current()->Notify( | 709 content::NotificationService::current()->Notify( |
| 706 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | 710 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 707 content::Source<WebDataService>(this), | 711 content::Source<WebDataService>(this), |
| 708 content::Details<AutofillCreditCardChange>(&change)); | 712 content::Details<AutofillCreditCardChange>(&change)); |
| 709 | 713 |
| 710 return WebDatabase::COMMIT_NEEDED; | 714 return WebDatabase::COMMIT_NEEDED; |
| 711 } | 715 } |
| 712 | 716 |
| 713 WebDatabase::State WebDataService::RemoveCreditCardImpl( | 717 WebDatabase::State WebDataService::RemoveCreditCardImpl( |
| 714 const std::string& guid, WebDatabase* db) { | 718 const std::string& guid, WebDatabase* db) { |
| 715 if (!db->GetAutofillTable()->RemoveCreditCard(guid)) { | 719 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { |
| 716 NOTREACHED(); | 720 NOTREACHED(); |
| 717 return WebDatabase::COMMIT_NOT_NEEDED; | 721 return WebDatabase::COMMIT_NOT_NEEDED; |
| 718 } | 722 } |
| 719 | 723 |
| 720 // Send GUID-based notification. | 724 // Send GUID-based notification. |
| 721 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, guid, | 725 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, guid, |
| 722 NULL); | 726 NULL); |
| 723 content::NotificationService::current()->Notify( | 727 content::NotificationService::current()->Notify( |
| 724 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | 728 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 725 content::Source<WebDataService>(this), | 729 content::Source<WebDataService>(this), |
| 726 content::Details<AutofillCreditCardChange>(&change)); | 730 content::Details<AutofillCreditCardChange>(&change)); |
| 727 | 731 |
| 728 return WebDatabase::COMMIT_NEEDED; | 732 return WebDatabase::COMMIT_NEEDED; |
| 729 } | 733 } |
| 730 | 734 |
| 731 scoped_ptr<WDTypedResult> WebDataService::GetCreditCardsImpl(WebDatabase* db) { | 735 scoped_ptr<WDTypedResult> WebDataService::GetCreditCardsImpl(WebDatabase* db) { |
| 732 std::vector<CreditCard*> credit_cards; | 736 std::vector<CreditCard*> credit_cards; |
| 733 db->GetAutofillTable()->GetCreditCards(&credit_cards); | 737 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); |
| 734 return scoped_ptr<WDTypedResult>( | 738 return scoped_ptr<WDTypedResult>( |
| 735 new WDDestroyableResult<std::vector<CreditCard*> >( | 739 new WDDestroyableResult<std::vector<CreditCard*> >( |
| 736 AUTOFILL_CREDITCARDS_RESULT, | 740 AUTOFILL_CREDITCARDS_RESULT, |
| 737 credit_cards, | 741 credit_cards, |
| 738 base::Bind(&WebDataService::DestroyAutofillCreditCardResult, | 742 base::Bind(&WebDataService::DestroyAutofillCreditCardResult, |
| 739 base::Unretained(this)))); | 743 base::Unretained(this)))); |
| 740 } | 744 } |
| 741 | 745 |
| 742 WebDatabase::State | 746 WebDatabase::State |
| 743 WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( | 747 WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( |
| 744 const base::Time& delete_begin, const base::Time& delete_end, | 748 const base::Time& delete_begin, const base::Time& delete_end, |
| 745 WebDatabase* db) { | 749 WebDatabase* db) { |
| 746 std::vector<std::string> profile_guids; | 750 std::vector<std::string> profile_guids; |
| 747 std::vector<std::string> credit_card_guids; | 751 std::vector<std::string> credit_card_guids; |
| 748 if (db->GetAutofillTable()-> | 752 if (AutofillTable::FromWebDatabase(db)-> |
| 749 RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 753 RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
| 750 delete_begin, | 754 delete_begin, |
| 751 delete_end, | 755 delete_end, |
| 752 &profile_guids, | 756 &profile_guids, |
| 753 &credit_card_guids)) { | 757 &credit_card_guids)) { |
| 754 for (std::vector<std::string>::iterator iter = profile_guids.begin(); | 758 for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
| 755 iter != profile_guids.end(); ++iter) { | 759 iter != profile_guids.end(); ++iter) { |
| 756 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, | 760 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, |
| 757 NULL); | 761 NULL); |
| 758 content::NotificationService::current()->Notify( | 762 content::NotificationService::current()->Notify( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 void WebDataService::DestroyAutofillCreditCardResult( | 808 void WebDataService::DestroyAutofillCreditCardResult( |
| 805 const WDTypedResult* result) { | 809 const WDTypedResult* result) { |
| 806 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 810 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
| 807 const WDResult<std::vector<CreditCard*> >* r = | 811 const WDResult<std::vector<CreditCard*> >* r = |
| 808 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 812 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
| 809 | 813 |
| 810 std::vector<CreditCard*> credit_cards = r->GetValue(); | 814 std::vector<CreditCard*> credit_cards = r->GetValue(); |
| 811 STLDeleteElements(&credit_cards); | 815 STLDeleteElements(&credit_cards); |
| 812 } | 816 } |
| 813 | 817 |
| OLD | NEW |