Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2075)

Unified Diff: chrome/browser/webdata/web_data_service_factory.cc

Issue 12491017: Make WebDataService no longer depend on ProfileKeyedService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean-up Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..142919f7237ae7a463095b214bb7d312aa8de8ac 100644
--- a/chrome/browser/webdata/web_data_service_factory.cc
+++ b/chrome/browser/webdata/web_data_service_factory.cc
@@ -7,9 +7,27 @@
#include "base/files/file_path.h"
#include "chrome/browser/profiles/profile_dependency_manager.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"
+WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile){
+ base::FilePath path = profile->GetPath();
+ path = path.Append(chrome::kWebDataFilename);
+ web_data_service_ = new WebDataService();
+ web_data_service_->Init(path);
+}
+
+WebDataServiceWrapper::~WebDataServiceWrapper() {
+ web_data_service_ = NULL;
dhollowa 2013/03/18 18:50:59 nit: not needed
Cait (Slow) 2013/03/18 19:10:35 Done.
+}
+
+void WebDataServiceWrapper::Shutdown() {
+ web_data_service_->ShutdownOnUIThread();
dhollowa 2013/03/18 18:50:59 There may be advantage to: web_data_service_ = NUL
Cait (Slow) 2013/03/18 19:10:35 Done.
+}
+
+scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() {
+ return web_data_service_.get();
+}
+
// static
scoped_ptr<AutofillWebDataService> AutofillWebDataService::FromBrowserContext(
content::BrowserContext* context) {
@@ -38,7 +56,7 @@ scoped_refptr<WebDataService> WebDataService::FromBrowserContext(
}
WebDataServiceFactory::WebDataServiceFactory()
- : RefcountedProfileKeyedServiceFactory(
+ : ProfileKeyedServiceFactory(
"WebDataService",
ProfileDependencyManager::GetInstance()) {
// WebDataServiceFactory has no dependecies.
@@ -53,8 +71,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();
+ // |service| can be NULL in Incognito mode.
dhollowa 2013/03/18 18:50:59 |service|? or |wrapper|?
Cait (Slow) 2013/03/18 19:10:35 Done.
+ return NULL;
}
// static
@@ -64,8 +87,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();
+ // |service| can be NULL in Incognito mode.
dhollowa 2013/03/18 18:50:59 ditto
Cait (Slow) 2013/03/18 19:10:35 Done.
+ return NULL;
}
// static
@@ -77,16 +105,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 {

Powered by Google App Engine
This is Rietveld 408576698