| 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 4d546197f55cae108140c7facb2bb8fa82a8f948..25a6af764bfc92279bf2aabc402b68da37837a6f 100644
|
| --- a/chrome/browser/webdata/web_data_service_factory.cc
|
| +++ b/chrome/browser/webdata/web_data_service_factory.cc
|
| @@ -4,15 +4,50 @@
|
|
|
| #include "chrome/browser/webdata/web_data_service_factory.h"
|
|
|
| +#include "base/bind.h"
|
| #include "base/files/file_path.h"
|
| #include "chrome/browser/profiles/profile_dependency_manager.h"
|
| +#include "chrome/browser/ui/profile_error_dialog.h"
|
| #include "chrome/browser/webdata/autofill_web_data_service_impl.h"
|
| -#include "chrome/browser/webdata/web_data_service.h"
|
| #include "chrome/common/chrome_constants.h"
|
| +#include "grit/chromium_strings.h"
|
| +#include "grit/generated_resources.h"
|
| +
|
| +namespace {
|
| +
|
| +// Callback to show error dialog on profile load error.
|
| +void ProfileErrorCallback(sql::InitStatus status) {
|
| + ShowProfileErrorDialog(
|
| + (status == sql::INIT_FAILURE) ?
|
| + IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +WebDataServiceWrapper::WebDataServiceWrapper() {}
|
| +
|
| +WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) {
|
| + base::FilePath path = profile->GetPath();
|
| + path = path.Append(chrome::kWebDataFilename);
|
| + web_data_service_ = new WebDataService(base::Bind(&ProfileErrorCallback));
|
| + web_data_service_->Init(path);
|
| +}
|
| +
|
| +WebDataServiceWrapper::~WebDataServiceWrapper() {
|
| +}
|
| +
|
| +void WebDataServiceWrapper::Shutdown() {
|
| + web_data_service_->ShutdownOnUIThread();
|
| + web_data_service_ = NULL;
|
| +}
|
| +
|
| +scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() {
|
| + return web_data_service_.get();
|
| +}
|
|
|
| // static
|
| -scoped_ptr<AutofillWebDataService> AutofillWebDataService::FromBrowserContext(
|
| - content::BrowserContext* context) {
|
| +scoped_refptr<AutofillWebDataService>
|
| +AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) {
|
| // For this service, the implicit/explicit distinction doesn't
|
| // really matter; it's just used for a DCHECK. So we currently
|
| // cheat and always say EXPLICIT_ACCESS.
|
| @@ -20,10 +55,10 @@ scoped_ptr<AutofillWebDataService> AutofillWebDataService::FromBrowserContext(
|
| static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS);
|
|
|
| if (service.get()) {
|
| - return scoped_ptr<AutofillWebDataService>(
|
| + return scoped_refptr<AutofillWebDataService>(
|
| new AutofillWebDataServiceImpl(service));
|
| } else {
|
| - return scoped_ptr<AutofillWebDataService>(NULL);
|
| + return scoped_refptr<AutofillWebDataService>(NULL);
|
| }
|
| }
|
|
|
| @@ -38,7 +73,7 @@ scoped_refptr<WebDataService> WebDataService::FromBrowserContext(
|
| }
|
|
|
| WebDataServiceFactory::WebDataServiceFactory()
|
| - : RefcountedProfileKeyedServiceFactory(
|
| + : ProfileKeyedServiceFactory(
|
| "WebDataService",
|
| ProfileDependencyManager::GetInstance()) {
|
| // WebDataServiceFactory has no dependecies.
|
| @@ -53,8 +88,13 @@ scoped_refptr<WebDataService> WebDataServiceFactory::GetForProfile(
|
| // DCHECK, we need to start taking it as a parameter to
|
| // AutofillWebDataServiceImpl::FromBrowserContext (see above).
|
| DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
|
| - return static_cast<WebDataService*>(
|
| - GetInstance()->GetServiceForProfile(profile, true).get());
|
| + WebDataServiceWrapper* wrapper =
|
| + static_cast<WebDataServiceWrapper*>(
|
| + GetInstance()->GetServiceForProfile(profile, true));
|
| + if (wrapper)
|
| + return wrapper->GetWebData();
|
| + // |wrapper| can be NULL in Incognito mode.
|
| + return NULL;
|
| }
|
|
|
| // static
|
| @@ -64,8 +104,13 @@ scoped_refptr<WebDataService> WebDataServiceFactory::GetForProfileIfExists(
|
| // DCHECK, we need to start taking it as a parameter to
|
| // AutofillWebDataServiceImpl::FromBrowserContext (see above).
|
| DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
|
| - return static_cast<WebDataService*>(
|
| - GetInstance()->GetServiceForProfile(profile, false).get());
|
| + WebDataServiceWrapper* wrapper =
|
| + static_cast<WebDataServiceWrapper*>(
|
| + GetInstance()->GetServiceForProfile(profile, true));
|
| + if (wrapper)
|
| + return wrapper->GetWebData();
|
| + // |wrapper| can be NULL in Incognito mode.
|
| + return NULL;
|
| }
|
|
|
| // static
|
| @@ -77,16 +122,9 @@ bool WebDataServiceFactory::ServiceRedirectedInIncognito() const {
|
| return true;
|
| }
|
|
|
| -scoped_refptr<RefcountedProfileKeyedService>
|
| +ProfileKeyedService*
|
| WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const {
|
| - DCHECK(profile);
|
| -
|
| - base::FilePath path = profile->GetPath();
|
| - path = path.Append(chrome::kWebDataFilename);
|
| -
|
| - scoped_refptr<WebDataService> wds(new WebDataService());
|
| - wds->Init(path);
|
| - return wds.get();
|
| + return new WebDataServiceWrapper(profile);
|
| }
|
|
|
| bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const {
|
|
|