summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsdefresne <sdefresne@chromium.org>2014-12-15 15:21:56 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-15 23:22:23 +0000
commitcb955cd06650ee281f745b5a86aff7864fe44066 (patch)
treed663541ca9f25582d5de09be3844285467d404dd
parent81c98ba5f74cbe9e6f1a12a0b96371b65dd4374e (diff)
downloadchromium_src-cb955cd06650ee281f745b5a86aff7864fe44066.zip
chromium_src-cb955cd06650ee281f745b5a86aff7864fe44066.tar.gz
chromium_src-cb955cd06650ee281f745b5a86aff7864fe44066.tar.bz2
Introduce new component webdata_services
Move WebDataServiceWrapper into its own component webdata_services so that the code can be shared with iOS. The code cannot go into webdata component since it depends on other components (autofill, password_manager, search_engine, signin) that depends on webdata (as they implements the WebDataService interface). BUG=437508 Review URL: https://codereview.chromium.org/777863002 Cr-Commit-Position: refs/heads/master@{#308451}
-rw-r--r--chrome/browser/BUILD.gn1
-rw-r--r--chrome/browser/DEPS1
-rw-r--r--chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc2
-rw-r--r--chrome/browser/sync/profile_sync_service_autofill_unittest.cc2
-rw-r--r--chrome/browser/webdata/web_data_service_factory.cc173
-rw-r--r--chrome/browser/webdata/web_data_service_factory.h49
-rw-r--r--chrome/chrome_browser.gypi1
-rw-r--r--chrome/chrome_tests_unit.gypi4
-rw-r--r--chrome/test/base/testing_profile.cc108
-rw-r--r--components/OWNERS3
-rw-r--r--components/autofill/core/browser/DEPS1
-rw-r--r--components/autofill/core/browser/autocomplete_history_manager_unittest.cc2
-rw-r--r--components/components.gyp1
-rw-r--r--components/webdata/DEPS8
-rw-r--r--components/webdata_services.gypi48
-rw-r--r--components/webdata_services/BUILD.gn38
-rw-r--r--components/webdata_services/DEPS10
-rw-r--r--components/webdata_services/OWNERS4
-rw-r--r--components/webdata_services/web_data_service_test_util.cc (renamed from components/webdata/common/web_data_service_test_util.cc)7
-rw-r--r--components/webdata_services/web_data_service_test_util.h (renamed from components/webdata/common/web_data_service_test_util.h)8
-rw-r--r--components/webdata_services/web_data_service_wrapper.cc107
-rw-r--r--components/webdata_services/web_data_service_wrapper.h85
22 files changed, 438 insertions, 225 deletions
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 50f6b85..6cc56a2 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -118,6 +118,7 @@ static_library("browser") {
"//components/variations",
"//components/variations/net",
"//components/webdata/common",
+ "//components/webdata_services",
"//components/web_resource",
"//content/public/browser",
"//content/public/common",
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS
index e8b71cf..c577666 100644
--- a/chrome/browser/DEPS
+++ b/chrome/browser/DEPS
@@ -83,6 +83,7 @@ include_rules = [
"+components/web_modal",
"+components/web_cache/browser",
"+components/webdata/common",
+ "+components/webdata_services",
"+components/web_resource",
"+content/public/browser",
"+content/test/net",
diff --git a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
index ada1476..7547fc8 100644
--- a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
+++ b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
@@ -17,7 +17,7 @@
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/sync_driver/data_type_controller_mock.h"
-#include "components/webdata/common/web_data_service_test_util.h"
+#include "components/webdata_services/web_data_service_test_util.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
index 4f4e9ba..ca92593 100644
--- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
@@ -49,8 +49,8 @@
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/sync_driver/data_type_controller.h"
-#include "components/webdata/common/web_data_service_test_util.h"
#include "components/webdata/common/web_database.h"
+#include "components/webdata_services/web_data_service_test_util.h"
#include "content/public/test/test_browser_thread.h"
#include "google_apis/gaia/gaia_constants.h"
#include "sync/internal_api/public/base/model_type.h"
diff --git a/chrome/browser/webdata/web_data_service_factory.cc b/chrome/browser/webdata/web_data_service_factory.cc
index 18f9c40..036350d 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 {
diff --git a/chrome/browser/webdata/web_data_service_factory.h b/chrome/browser/webdata/web_data_service_factory.h
index fd6d975..9dfefcb 100644
--- a/chrome/browser/webdata/web_data_service_factory.h
+++ b/chrome/browser/webdata/web_data_service_factory.h
@@ -7,59 +7,30 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
-#include "base/memory/singleton.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
-#include "components/keyed_service/core/keyed_service.h"
-#include "components/webdata/common/web_database_service.h"
+template <typename T> struct DefaultSingletonTraits;
class KeywordWebDataService;
class TokenWebData;
+class WebDataServiceWrapper;
#if defined(OS_WIN)
class PasswordWebDataService;
#endif
namespace autofill {
+class AutofillWebDataBackend;
class AutofillWebDataService;
} // namespace autofill
-// A wrapper of WebDataService so that we can use it as a profile keyed service.
-class WebDataServiceWrapper : public KeyedService {
- public:
- explicit WebDataServiceWrapper(Profile* profile);
-
- // For testing.
- WebDataServiceWrapper();
-
- ~WebDataServiceWrapper() override;
-
- // KeyedService:
- void Shutdown() override;
-
- virtual scoped_refptr<autofill::AutofillWebDataService> GetAutofillWebData();
-
- virtual scoped_refptr<KeywordWebDataService> GetKeywordWebData();
-
- virtual scoped_refptr<TokenWebData> GetTokenWebData();
-
-#if defined(OS_WIN)
- virtual scoped_refptr<PasswordWebDataService> GetPasswordWebData();
-#endif
-
- private:
- scoped_refptr<WebDatabaseService> web_database_;
-
- scoped_refptr<autofill::AutofillWebDataService> autofill_web_data_;
- scoped_refptr<KeywordWebDataService> keyword_web_data_;
- scoped_refptr<TokenWebData> token_web_data_;
-
-#if defined(OS_WIN)
- scoped_refptr<PasswordWebDataService> password_web_data_;
-#endif
-
- DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper);
-};
+// Initialize syncable services on database thread.
+// (visible for testing)
+void InitSyncableServicesOnDBThread(
+ scoped_refptr<autofill::AutofillWebDataService> autofill_web_data,
+ const base::FilePath& profile_path,
+ const std::string& app_locale,
+ autofill::AutofillWebDataBackend* autofill_backend);
// Singleton that owns all WebDataServiceWrappers and associates them with
// Profiles.
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 95e1c0f..1f21ddf 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2941,6 +2941,7 @@
'../components/components.gyp:variations',
'../components/components.gyp:variations_http_provider',
'../components/components.gyp:webdata_common',
+ '../components/components.gyp:webdata_services',
'../content/content.gyp:content_browser',
'../content/content.gyp:content_common',
'../courgette/courgette.gyp:courgette_lib',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index d697b15..6acebf8 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1421,9 +1421,6 @@
'../components/search_engines/template_url_service_sync_unittest.cc',
'../components/search_engines/template_url_service_unittest.cc',
- '../components/webdata/common/web_data_service_test_util.cc',
- '../components/webdata/common/web_data_service_test_util.h',
-
'../skia/ext/analysis_canvas_unittest.cc',
'../skia/ext/bitmap_platform_device_mac_unittest.cc',
'../skia/ext/convolver_unittest.cc',
@@ -1988,6 +1985,7 @@
'../components/components.gyp:autofill_content_test_support',
'../components/components.gyp:component_metrics_proto',
'../components/components.gyp:data_reduction_proxy_test_support',
+ '../components/components.gyp:webdata_services_test_support',
'../components/components_strings.gyp:components_strings',
'../content/app/resources/content_resources.gyp:content_resources',
'../gpu/gpu.gyp:gpu_unittest_utils',
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index f565f58..a8334c0 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -49,6 +49,7 @@
#include "chrome/common/url_constants.h"
#include "chrome/test/base/history_index_restore_observer.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
+#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/common/bookmark_constants.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
@@ -57,6 +58,7 @@
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/policy/core/common/policy_service.h"
#include "components/user_prefs/user_prefs.h"
+#include "components/webdata_services/web_data_service_wrapper.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/cookie_store_factory.h"
#include "content/public/browser/notification_service.h"
@@ -184,6 +186,67 @@ KeyedService* CreateTestDesktopNotificationService(
}
#endif
+KeyedService* BuildFaviconService(content::BrowserContext* profile) {
+ FaviconClient* favicon_client =
+ ChromeFaviconClientFactory::GetForProfile(static_cast<Profile*>(profile));
+ return new FaviconService(static_cast<Profile*>(profile), favicon_client);
+}
+
+KeyedService* BuildHistoryService(content::BrowserContext* context) {
+ Profile* profile = static_cast<Profile*>(context);
+ HistoryService* history_service = new HistoryService(
+ ChromeHistoryClientFactory::GetForProfile(profile), profile);
+ return history_service;
+}
+
+KeyedService* BuildBookmarkModel(content::BrowserContext* context) {
+ Profile* profile = static_cast<Profile*>(context);
+ ChromeBookmarkClient* bookmark_client =
+ ChromeBookmarkClientFactory::GetForProfile(profile);
+ BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client);
+ bookmark_client->Init(bookmark_model);
+ bookmark_model->Load(profile->GetPrefs(),
+ profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
+ profile->GetPath(),
+ profile->GetIOTaskRunner(),
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::UI));
+ return bookmark_model;
+}
+
+KeyedService* BuildChromeBookmarkClient(
+ content::BrowserContext* context) {
+ return new ChromeBookmarkClient(static_cast<Profile*>(context));
+}
+
+KeyedService* BuildChromeHistoryClient(
+ content::BrowserContext* context) {
+ Profile* profile = static_cast<Profile*>(context);
+ return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile),
+ profile,
+ profile->GetTopSites());
+}
+
+void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type,
+ sql::InitStatus status) {
+ NOTREACHED();
+}
+
+KeyedService* BuildWebDataService(content::BrowserContext* 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),
+ &TestProfileErrorCallback);
+ 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;
+}
+
} // namespace
// static
@@ -453,25 +516,12 @@ TestingProfile::~TestingProfile() {
}
}
-static KeyedService* BuildFaviconService(content::BrowserContext* profile) {
- FaviconClient* favicon_client =
- ChromeFaviconClientFactory::GetForProfile(static_cast<Profile*>(profile));
- return new FaviconService(static_cast<Profile*>(profile), favicon_client);
-}
-
void TestingProfile::CreateFaviconService() {
// It is up to the caller to create the history service if one is needed.
FaviconServiceFactory::GetInstance()->SetTestingFactory(
this, BuildFaviconService);
}
-static KeyedService* BuildHistoryService(content::BrowserContext* context) {
- Profile* profile = static_cast<Profile*>(context);
- HistoryService* history_service = new HistoryService(
- ChromeHistoryClientFactory::GetForProfile(profile), profile);
- return history_service;
-}
-
bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
DestroyHistoryService();
if (delete_file) {
@@ -546,34 +596,6 @@ void TestingProfile::DestroyTopSites() {
}
}
-static KeyedService* BuildBookmarkModel(content::BrowserContext* context) {
- Profile* profile = static_cast<Profile*>(context);
- ChromeBookmarkClient* bookmark_client =
- ChromeBookmarkClientFactory::GetForProfile(profile);
- BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client);
- bookmark_client->Init(bookmark_model);
- bookmark_model->Load(profile->GetPrefs(),
- profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
- profile->GetPath(),
- profile->GetIOTaskRunner(),
- content::BrowserThread::GetMessageLoopProxyForThread(
- content::BrowserThread::UI));
- return bookmark_model;
-}
-
-static KeyedService* BuildChromeBookmarkClient(
- content::BrowserContext* context) {
- return new ChromeBookmarkClient(static_cast<Profile*>(context));
-}
-
-static KeyedService* BuildChromeHistoryClient(
- content::BrowserContext* context) {
- Profile* profile = static_cast<Profile*>(context);
- return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile),
- profile,
- profile->GetTopSites());
-}
-
void TestingProfile::CreateBookmarkModel(bool delete_file) {
if (delete_file) {
base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName);
@@ -588,10 +610,6 @@ void TestingProfile::CreateBookmarkModel(bool delete_file) {
this, BuildBookmarkModel));
}
-static KeyedService* BuildWebDataService(content::BrowserContext* profile) {
- return new WebDataServiceWrapper(static_cast<Profile*>(profile));
-}
-
void TestingProfile::CreateWebDataService() {
WebDataServiceFactory::GetInstance()->SetTestingFactory(
this, BuildWebDataService);
diff --git a/components/OWNERS b/components/OWNERS
index ee2e2dc..4de6407 100644
--- a/components/OWNERS
+++ b/components/OWNERS
@@ -246,6 +246,9 @@ per-file variations.gypi=asvitkine@chromium.org
per-file variations.gypi=jwd@chromium.org
per-file variations.gypi=stevet@chromium.org
+per-file webdata.gypi=pkasting@chromium.org
+per-file webdata_services.gypi=pkasting@chromium.org
+
per-file web_resource.gypi=asvitkine@chromium.org
per-file web_resource.gypi=stevet@chromium.org
diff --git a/components/autofill/core/browser/DEPS b/components/autofill/core/browser/DEPS
index 75cde3a..0348d37 100644
--- a/components/autofill/core/browser/DEPS
+++ b/components/autofill/core/browser/DEPS
@@ -1,6 +1,7 @@
include_rules = [
"+components/keyed_service/core",
"+components/webdata/common",
+ "+components/webdata_services",
"+crypto/random.h",
"+google_apis/gaia",
"+google_apis/google_api_keys.h",
diff --git a/components/autofill/core/browser/autocomplete_history_manager_unittest.cc b/components/autofill/core/browser/autocomplete_history_manager_unittest.cc
index af42bef..d5273bd 100644
--- a/components/autofill/core/browser/autocomplete_history_manager_unittest.cc
+++ b/components/autofill/core/browser/autocomplete_history_manager_unittest.cc
@@ -19,7 +19,7 @@
#include "components/autofill/core/browser/test_autofill_driver.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/form_data.h"
-#include "components/webdata/common/web_data_service_test_util.h"
+#include "components/webdata_services/web_data_service_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/rect.h"
diff --git a/components/components.gyp b/components/components.gyp
index 6abd9ab..91b5fc6 100644
--- a/components/components.gyp
+++ b/components/components.gyp
@@ -130,6 +130,7 @@
'search_engines.gypi',
'sync_driver.gypi',
'invalidation.gypi',
+ 'webdata_services.gypi',
],
}],
['enable_plugins==1', {
diff --git a/components/webdata/DEPS b/components/webdata/DEPS
index d443cb4..d5cca70 100644
--- a/components/webdata/DEPS
+++ b/components/webdata/DEPS
@@ -7,15 +7,9 @@ specific_include_rules = {
# TODO(caitkp): Extract unit tests from //chrome, at lower priority
# than production code.
r'(.*_unittest|.*_test_util)\.(cc|h)': [
- "+chrome/browser/webdata/logins_table.h",
- "+chrome/browser/webdata/token_service_table.h",
- "+chrome/browser/webdata/token_web_data.h",
- "+chrome/browser/webdata/web_data_service.h",
- "+chrome/browser/webdata/web_data_service_factory.h",
- "+components/autofill/core",
+ "+components/autofill/core/browser",
"+components/password_manager/core/browser/webdata",
"+components/search_engines/keyword_table.h",
"+components/signin/core/browser/webdata",
- "+content/public/test",
],
}
diff --git a/components/webdata_services.gypi b/components/webdata_services.gypi
new file mode 100644
index 0000000..c28267b
--- /dev/null
+++ b/components/webdata_services.gypi
@@ -0,0 +1,48 @@
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'targets': [
+ {
+ # GN version: //components/webdata_services
+ 'target_name': 'webdata_services',
+ 'type': 'static_library',
+ 'include_dirs': [
+ '..',
+ ],
+ 'dependencies': [
+ '../base/base.gyp:base',
+ '../sql/sql.gyp:sql',
+ 'autofill_core_browser',
+ 'keyed_service_core',
+ 'password_manager_core_browser',
+ 'search_engines',
+ 'signin_core_browser',
+ 'webdata_common',
+ ],
+ 'sources': [
+ 'webdata_services/web_data_service_wrapper.cc',
+ 'webdata_services/web_data_service_wrapper.h',
+ ],
+ },
+ {
+ # GN version: //components/webdata_services:test_support
+ 'target_name': 'webdata_services_test_support',
+ 'type': 'static_library',
+ 'include_dirs': [
+ '..',
+ ],
+ 'dependencies': [
+ '../base/base.gyp:base',
+ 'autofill_core_browser',
+ 'signin_core_browser',
+ 'webdata_services',
+ ],
+ 'sources': [
+ 'webdata_services/web_data_service_test_util.cc',
+ 'webdata_services/web_data_service_test_util.h',
+ ],
+ },
+ ],
+}
diff --git a/components/webdata_services/BUILD.gn b/components/webdata_services/BUILD.gn
new file mode 100644
index 0000000..8e83363
--- /dev/null
+++ b/components/webdata_services/BUILD.gn
@@ -0,0 +1,38 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+static_library("webdata_services") {
+ output_name = "webdata_services"
+
+ sources = [
+ "web_data_service_wrapper.cc",
+ "web_data_service_wrapper.h",
+ ]
+
+ deps = [
+ "//base",
+ "//components/autofill/core/browser",
+ "//components/keyed_service/core",
+ "//components/password_manager/core/browser",
+ "//components/search_engines",
+ "//components/signin/core/browser",
+ "//components/webdata/common",
+ "//sql",
+ ]
+}
+
+source_set("test_support") {
+ testonly = true
+ sources = [
+ "web_data_service_test_util.cc",
+ "web_data_service_test_util.h",
+ ]
+
+ deps = [
+ ":webdata_services",
+ "//base",
+ "//components/autofill/core/browser",
+ "//components/signin/core/browser",
+ ]
+}
diff --git a/components/webdata_services/DEPS b/components/webdata_services/DEPS
new file mode 100644
index 0000000..2fa1e61
--- /dev/null
+++ b/components/webdata_services/DEPS
@@ -0,0 +1,10 @@
+include_rules = [
+ "+components/autofill/core/browser/webdata",
+ "+components/keyed_service/core",
+ "+components/password_manager/core/browser/webdata",
+ "+components/search_engines/keyword_table.h",
+ "+components/search_engines/keyword_web_data_service.h",
+ "+components/signin/core/browser/webdata",
+ "+components/webdata/common",
+ "+sql",
+]
diff --git a/components/webdata_services/OWNERS b/components/webdata_services/OWNERS
new file mode 100644
index 0000000..dbe16c9
--- /dev/null
+++ b/components/webdata_services/OWNERS
@@ -0,0 +1,4 @@
+pkasting@chromium.org
+
+# For sqlite stuff:
+shess@chromium.org
diff --git a/components/webdata/common/web_data_service_test_util.cc b/components/webdata_services/web_data_service_test_util.cc
index 0d91cdf..e013f32 100644
--- a/components/webdata/common/web_data_service_test_util.cc
+++ b/components/webdata_services/web_data_service_test_util.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/webdata/common/web_data_service_test_util.h"
+#include "components/webdata_services/web_data_service_test_util.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
@@ -23,15 +23,14 @@ void MockWebDataServiceWrapperBase::Shutdown() {
MockWebDataServiceWrapper::MockWebDataServiceWrapper(
scoped_refptr<AutofillWebDataService> fake_autofill,
scoped_refptr<TokenWebData> fake_token)
- : fake_autofill_web_data_(fake_autofill),
- fake_token_web_data_(fake_token) {
+ : fake_autofill_web_data_(fake_autofill), fake_token_web_data_(fake_token) {
}
MockWebDataServiceWrapper::~MockWebDataServiceWrapper() {
}
scoped_refptr<AutofillWebDataService>
- MockWebDataServiceWrapper::GetAutofillWebData() {
+MockWebDataServiceWrapper::GetAutofillWebData() {
return fake_autofill_web_data_;
}
diff --git a/components/webdata/common/web_data_service_test_util.h b/components/webdata_services/web_data_service_test_util.h
index 7368356..4c260a1 100644
--- a/components/webdata/common/web_data_service_test_util.h
+++ b/components/webdata_services/web_data_service_test_util.h
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__
-#define COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__
+#ifndef COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_TEST_UTIL_H__
+#define COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_TEST_UTIL_H__
#include "base/basictypes.h"
#include "base/message_loop/message_loop.h"
-#include "chrome/browser/webdata/web_data_service_factory.h"
#include "components/signin/core/browser/webdata/token_web_data.h"
+#include "components/webdata_services/web_data_service_wrapper.h"
// Base class for mocks of WebDataService, that does nothing in
// Shutdown().
@@ -45,4 +45,4 @@ class MockWebDataServiceWrapper : public MockWebDataServiceWrapperBase {
DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapper);
};
-#endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_TEST_UTIL_H__
+#endif // COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_TEST_UTIL_H__
diff --git a/components/webdata_services/web_data_service_wrapper.cc b/components/webdata_services/web_data_service_wrapper.cc
new file mode 100644
index 0000000..ca4287e
--- /dev/null
+++ b/components/webdata_services/web_data_service_wrapper.cc
@@ -0,0 +1,107 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/webdata_services/web_data_service_wrapper.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/files/file_path.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "components/autofill/core/browser/webdata/autofill_table.h"
+#include "components/autofill/core/browser/webdata/autofill_webdata_service.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/web_database_service.h"
+#include "components/webdata/common/webdata_constants.h"
+
+#if defined(OS_WIN)
+#include "components/password_manager/core/browser/webdata/password_web_data_service_win.h"
+#endif
+
+WebDataServiceWrapper::WebDataServiceWrapper() {
+}
+
+WebDataServiceWrapper::WebDataServiceWrapper(
+ const base::FilePath& profile_path,
+ const std::string& application_locale,
+ const scoped_refptr<base::MessageLoopProxy>& ui_thread,
+ const scoped_refptr<base::MessageLoopProxy>& db_thread,
+ ShowErrorCallback show_error_callback) {
+ base::FilePath path = profile_path.Append(kWebDataFilename);
+ 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(application_locale)));
+ 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 autofill::AutofillWebDataService(
+ web_database_, ui_thread, db_thread,
+ base::Bind(show_error_callback, ERROR_LOADING_AUTOFILL));
+ autofill_web_data_->Init();
+
+ keyword_web_data_ = new KeywordWebDataService(
+ web_database_, ui_thread,
+ base::Bind(show_error_callback, ERROR_LOADING_KEYWORD));
+ keyword_web_data_->Init();
+
+ token_web_data_ = new TokenWebData(
+ web_database_, ui_thread, db_thread,
+ base::Bind(show_error_callback, ERROR_LOADING_TOKEN));
+ token_web_data_->Init();
+
+#if defined(OS_WIN)
+ password_web_data_ = new PasswordWebDataService(
+ web_database_, ui_thread,
+ base::Bind(show_error_callback, ERROR_LOADING_PASSWORD));
+ password_web_data_->Init();
+#endif
+}
+
+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<autofill::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
diff --git a/components/webdata_services/web_data_service_wrapper.h b/components/webdata_services/web_data_service_wrapper.h
new file mode 100644
index 0000000..76f5693
--- /dev/null
+++ b/components/webdata_services/web_data_service_wrapper.h
@@ -0,0 +1,85 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_
+#define COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_
+
+#include <string>
+
+#include "base/callback_forward.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "sql/init_status.h"
+
+class KeywordWebDataService;
+class TokenWebData;
+class WebDatabaseService;
+
+#if defined(OS_WIN)
+class PasswordWebDataService;
+#endif
+
+namespace autofill {
+class AutofillWebDataBackend;
+class AutofillWebDataService;
+} // namespace autofill
+
+namespace base {
+class FilePath;
+class MessageLoopProxy;
+} // namespace base
+
+// WebDataServiceWrapper is a KeyedService that owns multiple WebDataServices
+// so that they can be associated with a context.
+class WebDataServiceWrapper : public KeyedService {
+ public:
+ // ErrorType indicates which service encountered an error loading its data.
+ enum ErrorType {
+ ERROR_LOADING_AUTOFILL,
+ ERROR_LOADING_KEYWORD,
+ ERROR_LOADING_TOKEN,
+ ERROR_LOADING_PASSWORD,
+ };
+
+ // Shows an error message if a loading error occurs.
+ using ShowErrorCallback = void (*)(ErrorType, sql::InitStatus);
+
+ WebDataServiceWrapper(const base::FilePath& profile_path,
+ const std::string& application_locale,
+ const scoped_refptr<base::MessageLoopProxy>& ui_thread,
+ const scoped_refptr<base::MessageLoopProxy>& db_thread,
+ ShowErrorCallback show_error_callback);
+ ~WebDataServiceWrapper() override;
+
+ // For testing.
+ WebDataServiceWrapper();
+
+ // KeyedService:
+ void Shutdown() override;
+
+ // Create the various types of service instances. These methods are virtual
+ // for testing purpose.
+ virtual scoped_refptr<autofill::AutofillWebDataService> GetAutofillWebData();
+ virtual scoped_refptr<KeywordWebDataService> GetKeywordWebData();
+ virtual scoped_refptr<TokenWebData> GetTokenWebData();
+#if defined(OS_WIN)
+ virtual scoped_refptr<PasswordWebDataService> GetPasswordWebData();
+#endif
+
+ private:
+ scoped_refptr<WebDatabaseService> web_database_;
+
+ scoped_refptr<autofill::AutofillWebDataService> autofill_web_data_;
+ scoped_refptr<KeywordWebDataService> keyword_web_data_;
+ scoped_refptr<TokenWebData> token_web_data_;
+
+#if defined(OS_WIN)
+ scoped_refptr<PasswordWebDataService> password_web_data_;
+#endif
+
+ DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper);
+};
+
+#endif // COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_