| Index: chrome/browser/webdata/web_data_service_factory.cc
|
| diff --git a/chrome/browser/webdata/web_data_service_factory.cc b/chrome/browser/webdata/web_data_service_factory.cc
|
| index 18f9c4054da74202a8987e44289bff424489731b..036350d5dd82bce53f3fd4101997612217a291db 100644
|
| --- a/chrome/browser/webdata/web_data_service_factory.cc
|
| +++ b/chrome/browser/webdata/web_data_service_factory.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/files/file_path.h"
|
| +#include "base/memory/singleton.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/profiles/incognito_helpers.h"
|
| #include "chrome/browser/sync/glue/sync_start_util.h"
|
| @@ -13,39 +14,58 @@
|
| #include "chrome/browser/webdata/autocomplete_syncable_service.h"
|
| #include "chrome/grit/chromium_strings.h"
|
| #include "chrome/grit/generated_resources.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/password_manager/core/browser/webdata/logins_table.h"
|
| -#include "components/search_engines/keyword_table.h"
|
| #include "components/search_engines/keyword_web_data_service.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 "components/webdata_services/web_data_service_wrapper.h"
|
| #include "content/public/browser/browser_thread.h"
|
|
|
| #if defined(OS_WIN)
|
| #include "components/password_manager/core/browser/webdata/password_web_data_service_win.h"
|
| #endif
|
|
|
| -using autofill::AutofillWebDataService;
|
| using autofill::AutofillProfileSyncableService;
|
| using content::BrowserThread;
|
|
|
| namespace {
|
|
|
| +// Converts a WebDataServiceWrapper::ErrorType to ProfileErrorType.
|
| +ProfileErrorType ProfileErrorFromWebDataServiceWrapperError(
|
| + WebDataServiceWrapper::ErrorType error_type) {
|
| + switch (error_type) {
|
| + case WebDataServiceWrapper::ERROR_LOADING_AUTOFILL:
|
| + return PROFILE_ERROR_DB_AUTOFILL_WEB_DATA;
|
| +
|
| + case WebDataServiceWrapper::ERROR_LOADING_KEYWORD:
|
| + return PROFILE_ERROR_DB_KEYWORD_WEB_DATA;
|
| +
|
| + case WebDataServiceWrapper::ERROR_LOADING_TOKEN:
|
| + return PROFILE_ERROR_DB_TOKEN_WEB_DATA;
|
| +
|
| + case WebDataServiceWrapper::ERROR_LOADING_PASSWORD:
|
| + return PROFILE_ERROR_DB_WEB_DATA;
|
| +
|
| + default:
|
| + NOTREACHED()
|
| + << "Unknown WebDataServiceWrapper::ErrorType: " << error_type;
|
| + return PROFILE_ERROR_DB_WEB_DATA;
|
| + }
|
| +}
|
| +
|
| // Callback to show error dialog on profile load error.
|
| -void ProfileErrorCallback(ProfileErrorType type, sql::InitStatus status) {
|
| +void ProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type,
|
| + sql::InitStatus status) {
|
| ShowProfileErrorDialog(
|
| - type,
|
| + ProfileErrorFromWebDataServiceWrapperError(error_type),
|
| (status == sql::INIT_FAILURE) ?
|
| IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
|
| }
|
|
|
| +} // namespace
|
| +
|
| void InitSyncableServicesOnDBThread(
|
| - scoped_refptr<AutofillWebDataService> autofill_web_data,
|
| + scoped_refptr<autofill::AutofillWebDataService> autofill_web_data,
|
| const base::FilePath& profile_path,
|
| const std::string& app_locale,
|
| autofill::AutofillWebDataBackend* autofill_backend) {
|
| @@ -65,105 +85,6 @@ void InitSyncableServicesOnDBThread(
|
| sync_start_util::GetFlareForSyncableService(profile_path));
|
| }
|
|
|
| -} // namespace
|
| -
|
| -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);
|
| -
|
| - // All tables objects that participate in managing the database must
|
| - // be added here.
|
| - web_database_->AddTable(scoped_ptr<WebDatabaseTable>(
|
| - new autofill::AutofillTable(g_browser_process->GetApplicationLocale())));
|
| - web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new KeywordTable()));
|
| - // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password
|
| - // access, but for now, we still create it on all platforms since it deletes
|
| - // the old logins table. We can remove this after a while, e.g. in M22 or so.
|
| - web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new LoginsTable()));
|
| - web_database_->AddTable(
|
| - scoped_ptr<WebDatabaseTable>(new TokenServiceTable()));
|
| -
|
| - 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();
|
| -
|
| - keyword_web_data_ = new KeywordWebDataService(
|
| - web_database_,
|
| - ui_thread,
|
| - base::Bind(&ProfileErrorCallback, PROFILE_ERROR_DB_KEYWORD_WEB_DATA));
|
| - keyword_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();
|
| -
|
| -#if defined(OS_WIN)
|
| - password_web_data_ = new PasswordWebDataService(
|
| - web_database_,
|
| - ui_thread,
|
| - base::Bind(&ProfileErrorCallback, PROFILE_ERROR_DB_WEB_DATA));
|
| - password_web_data_->Init();
|
| -#endif
|
| -
|
| - 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();
|
| - keyword_web_data_->ShutdownOnUIThread();
|
| - token_web_data_->ShutdownOnUIThread();
|
| -
|
| -#if defined(OS_WIN)
|
| - password_web_data_->ShutdownOnUIThread();
|
| -#endif
|
| - web_database_->ShutdownDatabase();
|
| -}
|
| -
|
| -scoped_refptr<AutofillWebDataService>
|
| -WebDataServiceWrapper::GetAutofillWebData() {
|
| - return autofill_web_data_.get();
|
| -}
|
| -
|
| -scoped_refptr<KeywordWebDataService>
|
| -WebDataServiceWrapper::GetKeywordWebData() {
|
| - return keyword_web_data_.get();
|
| -}
|
| -
|
| -scoped_refptr<TokenWebData> WebDataServiceWrapper::GetTokenWebData() {
|
| - return token_web_data_.get();
|
| -}
|
| -
|
| -#if defined(OS_WIN)
|
| -scoped_refptr<PasswordWebDataService>
|
| -WebDataServiceWrapper::GetPasswordWebData() {
|
| - return password_web_data_.get();
|
| -}
|
| -#endif
|
| -
|
| WebDataServiceFactory::WebDataServiceFactory()
|
| : BrowserContextKeyedServiceFactory(
|
| "WebDataService",
|
| @@ -199,16 +120,16 @@ WebDataServiceWrapper* WebDataServiceFactory::GetForProfileIfExists(
|
| }
|
|
|
| // static
|
| -scoped_refptr<AutofillWebDataService>
|
| +scoped_refptr<autofill::AutofillWebDataService>
|
| WebDataServiceFactory::GetAutofillWebDataForProfile(
|
| Profile* profile,
|
| Profile::ServiceAccessType access_type) {
|
| WebDataServiceWrapper* wrapper =
|
| WebDataServiceFactory::GetForProfile(profile, access_type);
|
| - // |wrapper| can be NULL in Incognito mode.
|
| + // |wrapper| can be null in Incognito mode.
|
| return wrapper ?
|
| wrapper->GetAutofillWebData() :
|
| - scoped_refptr<AutofillWebDataService>(NULL);
|
| + scoped_refptr<autofill::AutofillWebDataService>(nullptr);
|
| }
|
|
|
| // static
|
| @@ -218,9 +139,10 @@ WebDataServiceFactory::GetKeywordWebDataForProfile(
|
| Profile::ServiceAccessType access_type) {
|
| WebDataServiceWrapper* wrapper =
|
| WebDataServiceFactory::GetForProfile(profile, access_type);
|
| - // |wrapper| can be NULL in Incognito mode.
|
| + // |wrapper| can be null in Incognito mode.
|
| return wrapper ?
|
| - wrapper->GetKeywordWebData() : scoped_refptr<KeywordWebDataService>(NULL);
|
| + wrapper->GetKeywordWebData() :
|
| + scoped_refptr<KeywordWebDataService>(nullptr);
|
| }
|
|
|
| // static
|
| @@ -229,9 +151,9 @@ scoped_refptr<TokenWebData> WebDataServiceFactory::GetTokenWebDataForProfile(
|
| Profile::ServiceAccessType access_type) {
|
| WebDataServiceWrapper* wrapper =
|
| WebDataServiceFactory::GetForProfile(profile, access_type);
|
| - // |wrapper| can be NULL in Incognito mode.
|
| + // |wrapper| can be null in Incognito mode.
|
| return wrapper ?
|
| - wrapper->GetTokenWebData() : scoped_refptr<TokenWebData>(NULL);
|
| + wrapper->GetTokenWebData() : scoped_refptr<TokenWebData>(nullptr);
|
| }
|
|
|
| #if defined(OS_WIN)
|
| @@ -242,10 +164,10 @@ WebDataServiceFactory::GetPasswordWebDataForProfile(
|
| Profile::ServiceAccessType access_type) {
|
| WebDataServiceWrapper* wrapper =
|
| WebDataServiceFactory::GetForProfile(profile, access_type);
|
| - // |wrapper| can be NULL in Incognito mode.
|
| + // |wrapper| can be null in Incognito mode.
|
| return wrapper ?
|
| wrapper->GetPasswordWebData() :
|
| - scoped_refptr<PasswordWebDataService>(NULL);
|
| + scoped_refptr<PasswordWebDataService>(nullptr);
|
| }
|
| #endif
|
|
|
| @@ -261,7 +183,18 @@ content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse(
|
|
|
| KeyedService* WebDataServiceFactory::BuildServiceInstanceFor(
|
| content::BrowserContext* profile) const {
|
| - return new WebDataServiceWrapper(static_cast<Profile*>(profile));
|
| + WebDataServiceWrapper* web_data_service_wrapper = new WebDataServiceWrapper(
|
| + static_cast<Profile*>(profile)->GetPath(),
|
| + g_browser_process->GetApplicationLocale(),
|
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
|
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
|
| + &ProfileErrorCallback);
|
| + web_data_service_wrapper->GetAutofillWebData()->GetAutofillBackend(
|
| + base::Bind(&InitSyncableServicesOnDBThread,
|
| + web_data_service_wrapper->GetAutofillWebData(),
|
| + static_cast<Profile*>(profile)->GetPath(),
|
| + g_browser_process->GetApplicationLocale()));
|
| + return web_data_service_wrapper;
|
| }
|
|
|
| bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const {
|
|
|