| Index: chrome/browser/webdata/web_data_service.cc
|
| diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
|
| index edf882768248bb8724985558d5f3d5fe39f33394..9557ef869d875f7c318002d45e6168e7628fed22 100644
|
| --- a/chrome/browser/webdata/web_data_service.cc
|
| +++ b/chrome/browser/webdata/web_data_service.cc
|
| @@ -4,15 +4,7 @@
|
|
|
| #include "chrome/browser/webdata/web_data_service.h"
|
|
|
| -#include "base/bind.h"
|
| -#include "base/command_line.h"
|
| -#include "base/message_loop.h"
|
| -#include "base/stl_util.h"
|
| -#include "base/threading/thread.h"
|
| -#include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/search_engines/template_url.h"
|
| -#include "chrome/browser/ui/profile_error_dialog.h"
|
| #include "chrome/browser/webdata/autocomplete_syncable_service.h"
|
| #include "chrome/browser/webdata/autofill_change.h"
|
| #include "chrome/browser/webdata/autofill_entry.h"
|
| @@ -24,20 +16,14 @@
|
| #include "chrome/browser/webdata/web_apps_table.h"
|
| #include "chrome/browser/webdata/web_database_service.h"
|
| #include "chrome/browser/webdata/web_intents_table.h"
|
| -#include "chrome/common/chrome_constants.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| #include "components/autofill/browser/autofill_country.h"
|
| #include "components/autofill/browser/autofill_profile.h"
|
| #include "components/autofill/browser/credit_card.h"
|
| #include "components/autofill/common/form_field_data.h"
|
| -#ifdef DEBUG
|
| -#include "content/public/browser/browser_thread.h"
|
| -#endif
|
| #include "content/public/browser/notification_details.h"
|
| #include "content/public/browser/notification_service.h"
|
| #include "content/public/browser/notification_source.h"
|
| -#include "grit/chromium_strings.h"
|
| -#include "grit/generated_resources.h"
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -77,14 +63,10 @@ WDKeywordsResult::WDKeywordsResult()
|
|
|
| WDKeywordsResult::~WDKeywordsResult() {}
|
|
|
| -WebDataService::WebDataService()
|
| - : db_loaded_(false),
|
| +WebDataService::WebDataService(const ProfileErrorCallback& callback)
|
| + : WebDataServiceBase(callback),
|
| autocomplete_syncable_service_(NULL),
|
| autofill_profile_syncable_service_(NULL) {
|
| - // WebDataService requires DB thread if instantiated.
|
| - // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL)
|
| - // if you do not want to instantiate WebDataService in your test.
|
| - DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB));
|
| }
|
|
|
| // static
|
| @@ -102,52 +84,17 @@ void WebDataService::NotifyOfMultipleAutofillChanges(
|
| }
|
|
|
| void WebDataService::ShutdownOnUIThread() {
|
| - db_loaded_ = false;
|
| - ShutdownDatabase();
|
| BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
|
| Bind(&WebDataService::ShutdownSyncableServices, this));
|
| + WebDataServiceBase::ShutdownOnUIThread();
|
| }
|
|
|
| void WebDataService::Init(const base::FilePath& path) {
|
| - wdbs_.reset(new WebDatabaseService(path));
|
| - wdbs_->LoadDatabase(Bind(&WebDataService::DatabaseInitOnDB, this));
|
| -
|
| + WebDataServiceBase::Init(path);
|
| BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
|
| Bind(&WebDataService::InitializeSyncableServices, this));
|
| }
|
|
|
| -void WebDataService::UnloadDatabase() {
|
| - if (!wdbs_)
|
| - return;
|
| - wdbs_->UnloadDatabase();
|
| -}
|
| -
|
| -void WebDataService::ShutdownDatabase() {
|
| - if (!wdbs_)
|
| - return;
|
| - wdbs_->ShutdownDatabase();
|
| -}
|
| -
|
| -void WebDataService::CancelRequest(Handle h) {
|
| - if (!wdbs_)
|
| - return;
|
| - wdbs_->CancelRequest(h);
|
| -}
|
| -
|
| -content::NotificationSource WebDataService::GetNotificationSource() {
|
| - return content::Source<WebDataService>(this);
|
| -}
|
| -
|
| -bool WebDataService::IsDatabaseLoaded() {
|
| - return db_loaded_;
|
| -}
|
| -
|
| -WebDatabase* WebDataService::GetDatabase() {
|
| - if (!wdbs_)
|
| - return NULL;
|
| - return wdbs_->GetDatabaseOnDB();
|
| -}
|
| -
|
| //////////////////////////////////////////////////////////////////////////////
|
| //
|
| // Keywords.
|
| @@ -329,8 +276,13 @@ void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween(
|
| this, delete_begin, delete_end));
|
| }
|
|
|
| +WebDataService::WebDataService()
|
| + : WebDataServiceBase(ProfileErrorCallback()),
|
| + autocomplete_syncable_service_(NULL),
|
| + autofill_profile_syncable_service_(NULL) {
|
| +}
|
| +
|
| WebDataService::~WebDataService() {
|
| - wdbs_.reset();
|
| DCHECK(!autocomplete_syncable_service_);
|
| DCHECK(!autofill_profile_syncable_service_);
|
| }
|
| @@ -341,34 +293,6 @@ WebDataService::~WebDataService() {
|
| //
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| -void WebDataService::DBInitFailed(sql::InitStatus sql_status) {
|
| - ShowProfileErrorDialog(
|
| - (sql_status == sql::INIT_FAILURE) ?
|
| - IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
|
| -}
|
| -
|
| -void WebDataService::NotifyDatabaseLoadedOnUIThread() {
|
| - db_loaded_ = true;
|
| - // Notify that the database has been initialized.
|
| - content::NotificationService::current()->Notify(
|
| - chrome::NOTIFICATION_WEB_DATABASE_LOADED,
|
| - content::Source<WebDataService>(this),
|
| - content::NotificationService::NoDetails());
|
| -}
|
| -
|
| -void WebDataService::DatabaseInitOnDB(sql::InitStatus status) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
|
| - if (status == sql::INIT_OK) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&WebDataService::NotifyDatabaseLoadedOnUIThread, this));
|
| - } else {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&WebDataService::DBInitFailed, this, status));
|
| - }
|
| -}
|
| -
|
| void WebDataService::InitializeSyncableServices() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
|
| DCHECK(!autocomplete_syncable_service_);
|
| @@ -395,20 +319,20 @@ void WebDataService::ShutdownSyncableServices() {
|
|
|
| WebDatabase::State WebDataService::AddKeywordImpl(
|
| const TemplateURLData& data, WebDatabase* db) {
|
| - db->GetKeywordTable()->AddKeyword(data);
|
| + KeywordTable::FromWebDatabase(db)->AddKeyword(data);
|
| return WebDatabase::COMMIT_NEEDED;
|
| }
|
|
|
| WebDatabase::State WebDataService::RemoveKeywordImpl(
|
| TemplateURLID id, WebDatabase* db) {
|
| DCHECK(id);
|
| - db->GetKeywordTable()->RemoveKeyword(id);
|
| + KeywordTable::FromWebDatabase(db)->RemoveKeyword(id);
|
| return WebDatabase::COMMIT_NEEDED;
|
| }
|
|
|
| WebDatabase::State WebDataService::UpdateKeywordImpl(
|
| const TemplateURLData& data, WebDatabase* db) {
|
| - if (!db->GetKeywordTable()->UpdateKeyword(data)) {
|
| + if (!KeywordTable::FromWebDatabase(db)->UpdateKeyword(data)) {
|
| NOTREACHED();
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| @@ -417,18 +341,18 @@ WebDatabase::State WebDataService::UpdateKeywordImpl(
|
|
|
| scoped_ptr<WDTypedResult> WebDataService::GetKeywordsImpl(WebDatabase* db) {
|
| WDKeywordsResult result;
|
| - db->GetKeywordTable()->GetKeywords(&result.keywords);
|
| + KeywordTable::FromWebDatabase(db)->GetKeywords(&result.keywords);
|
| result.default_search_provider_id =
|
| - db->GetKeywordTable()->GetDefaultSearchProviderID();
|
| + KeywordTable::FromWebDatabase(db)->GetDefaultSearchProviderID();
|
| result.builtin_keyword_version =
|
| - db->GetKeywordTable()->GetBuiltinKeywordVersion();
|
| + KeywordTable::FromWebDatabase(db)->GetBuiltinKeywordVersion();
|
| return scoped_ptr<WDTypedResult>(
|
| new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result));
|
| }
|
|
|
| WebDatabase::State WebDataService::SetDefaultSearchProviderImpl(
|
| TemplateURLID id, WebDatabase* db) {
|
| - if (!db->GetKeywordTable()->SetDefaultSearchProviderID(id)) {
|
| + if (!KeywordTable::FromWebDatabase(db)->SetDefaultSearchProviderID(id)) {
|
| NOTREACHED();
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| @@ -437,7 +361,7 @@ WebDatabase::State WebDataService::SetDefaultSearchProviderImpl(
|
|
|
| WebDatabase::State WebDataService::SetBuiltinKeywordVersionImpl(
|
| int version, WebDatabase* db) {
|
| - if (!db->GetKeywordTable()->SetBuiltinKeywordVersion(version)) {
|
| + if (!KeywordTable::FromWebDatabase(db)->SetBuiltinKeywordVersion(version)) {
|
| NOTREACHED();
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| @@ -452,28 +376,29 @@ WebDatabase::State WebDataService::SetBuiltinKeywordVersionImpl(
|
|
|
| WebDatabase::State WebDataService::SetWebAppImageImpl(
|
| const GURL& app_url, const SkBitmap& image, WebDatabase* db) {
|
| - db->GetWebAppsTable()->SetWebAppImage(app_url, image);
|
| + WebAppsTable::FromWebDatabase(db)->SetWebAppImage(app_url, image);
|
| return WebDatabase::COMMIT_NEEDED;
|
| }
|
|
|
| WebDatabase::State WebDataService::SetWebAppHasAllImagesImpl(
|
| const GURL& app_url, bool has_all_images, WebDatabase* db) {
|
| - db->GetWebAppsTable()->
|
| - SetWebAppHasAllImages(app_url, has_all_images);
|
| + WebAppsTable::FromWebDatabase(db)->SetWebAppHasAllImages(app_url,
|
| + has_all_images);
|
| return WebDatabase::COMMIT_NEEDED;
|
| }
|
|
|
| WebDatabase::State WebDataService::RemoveWebAppImpl(
|
| const GURL& app_url, WebDatabase* db) {
|
| - db->GetWebAppsTable()->RemoveWebApp(app_url);
|
| + WebAppsTable::FromWebDatabase(db)->RemoveWebApp(app_url);
|
| return WebDatabase::COMMIT_NEEDED;
|
| }
|
|
|
| scoped_ptr<WDTypedResult> WebDataService::GetWebAppImagesImpl(
|
| const GURL& app_url, WebDatabase* db) {
|
| WDAppImagesResult result;
|
| - result.has_all_images = db->GetWebAppsTable()->GetWebAppHasAllImages(app_url);
|
| - db->GetWebAppsTable()->GetWebAppImages(app_url, &result.images);
|
| + result.has_all_images =
|
| + WebAppsTable::FromWebDatabase(db)->GetWebAppHasAllImages(app_url);
|
| + WebAppsTable::FromWebDatabase(db)->GetWebAppImages(app_url, &result.images);
|
| return scoped_ptr<WDTypedResult>(
|
| new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result));
|
| }
|
| @@ -485,7 +410,7 @@ scoped_ptr<WDTypedResult> WebDataService::GetWebAppImagesImpl(
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| WebDatabase::State WebDataService::RemoveAllTokensImpl(WebDatabase* db) {
|
| - if (db->GetTokenServiceTable()->RemoveAllTokens()) {
|
| + if (TokenServiceTable::FromWebDatabase(db)->RemoveAllTokens()) {
|
| return WebDatabase::COMMIT_NEEDED;
|
| }
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| @@ -493,7 +418,8 @@ WebDatabase::State WebDataService::RemoveAllTokensImpl(WebDatabase* db) {
|
|
|
| WebDatabase::State WebDataService::SetTokenForServiceImpl(
|
| const std::string& service, const std::string& token, WebDatabase* db) {
|
| - if (db->GetTokenServiceTable()->SetTokenForService(service, token)) {
|
| + if (TokenServiceTable::FromWebDatabase(db)->SetTokenForService(service,
|
| + token)) {
|
| return WebDatabase::COMMIT_NEEDED;
|
| }
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| @@ -501,7 +427,7 @@ WebDatabase::State WebDataService::SetTokenForServiceImpl(
|
|
|
| scoped_ptr<WDTypedResult> WebDataService::GetAllTokensImpl(WebDatabase* db) {
|
| std::map<std::string, std::string> map;
|
| - db->GetTokenServiceTable()->GetAllTokens(&map);
|
| + TokenServiceTable::FromWebDatabase(db)->GetAllTokens(&map);
|
| return scoped_ptr<WDTypedResult>(
|
| new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map));
|
| }
|
| @@ -515,7 +441,8 @@ scoped_ptr<WDTypedResult> WebDataService::GetAllTokensImpl(WebDatabase* db) {
|
| WebDatabase::State WebDataService::AddFormElementsImpl(
|
| const std::vector<FormFieldData>& fields, WebDatabase* db) {
|
| AutofillChangeList changes;
|
| - if (!db->GetAutofillTable()->AddFormFieldValues(fields, &changes)) {
|
| + if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues(
|
| + fields, &changes)) {
|
| NOTREACHED();
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| @@ -534,7 +461,7 @@ WebDatabase::State WebDataService::AddFormElementsImpl(
|
| scoped_ptr<WDTypedResult> WebDataService::GetFormValuesForElementNameImpl(
|
| const string16& name, const string16& prefix, int limit, WebDatabase* db) {
|
| std::vector<string16> values;
|
| - db->GetAutofillTable()->GetFormValuesForElementName(
|
| + AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName(
|
| name, prefix, &values, limit);
|
| return scoped_ptr<WDTypedResult>(
|
| new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values));
|
| @@ -545,7 +472,7 @@ WebDatabase::State WebDataService::RemoveFormElementsAddedBetweenImpl(
|
| WebDatabase* db) {
|
| AutofillChangeList changes;
|
|
|
| - if (db->GetAutofillTable()->RemoveFormElementsAddedBetween(
|
| + if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween(
|
| delete_begin, delete_end, &changes)) {
|
| if (!changes.empty()) {
|
| // Post the notifications including the list of affected keys.
|
| @@ -565,7 +492,7 @@ WebDatabase::State WebDataService::RemoveExpiredFormElementsImpl(
|
| WebDatabase* db) {
|
| AutofillChangeList changes;
|
|
|
| - if (db->GetAutofillTable()->RemoveExpiredFormElements(&changes)) {
|
| + if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) {
|
| if (!changes.empty()) {
|
| // Post the notifications including the list of affected keys.
|
| // This is sent here so that work resulting from this notification
|
| @@ -583,7 +510,7 @@ WebDatabase::State WebDataService::RemoveExpiredFormElementsImpl(
|
| WebDatabase::State WebDataService::RemoveFormValueForElementNameImpl(
|
| const string16& name, const string16& value, WebDatabase* db) {
|
|
|
| - if (db->GetAutofillTable()->RemoveFormElement(name, value)) {
|
| + if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) {
|
| AutofillChangeList changes;
|
| changes.push_back(AutofillChange(AutofillChange::REMOVE,
|
| AutofillKey(name, value)));
|
| @@ -601,7 +528,7 @@ WebDatabase::State WebDataService::RemoveFormValueForElementNameImpl(
|
|
|
| WebDatabase::State WebDataService::AddAutofillProfileImpl(
|
| const AutofillProfile& profile, WebDatabase* db) {
|
| - if (!db->GetAutofillTable()->AddAutofillProfile(profile)) {
|
| + if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) {
|
| NOTREACHED();
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| @@ -623,13 +550,14 @@ WebDatabase::State WebDataService::UpdateAutofillProfileImpl(
|
| // valid to try to update a missing profile. We simply drop the write and
|
| // the caller will detect this on the next refresh.
|
| AutofillProfile* original_profile = NULL;
|
| - if (!db->GetAutofillTable()->GetAutofillProfile(profile.guid(),
|
| + if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(),
|
| &original_profile)) {
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| scoped_ptr<AutofillProfile> scoped_profile(original_profile);
|
|
|
| - if (!db->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) {
|
| + if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti(
|
| + profile)) {
|
| NOTREACHED();
|
| return WebDatabase::COMMIT_NEEDED;
|
| }
|
| @@ -648,13 +576,13 @@ WebDatabase::State WebDataService::UpdateAutofillProfileImpl(
|
| WebDatabase::State WebDataService::RemoveAutofillProfileImpl(
|
| const std::string& guid, WebDatabase* db) {
|
| AutofillProfile* profile = NULL;
|
| - if (!db->GetAutofillTable()->GetAutofillProfile(guid, &profile)) {
|
| + if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) {
|
| NOTREACHED();
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| scoped_ptr<AutofillProfile> scoped_profile(profile);
|
|
|
| - if (!db->GetAutofillTable()->RemoveAutofillProfile(guid)) {
|
| + if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) {
|
| NOTREACHED();
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| @@ -672,7 +600,7 @@ WebDatabase::State WebDataService::RemoveAutofillProfileImpl(
|
| scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl(
|
| WebDatabase* db) {
|
| std::vector<AutofillProfile*> profiles;
|
| - db->GetAutofillTable()->GetAutofillProfiles(&profiles);
|
| + AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles);
|
| return scoped_ptr<WDTypedResult>(
|
| new WDDestroyableResult<std::vector<AutofillProfile*> >(
|
| AUTOFILL_PROFILES_RESULT,
|
| @@ -683,7 +611,7 @@ scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl(
|
|
|
| WebDatabase::State WebDataService::AddCreditCardImpl(
|
| const CreditCard& credit_card, WebDatabase* db) {
|
| - if (!db->GetAutofillTable()->AddCreditCard(credit_card)) {
|
| + if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) {
|
| NOTREACHED();
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| @@ -696,13 +624,13 @@ WebDatabase::State WebDataService::UpdateCreditCardImpl(
|
| // It is currently valid to try to update a missing profile. We simply drop
|
| // the write and the caller will detect this on the next refresh.
|
| CreditCard* original_credit_card = NULL;
|
| - if (!db->GetAutofillTable()->GetCreditCard(credit_card.guid(),
|
| + if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(),
|
| &original_credit_card)) {
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| scoped_ptr<CreditCard> scoped_credit_card(original_credit_card);
|
|
|
| - if (!db->GetAutofillTable()->UpdateCreditCard(credit_card)) {
|
| + if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) {
|
| NOTREACHED();
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| @@ -711,7 +639,7 @@ WebDatabase::State WebDataService::UpdateCreditCardImpl(
|
|
|
| WebDatabase::State WebDataService::RemoveCreditCardImpl(
|
| const std::string& guid, WebDatabase* db) {
|
| - if (!db->GetAutofillTable()->RemoveCreditCard(guid)) {
|
| + if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) {
|
| NOTREACHED();
|
| return WebDatabase::COMMIT_NOT_NEEDED;
|
| }
|
| @@ -720,7 +648,7 @@ WebDatabase::State WebDataService::RemoveCreditCardImpl(
|
|
|
| scoped_ptr<WDTypedResult> WebDataService::GetCreditCardsImpl(WebDatabase* db) {
|
| std::vector<CreditCard*> credit_cards;
|
| - db->GetAutofillTable()->GetCreditCards(&credit_cards);
|
| + AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards);
|
| return scoped_ptr<WDTypedResult>(
|
| new WDDestroyableResult<std::vector<CreditCard*> >(
|
| AUTOFILL_CREDITCARDS_RESULT,
|
| @@ -735,7 +663,7 @@ WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl(
|
| WebDatabase* db) {
|
| std::vector<std::string> profile_guids;
|
| std::vector<std::string> credit_card_guids;
|
| - if (db->GetAutofillTable()->
|
| + if (AutofillTable::FromWebDatabase(db)->
|
| RemoveAutofillProfilesAndCreditCardsModifiedBetween(
|
| delete_begin,
|
| delete_end,
|
|
|