| 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 "chrome/browser/search_engines/template_url.h" | 7 #include "chrome/browser/search_engines/template_url.h" |
| 8 #include "chrome/browser/webdata/autocomplete_syncable_service.h" | 8 #include "chrome/browser/webdata/autocomplete_syncable_service.h" |
| 9 #include "chrome/browser/webdata/autofill_change.h" | 9 #include "chrome/browser/webdata/autofill_change.h" |
| 10 #include "chrome/browser/webdata/autofill_entry.h" | 10 #include "chrome/browser/webdata/autofill_entry.h" |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 305 } |
| 306 | 306 |
| 307 //////////////////////////////////////////////////////////////////////////////// | 307 //////////////////////////////////////////////////////////////////////////////// |
| 308 // | 308 // |
| 309 // Keywords implementation. | 309 // Keywords implementation. |
| 310 // | 310 // |
| 311 //////////////////////////////////////////////////////////////////////////////// | 311 //////////////////////////////////////////////////////////////////////////////// |
| 312 | 312 |
| 313 WebDatabase::State WebDataService::AddKeywordImpl( | 313 WebDatabase::State WebDataService::AddKeywordImpl( |
| 314 const TemplateURLData& data, WebDatabase* db) { | 314 const TemplateURLData& data, WebDatabase* db) { |
| 315 db->GetKeywordTable()->AddKeyword(data); | 315 KeywordTable::FromWebDatabase(db)->AddKeyword(data); |
| 316 return WebDatabase::COMMIT_NEEDED; | 316 return WebDatabase::COMMIT_NEEDED; |
| 317 } | 317 } |
| 318 | 318 |
| 319 WebDatabase::State WebDataService::RemoveKeywordImpl( | 319 WebDatabase::State WebDataService::RemoveKeywordImpl( |
| 320 TemplateURLID id, WebDatabase* db) { | 320 TemplateURLID id, WebDatabase* db) { |
| 321 DCHECK(id); | 321 DCHECK(id); |
| 322 db->GetKeywordTable()->RemoveKeyword(id); | 322 KeywordTable::FromWebDatabase(db)->RemoveKeyword(id); |
| 323 return WebDatabase::COMMIT_NEEDED; | 323 return WebDatabase::COMMIT_NEEDED; |
| 324 } | 324 } |
| 325 | 325 |
| 326 WebDatabase::State WebDataService::UpdateKeywordImpl( | 326 WebDatabase::State WebDataService::UpdateKeywordImpl( |
| 327 const TemplateURLData& data, WebDatabase* db) { | 327 const TemplateURLData& data, WebDatabase* db) { |
| 328 if (!db->GetKeywordTable()->UpdateKeyword(data)) { | 328 if (!KeywordTable::FromWebDatabase(db)->UpdateKeyword(data)) { |
| 329 NOTREACHED(); | 329 NOTREACHED(); |
| 330 return WebDatabase::COMMIT_NOT_NEEDED; | 330 return WebDatabase::COMMIT_NOT_NEEDED; |
| 331 } | 331 } |
| 332 return WebDatabase::COMMIT_NEEDED; | 332 return WebDatabase::COMMIT_NEEDED; |
| 333 } | 333 } |
| 334 | 334 |
| 335 scoped_ptr<WDTypedResult> WebDataService::GetKeywordsImpl(WebDatabase* db) { | 335 scoped_ptr<WDTypedResult> WebDataService::GetKeywordsImpl(WebDatabase* db) { |
| 336 WDKeywordsResult result; | 336 WDKeywordsResult result; |
| 337 db->GetKeywordTable()->GetKeywords(&result.keywords); | 337 KeywordTable::FromWebDatabase(db)->GetKeywords(&result.keywords); |
| 338 result.default_search_provider_id = | 338 result.default_search_provider_id = |
| 339 db->GetKeywordTable()->GetDefaultSearchProviderID(); | 339 KeywordTable::FromWebDatabase(db)->GetDefaultSearchProviderID(); |
| 340 result.builtin_keyword_version = | 340 result.builtin_keyword_version = |
| 341 db->GetKeywordTable()->GetBuiltinKeywordVersion(); | 341 KeywordTable::FromWebDatabase(db)->GetBuiltinKeywordVersion(); |
| 342 return scoped_ptr<WDTypedResult>( | 342 return scoped_ptr<WDTypedResult>( |
| 343 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); | 343 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); |
| 344 } | 344 } |
| 345 | 345 |
| 346 WebDatabase::State WebDataService::SetDefaultSearchProviderImpl( | 346 WebDatabase::State WebDataService::SetDefaultSearchProviderImpl( |
| 347 TemplateURLID id, WebDatabase* db) { | 347 TemplateURLID id, WebDatabase* db) { |
| 348 if (!db->GetKeywordTable()->SetDefaultSearchProviderID(id)) { | 348 if (!KeywordTable::FromWebDatabase(db)->SetDefaultSearchProviderID(id)) { |
| 349 NOTREACHED(); | 349 NOTREACHED(); |
| 350 return WebDatabase::COMMIT_NOT_NEEDED; | 350 return WebDatabase::COMMIT_NOT_NEEDED; |
| 351 } | 351 } |
| 352 return WebDatabase::COMMIT_NEEDED; | 352 return WebDatabase::COMMIT_NEEDED; |
| 353 } | 353 } |
| 354 | 354 |
| 355 WebDatabase::State WebDataService::SetBuiltinKeywordVersionImpl( | 355 WebDatabase::State WebDataService::SetBuiltinKeywordVersionImpl( |
| 356 int version, WebDatabase* db) { | 356 int version, WebDatabase* db) { |
| 357 if (!db->GetKeywordTable()->SetBuiltinKeywordVersion(version)) { | 357 if (!KeywordTable::FromWebDatabase(db)->SetBuiltinKeywordVersion(version)) { |
| 358 NOTREACHED(); | 358 NOTREACHED(); |
| 359 return WebDatabase::COMMIT_NOT_NEEDED; | 359 return WebDatabase::COMMIT_NOT_NEEDED; |
| 360 } | 360 } |
| 361 return WebDatabase::COMMIT_NEEDED; | 361 return WebDatabase::COMMIT_NEEDED; |
| 362 } | 362 } |
| 363 | 363 |
| 364 //////////////////////////////////////////////////////////////////////////////// | 364 //////////////////////////////////////////////////////////////////////////////// |
| 365 // | 365 // |
| 366 // Web Apps implementation. | 366 // Web Apps implementation. |
| 367 // | 367 // |
| 368 //////////////////////////////////////////////////////////////////////////////// | 368 //////////////////////////////////////////////////////////////////////////////// |
| 369 | 369 |
| 370 WebDatabase::State WebDataService::SetWebAppImageImpl( | 370 WebDatabase::State WebDataService::SetWebAppImageImpl( |
| 371 const GURL& app_url, const SkBitmap& image, WebDatabase* db) { | 371 const GURL& app_url, const SkBitmap& image, WebDatabase* db) { |
| 372 db->GetWebAppsTable()->SetWebAppImage(app_url, image); | 372 WebAppsTable::FromWebDatabase(db)->SetWebAppImage(app_url, image); |
| 373 return WebDatabase::COMMIT_NEEDED; | 373 return WebDatabase::COMMIT_NEEDED; |
| 374 } | 374 } |
| 375 | 375 |
| 376 WebDatabase::State WebDataService::SetWebAppHasAllImagesImpl( | 376 WebDatabase::State WebDataService::SetWebAppHasAllImagesImpl( |
| 377 const GURL& app_url, bool has_all_images, WebDatabase* db) { | 377 const GURL& app_url, bool has_all_images, WebDatabase* db) { |
| 378 db->GetWebAppsTable()-> | 378 WebAppsTable::FromWebDatabase(db)->SetWebAppHasAllImages(app_url, |
| 379 SetWebAppHasAllImages(app_url, has_all_images); | 379 has_all_images); |
| 380 return WebDatabase::COMMIT_NEEDED; | 380 return WebDatabase::COMMIT_NEEDED; |
| 381 } | 381 } |
| 382 | 382 |
| 383 WebDatabase::State WebDataService::RemoveWebAppImpl( | 383 WebDatabase::State WebDataService::RemoveWebAppImpl( |
| 384 const GURL& app_url, WebDatabase* db) { | 384 const GURL& app_url, WebDatabase* db) { |
| 385 db->GetWebAppsTable()->RemoveWebApp(app_url); | 385 WebAppsTable::FromWebDatabase(db)->RemoveWebApp(app_url); |
| 386 return WebDatabase::COMMIT_NEEDED; | 386 return WebDatabase::COMMIT_NEEDED; |
| 387 } | 387 } |
| 388 | 388 |
| 389 scoped_ptr<WDTypedResult> WebDataService::GetWebAppImagesImpl( | 389 scoped_ptr<WDTypedResult> WebDataService::GetWebAppImagesImpl( |
| 390 const GURL& app_url, WebDatabase* db) { | 390 const GURL& app_url, WebDatabase* db) { |
| 391 WDAppImagesResult result; | 391 WDAppImagesResult result; |
| 392 result.has_all_images = db->GetWebAppsTable()->GetWebAppHasAllImages(app_url); | 392 result.has_all_images = |
| 393 db->GetWebAppsTable()->GetWebAppImages(app_url, &result.images); | 393 WebAppsTable::FromWebDatabase(db)->GetWebAppHasAllImages(app_url); |
| 394 WebAppsTable::FromWebDatabase(db)->GetWebAppImages(app_url, &result.images); |
| 394 return scoped_ptr<WDTypedResult>( | 395 return scoped_ptr<WDTypedResult>( |
| 395 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); | 396 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); |
| 396 } | 397 } |
| 397 | 398 |
| 398 //////////////////////////////////////////////////////////////////////////////// | 399 //////////////////////////////////////////////////////////////////////////////// |
| 399 // | 400 // |
| 400 // Token Service implementation. | 401 // Token Service implementation. |
| 401 // | 402 // |
| 402 //////////////////////////////////////////////////////////////////////////////// | 403 //////////////////////////////////////////////////////////////////////////////// |
| 403 | 404 |
| 404 WebDatabase::State WebDataService::RemoveAllTokensImpl(WebDatabase* db) { | 405 WebDatabase::State WebDataService::RemoveAllTokensImpl(WebDatabase* db) { |
| 405 if (db->GetTokenServiceTable()->RemoveAllTokens()) { | 406 if (TokenServiceTable::FromWebDatabase(db)->RemoveAllTokens()) { |
| 406 return WebDatabase::COMMIT_NEEDED; | 407 return WebDatabase::COMMIT_NEEDED; |
| 407 } | 408 } |
| 408 return WebDatabase::COMMIT_NOT_NEEDED; | 409 return WebDatabase::COMMIT_NOT_NEEDED; |
| 409 } | 410 } |
| 410 | 411 |
| 411 WebDatabase::State WebDataService::SetTokenForServiceImpl( | 412 WebDatabase::State WebDataService::SetTokenForServiceImpl( |
| 412 const std::string& service, const std::string& token, WebDatabase* db) { | 413 const std::string& service, const std::string& token, WebDatabase* db) { |
| 413 if (db->GetTokenServiceTable()->SetTokenForService(service, token)) { | 414 if (TokenServiceTable::FromWebDatabase(db)->SetTokenForService(service, |
| 415 token)) { |
| 414 return WebDatabase::COMMIT_NEEDED; | 416 return WebDatabase::COMMIT_NEEDED; |
| 415 } | 417 } |
| 416 return WebDatabase::COMMIT_NOT_NEEDED; | 418 return WebDatabase::COMMIT_NOT_NEEDED; |
| 417 } | 419 } |
| 418 | 420 |
| 419 scoped_ptr<WDTypedResult> WebDataService::GetAllTokensImpl(WebDatabase* db) { | 421 scoped_ptr<WDTypedResult> WebDataService::GetAllTokensImpl(WebDatabase* db) { |
| 420 std::map<std::string, std::string> map; | 422 std::map<std::string, std::string> map; |
| 421 db->GetTokenServiceTable()->GetAllTokens(&map); | 423 TokenServiceTable::FromWebDatabase(db)->GetAllTokens(&map); |
| 422 return scoped_ptr<WDTypedResult>( | 424 return scoped_ptr<WDTypedResult>( |
| 423 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); | 425 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); |
| 424 } | 426 } |
| 425 | 427 |
| 426 //////////////////////////////////////////////////////////////////////////////// | 428 //////////////////////////////////////////////////////////////////////////////// |
| 427 // | 429 // |
| 428 // Autofill implementation. | 430 // Autofill implementation. |
| 429 // | 431 // |
| 430 //////////////////////////////////////////////////////////////////////////////// | 432 //////////////////////////////////////////////////////////////////////////////// |
| 431 | 433 |
| 432 WebDatabase::State WebDataService::AddFormElementsImpl( | 434 WebDatabase::State WebDataService::AddFormElementsImpl( |
| 433 const std::vector<FormFieldData>& fields, WebDatabase* db) { | 435 const std::vector<FormFieldData>& fields, WebDatabase* db) { |
| 434 AutofillChangeList changes; | 436 AutofillChangeList changes; |
| 435 if (!db->GetAutofillTable()->AddFormFieldValues(fields, &changes)) { | 437 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( |
| 438 fields, &changes)) { |
| 436 NOTREACHED(); | 439 NOTREACHED(); |
| 437 return WebDatabase::COMMIT_NOT_NEEDED; | 440 return WebDatabase::COMMIT_NOT_NEEDED; |
| 438 } | 441 } |
| 439 | 442 |
| 440 // Post the notifications including the list of affected keys. | 443 // Post the notifications including the list of affected keys. |
| 441 // This is sent here so that work resulting from this notification will be | 444 // This is sent here so that work resulting from this notification will be |
| 442 // done on the DB thread, and not the UI thread. | 445 // done on the DB thread, and not the UI thread. |
| 443 content::NotificationService::current()->Notify( | 446 content::NotificationService::current()->Notify( |
| 444 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 447 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 445 content::Source<WebDataService>(this), | 448 content::Source<WebDataService>(this), |
| 446 content::Details<AutofillChangeList>(&changes)); | 449 content::Details<AutofillChangeList>(&changes)); |
| 447 | 450 |
| 448 return WebDatabase::COMMIT_NEEDED; | 451 return WebDatabase::COMMIT_NEEDED; |
| 449 } | 452 } |
| 450 | 453 |
| 451 scoped_ptr<WDTypedResult> WebDataService::GetFormValuesForElementNameImpl( | 454 scoped_ptr<WDTypedResult> WebDataService::GetFormValuesForElementNameImpl( |
| 452 const string16& name, const string16& prefix, int limit, WebDatabase* db) { | 455 const string16& name, const string16& prefix, int limit, WebDatabase* db) { |
| 453 std::vector<string16> values; | 456 std::vector<string16> values; |
| 454 db->GetAutofillTable()->GetFormValuesForElementName( | 457 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( |
| 455 name, prefix, &values, limit); | 458 name, prefix, &values, limit); |
| 456 return scoped_ptr<WDTypedResult>( | 459 return scoped_ptr<WDTypedResult>( |
| 457 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); | 460 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); |
| 458 } | 461 } |
| 459 | 462 |
| 460 WebDatabase::State WebDataService::RemoveFormElementsAddedBetweenImpl( | 463 WebDatabase::State WebDataService::RemoveFormElementsAddedBetweenImpl( |
| 461 const base::Time& delete_begin, const base::Time& delete_end, | 464 const base::Time& delete_begin, const base::Time& delete_end, |
| 462 WebDatabase* db) { | 465 WebDatabase* db) { |
| 463 AutofillChangeList changes; | 466 AutofillChangeList changes; |
| 464 | 467 |
| 465 if (db->GetAutofillTable()->RemoveFormElementsAddedBetween( | 468 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( |
| 466 delete_begin, delete_end, &changes)) { | 469 delete_begin, delete_end, &changes)) { |
| 467 if (!changes.empty()) { | 470 if (!changes.empty()) { |
| 468 // Post the notifications including the list of affected keys. | 471 // Post the notifications including the list of affected keys. |
| 469 // This is sent here so that work resulting from this notification | 472 // This is sent here so that work resulting from this notification |
| 470 // will be done on the DB thread, and not the UI thread. | 473 // will be done on the DB thread, and not the UI thread. |
| 471 content::NotificationService::current()->Notify( | 474 content::NotificationService::current()->Notify( |
| 472 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 475 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 473 content::Source<WebDataService>(this), | 476 content::Source<WebDataService>(this), |
| 474 content::Details<AutofillChangeList>(&changes)); | 477 content::Details<AutofillChangeList>(&changes)); |
| 475 } | 478 } |
| 476 return WebDatabase::COMMIT_NEEDED; | 479 return WebDatabase::COMMIT_NEEDED; |
| 477 } | 480 } |
| 478 return WebDatabase::COMMIT_NOT_NEEDED; | 481 return WebDatabase::COMMIT_NOT_NEEDED; |
| 479 } | 482 } |
| 480 | 483 |
| 481 WebDatabase::State WebDataService::RemoveExpiredFormElementsImpl( | 484 WebDatabase::State WebDataService::RemoveExpiredFormElementsImpl( |
| 482 WebDatabase* db) { | 485 WebDatabase* db) { |
| 483 AutofillChangeList changes; | 486 AutofillChangeList changes; |
| 484 | 487 |
| 485 if (db->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { | 488 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { |
| 486 if (!changes.empty()) { | 489 if (!changes.empty()) { |
| 487 // Post the notifications including the list of affected keys. | 490 // Post the notifications including the list of affected keys. |
| 488 // This is sent here so that work resulting from this notification | 491 // This is sent here so that work resulting from this notification |
| 489 // will be done on the DB thread, and not the UI thread. | 492 // will be done on the DB thread, and not the UI thread. |
| 490 content::NotificationService::current()->Notify( | 493 content::NotificationService::current()->Notify( |
| 491 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 494 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 492 content::Source<WebDataService>(this), | 495 content::Source<WebDataService>(this), |
| 493 content::Details<AutofillChangeList>(&changes)); | 496 content::Details<AutofillChangeList>(&changes)); |
| 494 } | 497 } |
| 495 return WebDatabase::COMMIT_NEEDED; | 498 return WebDatabase::COMMIT_NEEDED; |
| 496 } | 499 } |
| 497 return WebDatabase::COMMIT_NOT_NEEDED; | 500 return WebDatabase::COMMIT_NOT_NEEDED; |
| 498 } | 501 } |
| 499 | 502 |
| 500 WebDatabase::State WebDataService::RemoveFormValueForElementNameImpl( | 503 WebDatabase::State WebDataService::RemoveFormValueForElementNameImpl( |
| 501 const string16& name, const string16& value, WebDatabase* db) { | 504 const string16& name, const string16& value, WebDatabase* db) { |
| 502 | 505 |
| 503 if (db->GetAutofillTable()->RemoveFormElement(name, value)) { | 506 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { |
| 504 AutofillChangeList changes; | 507 AutofillChangeList changes; |
| 505 changes.push_back(AutofillChange(AutofillChange::REMOVE, | 508 changes.push_back(AutofillChange(AutofillChange::REMOVE, |
| 506 AutofillKey(name, value))); | 509 AutofillKey(name, value))); |
| 507 | 510 |
| 508 // Post the notifications including the list of affected keys. | 511 // Post the notifications including the list of affected keys. |
| 509 content::NotificationService::current()->Notify( | 512 content::NotificationService::current()->Notify( |
| 510 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 513 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 511 content::Source<WebDataService>(this), | 514 content::Source<WebDataService>(this), |
| 512 content::Details<AutofillChangeList>(&changes)); | 515 content::Details<AutofillChangeList>(&changes)); |
| 513 | 516 |
| 514 return WebDatabase::COMMIT_NEEDED; | 517 return WebDatabase::COMMIT_NEEDED; |
| 515 } | 518 } |
| 516 return WebDatabase::COMMIT_NOT_NEEDED; | 519 return WebDatabase::COMMIT_NOT_NEEDED; |
| 517 } | 520 } |
| 518 | 521 |
| 519 WebDatabase::State WebDataService::AddAutofillProfileImpl( | 522 WebDatabase::State WebDataService::AddAutofillProfileImpl( |
| 520 const AutofillProfile& profile, WebDatabase* db) { | 523 const AutofillProfile& profile, WebDatabase* db) { |
| 521 if (!db->GetAutofillTable()->AddAutofillProfile(profile)) { | 524 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { |
| 522 NOTREACHED(); | 525 NOTREACHED(); |
| 523 return WebDatabase::COMMIT_NOT_NEEDED; | 526 return WebDatabase::COMMIT_NOT_NEEDED; |
| 524 } | 527 } |
| 525 | 528 |
| 526 // Send GUID-based notification. | 529 // Send GUID-based notification. |
| 527 AutofillProfileChange change(AutofillProfileChange::ADD, | 530 AutofillProfileChange change(AutofillProfileChange::ADD, |
| 528 profile.guid(), &profile); | 531 profile.guid(), &profile); |
| 529 content::NotificationService::current()->Notify( | 532 content::NotificationService::current()->Notify( |
| 530 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 533 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 531 content::Source<WebDataService>(this), | 534 content::Source<WebDataService>(this), |
| 532 content::Details<AutofillProfileChange>(&change)); | 535 content::Details<AutofillProfileChange>(&change)); |
| 533 | 536 |
| 534 return WebDatabase::COMMIT_NEEDED; | 537 return WebDatabase::COMMIT_NEEDED; |
| 535 } | 538 } |
| 536 | 539 |
| 537 WebDatabase::State WebDataService::UpdateAutofillProfileImpl( | 540 WebDatabase::State WebDataService::UpdateAutofillProfileImpl( |
| 538 const AutofillProfile& profile, WebDatabase* db) { | 541 const AutofillProfile& profile, WebDatabase* db) { |
| 539 // Only perform the update if the profile exists. It is currently | 542 // Only perform the update if the profile exists. It is currently |
| 540 // valid to try to update a missing profile. We simply drop the write and | 543 // valid to try to update a missing profile. We simply drop the write and |
| 541 // the caller will detect this on the next refresh. | 544 // the caller will detect this on the next refresh. |
| 542 AutofillProfile* original_profile = NULL; | 545 AutofillProfile* original_profile = NULL; |
| 543 if (!db->GetAutofillTable()->GetAutofillProfile(profile.guid(), | 546 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), |
| 544 &original_profile)) { | 547 &original_profile)) { |
| 545 return WebDatabase::COMMIT_NOT_NEEDED; | 548 return WebDatabase::COMMIT_NOT_NEEDED; |
| 546 } | 549 } |
| 547 scoped_ptr<AutofillProfile> scoped_profile(original_profile); | 550 scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
| 548 | 551 |
| 549 if (!db->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) { | 552 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( |
| 553 profile)) { |
| 550 NOTREACHED(); | 554 NOTREACHED(); |
| 551 return WebDatabase::COMMIT_NEEDED; | 555 return WebDatabase::COMMIT_NEEDED; |
| 552 } | 556 } |
| 553 | 557 |
| 554 // Send GUID-based notification. | 558 // Send GUID-based notification. |
| 555 AutofillProfileChange change(AutofillProfileChange::UPDATE, | 559 AutofillProfileChange change(AutofillProfileChange::UPDATE, |
| 556 profile.guid(), &profile); | 560 profile.guid(), &profile); |
| 557 content::NotificationService::current()->Notify( | 561 content::NotificationService::current()->Notify( |
| 558 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 562 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 559 content::Source<WebDataService>(this), | 563 content::Source<WebDataService>(this), |
| 560 content::Details<AutofillProfileChange>(&change)); | 564 content::Details<AutofillProfileChange>(&change)); |
| 561 | 565 |
| 562 return WebDatabase::COMMIT_NEEDED; | 566 return WebDatabase::COMMIT_NEEDED; |
| 563 } | 567 } |
| 564 | 568 |
| 565 WebDatabase::State WebDataService::RemoveAutofillProfileImpl( | 569 WebDatabase::State WebDataService::RemoveAutofillProfileImpl( |
| 566 const std::string& guid, WebDatabase* db) { | 570 const std::string& guid, WebDatabase* db) { |
| 567 AutofillProfile* profile = NULL; | 571 AutofillProfile* profile = NULL; |
| 568 if (!db->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { | 572 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { |
| 569 NOTREACHED(); | 573 NOTREACHED(); |
| 570 return WebDatabase::COMMIT_NOT_NEEDED; | 574 return WebDatabase::COMMIT_NOT_NEEDED; |
| 571 } | 575 } |
| 572 scoped_ptr<AutofillProfile> scoped_profile(profile); | 576 scoped_ptr<AutofillProfile> scoped_profile(profile); |
| 573 | 577 |
| 574 if (!db->GetAutofillTable()->RemoveAutofillProfile(guid)) { | 578 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { |
| 575 NOTREACHED(); | 579 NOTREACHED(); |
| 576 return WebDatabase::COMMIT_NOT_NEEDED; | 580 return WebDatabase::COMMIT_NOT_NEEDED; |
| 577 } | 581 } |
| 578 | 582 |
| 579 // Send GUID-based notification. | 583 // Send GUID-based notification. |
| 580 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); | 584 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
| 581 content::NotificationService::current()->Notify( | 585 content::NotificationService::current()->Notify( |
| 582 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 586 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 583 content::Source<WebDataService>(this), | 587 content::Source<WebDataService>(this), |
| 584 content::Details<AutofillProfileChange>(&change)); | 588 content::Details<AutofillProfileChange>(&change)); |
| 585 | 589 |
| 586 return WebDatabase::COMMIT_NEEDED; | 590 return WebDatabase::COMMIT_NEEDED; |
| 587 } | 591 } |
| 588 | 592 |
| 589 scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl( | 593 scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl( |
| 590 WebDatabase* db) { | 594 WebDatabase* db) { |
| 591 std::vector<AutofillProfile*> profiles; | 595 std::vector<AutofillProfile*> profiles; |
| 592 db->GetAutofillTable()->GetAutofillProfiles(&profiles); | 596 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); |
| 593 return scoped_ptr<WDTypedResult>( | 597 return scoped_ptr<WDTypedResult>( |
| 594 new WDDestroyableResult<std::vector<AutofillProfile*> >( | 598 new WDDestroyableResult<std::vector<AutofillProfile*> >( |
| 595 AUTOFILL_PROFILES_RESULT, | 599 AUTOFILL_PROFILES_RESULT, |
| 596 profiles, | 600 profiles, |
| 597 base::Bind(&WebDataService::DestroyAutofillProfileResult, | 601 base::Bind(&WebDataService::DestroyAutofillProfileResult, |
| 598 base::Unretained(this)))); | 602 base::Unretained(this)))); |
| 599 } | 603 } |
| 600 | 604 |
| 601 WebDatabase::State WebDataService::AddCreditCardImpl( | 605 WebDatabase::State WebDataService::AddCreditCardImpl( |
| 602 const CreditCard& credit_card, WebDatabase* db) { | 606 const CreditCard& credit_card, WebDatabase* db) { |
| 603 if (!db->GetAutofillTable()->AddCreditCard(credit_card)) { | 607 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { |
| 604 NOTREACHED(); | 608 NOTREACHED(); |
| 605 return WebDatabase::COMMIT_NOT_NEEDED; | 609 return WebDatabase::COMMIT_NOT_NEEDED; |
| 606 } | 610 } |
| 607 | 611 |
| 608 return WebDatabase::COMMIT_NEEDED; | 612 return WebDatabase::COMMIT_NEEDED; |
| 609 } | 613 } |
| 610 | 614 |
| 611 WebDatabase::State WebDataService::UpdateCreditCardImpl( | 615 WebDatabase::State WebDataService::UpdateCreditCardImpl( |
| 612 const CreditCard& credit_card, WebDatabase* db) { | 616 const CreditCard& credit_card, WebDatabase* db) { |
| 613 // It is currently valid to try to update a missing profile. We simply drop | 617 // It is currently valid to try to update a missing profile. We simply drop |
| 614 // the write and the caller will detect this on the next refresh. | 618 // the write and the caller will detect this on the next refresh. |
| 615 CreditCard* original_credit_card = NULL; | 619 CreditCard* original_credit_card = NULL; |
| 616 if (!db->GetAutofillTable()->GetCreditCard(credit_card.guid(), | 620 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), |
| 617 &original_credit_card)) { | 621 &original_credit_card)) { |
| 618 return WebDatabase::COMMIT_NOT_NEEDED; | 622 return WebDatabase::COMMIT_NOT_NEEDED; |
| 619 } | 623 } |
| 620 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); | 624 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); |
| 621 | 625 |
| 622 if (!db->GetAutofillTable()->UpdateCreditCard(credit_card)) { | 626 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { |
| 623 NOTREACHED(); | 627 NOTREACHED(); |
| 624 return WebDatabase::COMMIT_NOT_NEEDED; | 628 return WebDatabase::COMMIT_NOT_NEEDED; |
| 625 } | 629 } |
| 626 return WebDatabase::COMMIT_NEEDED; | 630 return WebDatabase::COMMIT_NEEDED; |
| 627 } | 631 } |
| 628 | 632 |
| 629 WebDatabase::State WebDataService::RemoveCreditCardImpl( | 633 WebDatabase::State WebDataService::RemoveCreditCardImpl( |
| 630 const std::string& guid, WebDatabase* db) { | 634 const std::string& guid, WebDatabase* db) { |
| 631 if (!db->GetAutofillTable()->RemoveCreditCard(guid)) { | 635 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { |
| 632 NOTREACHED(); | 636 NOTREACHED(); |
| 633 return WebDatabase::COMMIT_NOT_NEEDED; | 637 return WebDatabase::COMMIT_NOT_NEEDED; |
| 634 } | 638 } |
| 635 return WebDatabase::COMMIT_NEEDED; | 639 return WebDatabase::COMMIT_NEEDED; |
| 636 } | 640 } |
| 637 | 641 |
| 638 scoped_ptr<WDTypedResult> WebDataService::GetCreditCardsImpl(WebDatabase* db) { | 642 scoped_ptr<WDTypedResult> WebDataService::GetCreditCardsImpl(WebDatabase* db) { |
| 639 std::vector<CreditCard*> credit_cards; | 643 std::vector<CreditCard*> credit_cards; |
| 640 db->GetAutofillTable()->GetCreditCards(&credit_cards); | 644 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); |
| 641 return scoped_ptr<WDTypedResult>( | 645 return scoped_ptr<WDTypedResult>( |
| 642 new WDDestroyableResult<std::vector<CreditCard*> >( | 646 new WDDestroyableResult<std::vector<CreditCard*> >( |
| 643 AUTOFILL_CREDITCARDS_RESULT, | 647 AUTOFILL_CREDITCARDS_RESULT, |
| 644 credit_cards, | 648 credit_cards, |
| 645 base::Bind(&WebDataService::DestroyAutofillCreditCardResult, | 649 base::Bind(&WebDataService::DestroyAutofillCreditCardResult, |
| 646 base::Unretained(this)))); | 650 base::Unretained(this)))); |
| 647 } | 651 } |
| 648 | 652 |
| 649 WebDatabase::State | 653 WebDatabase::State |
| 650 WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( | 654 WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( |
| 651 const base::Time& delete_begin, const base::Time& delete_end, | 655 const base::Time& delete_begin, const base::Time& delete_end, |
| 652 WebDatabase* db) { | 656 WebDatabase* db) { |
| 653 std::vector<std::string> profile_guids; | 657 std::vector<std::string> profile_guids; |
| 654 std::vector<std::string> credit_card_guids; | 658 std::vector<std::string> credit_card_guids; |
| 655 if (db->GetAutofillTable()-> | 659 if (AutofillTable::FromWebDatabase(db)-> |
| 656 RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 660 RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
| 657 delete_begin, | 661 delete_begin, |
| 658 delete_end, | 662 delete_end, |
| 659 &profile_guids, | 663 &profile_guids, |
| 660 &credit_card_guids)) { | 664 &credit_card_guids)) { |
| 661 for (std::vector<std::string>::iterator iter = profile_guids.begin(); | 665 for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
| 662 iter != profile_guids.end(); ++iter) { | 666 iter != profile_guids.end(); ++iter) { |
| 663 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, | 667 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, |
| 664 NULL); | 668 NULL); |
| 665 content::NotificationService::current()->Notify( | 669 content::NotificationService::current()->Notify( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 | 704 |
| 701 void WebDataService::DestroyAutofillCreditCardResult( | 705 void WebDataService::DestroyAutofillCreditCardResult( |
| 702 const WDTypedResult* result) { | 706 const WDTypedResult* result) { |
| 703 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 707 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
| 704 const WDResult<std::vector<CreditCard*> >* r = | 708 const WDResult<std::vector<CreditCard*> >* r = |
| 705 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 709 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
| 706 | 710 |
| 707 std::vector<CreditCard*> credit_cards = r->GetValue(); | 711 std::vector<CreditCard*> credit_cards = r->GetValue(); |
| 708 STLDeleteElements(&credit_cards); | 712 STLDeleteElements(&credit_cards); |
| 709 } | 713 } |
| OLD | NEW |