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..c687186a78d6514d216cf2515464112790261d25 100644 |
--- a/chrome/browser/webdata/web_data_service_factory.cc |
+++ b/chrome/browser/webdata/web_data_service_factory.cc |
@@ -4,15 +4,68 @@ |
#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/autocomplete_syncable_service.h" |
+#include "chrome/browser/webdata/autofill_profile_syncable_service.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 "content/public/browser/browser_thread.h" |
+#include "grit/chromium_strings.h" |
+#include "grit/generated_resources.h" |
+ |
+using content::BrowserThread; |
+ |
+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); |
+} |
+ |
+void InitSyncableServicesOnDBThread(scoped_refptr<WebDataService> web_data) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
+ |
+ // Currently only Autocomplete and Autofill profiles use the new Sync API, but |
+ // all the database data should migrate to this API over time. |
+ AutocompleteSyncableService::CreateForWebDataService(web_data); |
+ AutofillProfileSyncableService::CreateForWebDataService(web_data); |
+} |
+ |
+} // 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); |
+ |
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
+ base::Bind(&InitSyncableServicesOnDBThread, |
+ web_data_service_)); |
+} |
+ |
+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 +73,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 +91,7 @@ scoped_refptr<WebDataService> WebDataService::FromBrowserContext( |
} |
WebDataServiceFactory::WebDataServiceFactory() |
- : RefcountedProfileKeyedServiceFactory( |
+ : ProfileKeyedServiceFactory( |
"WebDataService", |
ProfileDependencyManager::GetInstance()) { |
// WebDataServiceFactory has no dependecies. |
@@ -53,8 +106,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 +122,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 +140,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 { |