This source file includes following definitions.
- ProfileErrorCallback
- InitSyncableServicesOnDBThread
- Shutdown
- GetAutofillWebData
- GetWebData
- GetTokenWebData
- FromBrowserContext
- GetForProfile
- GetForProfileIfExists
- GetAutofillWebDataForProfile
- GetTokenWebDataForProfile
- GetInstance
- GetBrowserContextToUse
- BuildServiceInstanceFor
- ServiceIsNULLWhileTesting
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "base/bind.h"
#include "base/files/file_path.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/sync/glue/sync_start_util.h"
#include "chrome/browser/ui/profile_error_dialog.h"
#include "chrome/browser/webdata/autocomplete_syncable_service.h"
#include "chrome/browser/webdata/keyword_table.h"
#include "chrome/browser/webdata/logins_table.h"
#include "chrome/browser/webdata/web_apps_table.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/browser/webdata/web_intents_table.h"
#include "components/autofill/core/browser/autofill_country.h"
#include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/signin/core/browser/webdata/token_service_table.h"
#include "components/signin/core/browser/webdata/token_web_data.h"
#include "components/webdata/common/webdata_constants.h"
#include "content/public/browser/browser_thread.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
using autofill::AutofillWebDataService;
using autofill::AutofillProfileSyncableService;
using content::BrowserThread;
namespace {
void ProfileErrorCallback(ProfileErrorType type, sql::InitStatus status) {
ShowProfileErrorDialog(
type,
(status == sql::INIT_FAILURE) ?
IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
}
void InitSyncableServicesOnDBThread(
scoped_refptr<AutofillWebDataService> autofill_web_data,
const base::FilePath& profile_path,
const std::string& app_locale,
autofill::AutofillWebDataBackend* autofill_backend) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
AutocompleteSyncableService::CreateForWebDataServiceAndBackend(
autofill_web_data.get(), autofill_backend);
AutocompleteSyncableService::FromWebDataService(autofill_web_data.get())
->InjectStartSyncFlare(
sync_start_util::GetFlareForSyncableService(profile_path));
AutofillProfileSyncableService::CreateForWebDataServiceAndBackend(
autofill_web_data.get(), autofill_backend, app_locale);
AutofillProfileSyncableService::FromWebDataService(autofill_web_data.get())
->InjectStartSyncFlare(
sync_start_util::GetFlareForSyncableService(profile_path));
}
}
WebDataServiceWrapper::WebDataServiceWrapper() {}
WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) {
base::FilePath profile_path = profile->GetPath();
base::FilePath path = profile_path.Append(kWebDataFilename);
scoped_refptr<base::MessageLoopProxy> ui_thread =
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
scoped_refptr<base::MessageLoopProxy> db_thread =
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB);
web_database_ = new WebDatabaseService(path, ui_thread, db_thread);
web_database_->AddTable(
scoped_ptr<WebDatabaseTable>(new autofill::AutofillTable(
g_browser_process->GetApplicationLocale())));
web_database_->AddTable(
scoped_ptr<WebDatabaseTable>(new KeywordTable()));
web_database_->AddTable(
scoped_ptr<WebDatabaseTable>(new LoginsTable()));
web_database_->AddTable(
scoped_ptr<WebDatabaseTable>(new TokenServiceTable()));
web_database_->AddTable(
scoped_ptr<WebDatabaseTable>(new WebAppsTable()));
web_database_->AddTable(
scoped_ptr<WebDatabaseTable>(new WebIntentsTable()));
web_database_->LoadDatabase();
autofill_web_data_ = new AutofillWebDataService(
web_database_, ui_thread, db_thread, base::Bind(
&ProfileErrorCallback, PROFILE_ERROR_DB_AUTOFILL_WEB_DATA));
autofill_web_data_->Init();
token_web_data_ = new TokenWebData(
web_database_, ui_thread, db_thread, base::Bind(
&ProfileErrorCallback, PROFILE_ERROR_DB_TOKEN_WEB_DATA));
token_web_data_->Init();
web_data_ = new WebDataService(
web_database_, base::Bind(&ProfileErrorCallback,
PROFILE_ERROR_DB_WEB_DATA));
web_data_->Init();
autofill_web_data_->GetAutofillBackend(
base::Bind(&InitSyncableServicesOnDBThread,
autofill_web_data_,
profile_path,
g_browser_process->GetApplicationLocale()));
}
WebDataServiceWrapper::~WebDataServiceWrapper() {
}
void WebDataServiceWrapper::Shutdown() {
autofill_web_data_->ShutdownOnUIThread();
token_web_data_->ShutdownOnUIThread();
web_data_->ShutdownOnUIThread();
web_database_->ShutdownDatabase();
}
scoped_refptr<AutofillWebDataService>
WebDataServiceWrapper::GetAutofillWebData() {
return autofill_web_data_.get();
}
scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() {
return web_data_.get();
}
scoped_refptr<TokenWebData> WebDataServiceWrapper::GetTokenWebData() {
return token_web_data_.get();
}
scoped_refptr<WebDataService> WebDataService::FromBrowserContext(
content::BrowserContext* context) {
WebDataServiceWrapper* wrapper =
WebDataServiceFactory::GetForProfile(
static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS);
if (wrapper)
return wrapper->GetWebData();
return scoped_refptr<WebDataService>(NULL);
}
WebDataServiceFactory::WebDataServiceFactory()
: BrowserContextKeyedServiceFactory(
"WebDataService",
BrowserContextDependencyManager::GetInstance()) {
}
WebDataServiceFactory::~WebDataServiceFactory() {}
WebDataServiceWrapper* WebDataServiceFactory::GetForProfile(
Profile* profile,
Profile::ServiceAccessType access_type) {
DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
return static_cast<WebDataServiceWrapper*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
WebDataServiceWrapper* WebDataServiceFactory::GetForProfileIfExists(
Profile* profile,
Profile::ServiceAccessType access_type) {
DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
return static_cast<WebDataServiceWrapper*>(
GetInstance()->GetServiceForBrowserContext(profile, false));
}
scoped_refptr<AutofillWebDataService>
WebDataServiceFactory::GetAutofillWebDataForProfile(
Profile* profile,
Profile::ServiceAccessType access_type) {
WebDataServiceWrapper* wrapper =
WebDataServiceFactory::GetForProfile(profile, access_type);
return wrapper ?
wrapper->GetAutofillWebData() :
scoped_refptr<AutofillWebDataService>(NULL);
}
scoped_refptr<TokenWebData>
WebDataServiceFactory::GetTokenWebDataForProfile(
Profile* profile,
Profile::ServiceAccessType access_type) {
WebDataServiceWrapper* wrapper =
WebDataServiceFactory::GetForProfile(profile, access_type);
return wrapper ? wrapper->GetTokenWebData()
: scoped_refptr<TokenWebData>(NULL);
}
WebDataServiceFactory* WebDataServiceFactory::GetInstance() {
return Singleton<WebDataServiceFactory>::get();
}
content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
KeyedService* WebDataServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const {
return new WebDataServiceWrapper(static_cast<Profile*>(profile));
}
bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const {
return true;
}