summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorrlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-14 23:49:46 +0000
committerrlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-14 23:49:46 +0000
commitd07edd42ce09a444f435c0dcffd4a123dc6f31b9 (patch)
tree171e5756c9b49514e7fe6ab43cb1ecd60e0acd4f /chrome/browser
parentb6da6b187ffec9d19a990c0c058864571bd01a8e (diff)
downloadchromium_src-d07edd42ce09a444f435c0dcffd4a123dc6f31b9.zip
chromium_src-d07edd42ce09a444f435c0dcffd4a123dc6f31b9.tar.gz
chromium_src-d07edd42ce09a444f435c0dcffd4a123dc6f31b9.tar.bz2
Taking over issue 10006037.
Moved WebDataService to ProfileKeyedService James: chrome\browser\ui\intents Peter: chrome\browser\ui\search_engines chrome\browser\search_engines Nicolas: chrome\browser\sync Rachel/Elliot: chrome\browser\profiles and the whole cl BUG=112234 TEST=unit-tests TBR=jhawkins@chromium.org,pkasting@chromium.org,zea@chromium.org,erg@chromium.org,isherman@chromium.org Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=136499 Review URL: https://chromiumcodereview.appspot.com/10185008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137014 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autocomplete_history_manager.cc4
-rw-r--r--chrome/browser/autocomplete_history_manager_unittest.cc4
-rw-r--r--chrome/browser/autofill/autofill_metrics_unittest.cc1
-rw-r--r--chrome/browser/autofill/personal_data_manager.cc95
-rw-r--r--chrome/browser/autofill/personal_data_manager_factory.cc4
-rw-r--r--chrome/browser/autofill/personal_data_manager_unittest.cc8
-rw-r--r--chrome/browser/browser_process_impl.h1
-rw-r--r--chrome/browser/browsing_data_remover.cc8
-rw-r--r--chrome/browser/chromeos/login/login_utils_browsertest.cc2
-rw-r--r--chrome/browser/extensions/app_notify_channel_setup_unittest.cc17
-rw-r--r--chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc13
-rw-r--r--chrome/browser/importer/profile_writer.cc4
-rw-r--r--chrome/browser/intents/register_intent_handler_infobar_delegate_unittest.cc15
-rw-r--r--chrome/browser/intents/web_intents_registry_factory.cc7
-rw-r--r--chrome/browser/intents/web_intents_registry_unittest.cc14
-rw-r--r--chrome/browser/memory_purger.cc8
-rw-r--r--chrome/browser/password_manager/password_store_factory.cc9
-rw-r--r--chrome/browser/password_manager/password_store_win_unittest.cc9
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.cc13
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.h2
-rw-r--r--chrome/browser/profiles/profile.h11
-rw-r--r--chrome/browser/profiles/profile_dependency_manager.cc4
-rw-r--r--chrome/browser/profiles/profile_impl.cc34
-rw-r--r--chrome/browser/profiles/profile_impl.h5
-rw-r--r--chrome/browser/search_engines/search_provider_install_data.cc4
-rw-r--r--chrome/browser/search_engines/template_url_service.cc13
-rw-r--r--chrome/browser/search_engines/template_url_service_factory.cc3
-rw-r--r--chrome/browser/search_engines/template_url_service_test_util.cc35
-rw-r--r--chrome/browser/search_engines/template_url_service_unittest.cc6
-rw-r--r--chrome/browser/signin/token_service.cc4
-rw-r--r--chrome/browser/signin/token_service_factory.cc5
-rw-r--r--chrome/browser/signin/token_service_unittest.cc14
-rw-r--r--chrome/browser/signin/ubertoken_fetcher_unittest.cc2
-rw-r--r--chrome/browser/sync/glue/autofill_data_type_controller.cc4
-rw-r--r--chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc28
-rw-r--r--chrome/browser/sync/glue/autofill_profile_data_type_controller.cc7
-rw-r--r--chrome/browser/sync/profile_sync_components_factory_impl.cc22
-rw-r--r--chrome/browser/sync/profile_sync_components_factory_impl.h4
-rw-r--r--chrome/browser/sync/profile_sync_service_autofill_unittest.cc30
-rw-r--r--chrome/browser/sync/profile_sync_service_factory.cc3
-rw-r--r--chrome/browser/sync/profile_sync_service_startup_unittest.cc2
-rw-r--r--chrome/browser/sync/profile_sync_service_unittest.cc2
-rw-r--r--chrome/browser/sync/test/integration/autofill_helper.cc13
-rw-r--r--chrome/browser/sync/test/integration/autofill_helper.h3
-rw-r--r--chrome/browser/ui/intents/web_intent_picker_controller_browsertest.cc7
-rw-r--r--chrome/browser/ui/intents/web_intents_model_unittest.cc9
-rw-r--r--chrome/browser/webdata/web_data_service.cc41
-rw-r--r--chrome/browser/webdata/web_data_service.h14
-rw-r--r--chrome/browser/webdata/web_data_service_factory.cc61
-rw-r--r--chrome/browser/webdata/web_data_service_factory.h44
-rw-r--r--chrome/browser/webdata/web_data_service_unittest.cc8
51 files changed, 459 insertions, 221 deletions
diff --git a/chrome/browser/autocomplete_history_manager.cc b/chrome/browser/autocomplete_history_manager.cc
index b287c89..b026753 100644
--- a/chrome/browser/autocomplete_history_manager.cc
+++ b/chrome/browser/autocomplete_history_manager.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/autofill/credit_card.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/autofill_messages.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/render_view_host.h"
@@ -115,7 +116,8 @@ AutocompleteHistoryManager::AutocompleteHistoryManager(
external_delegate_(NULL) {
profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext());
// May be NULL in unit tests.
- web_data_service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ web_data_service_ = WebDataServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS);
autofill_enabled_.Init(prefs::kAutofillEnabled, profile_->GetPrefs(), NULL);
}
diff --git a/chrome/browser/autocomplete_history_manager_unittest.cc b/chrome/browser/autocomplete_history_manager_unittest.cc
index 0e68d69..41185ec 100644
--- a/chrome/browser/autocomplete_history_manager_unittest.cc
+++ b/chrome/browser/autocomplete_history_manager_unittest.cc
@@ -37,7 +37,8 @@ class MockWebDataService : public WebDataService {
class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness {
protected:
AutocompleteHistoryManagerTest()
- : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {
+ : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()),
+ db_thread_(BrowserThread::DB) {
}
virtual void SetUp() {
@@ -48,6 +49,7 @@ class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness {
}
content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread db_thread_;
TestingProfile profile_;
scoped_refptr<MockWebDataService> web_data_service_;
diff --git a/chrome/browser/autofill/autofill_metrics_unittest.cc b/chrome/browser/autofill/autofill_metrics_unittest.cc
index df71b84..d6abecc 100644
--- a/chrome/browser/autofill/autofill_metrics_unittest.cc
+++ b/chrome/browser/autofill/autofill_metrics_unittest.cc
@@ -930,6 +930,7 @@ TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) {
EXPECT_CALL(*personal_data_.metric_logger(),
LogIsAutofillEnabledAtStartup(true)).Times(1);
personal_data_.Init(profile());
+ personal_data_.Shutdown();
personal_data_.set_autofill_enabled(false);
EXPECT_CALL(*personal_data_.metric_logger(),
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
index 7ab1285..1bc4ded 100644
--- a/chrome/browser/autofill/personal_data_manager.cc
+++ b/chrome/browser/autofill/personal_data_manager.cc
@@ -25,6 +25,7 @@
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/webdata/autofill_entry.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
@@ -170,10 +171,11 @@ void PersonalDataManager::OnWebDataServiceRequestDone(
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
if (sync_service && (!sync_service->HasSyncSetupCompleted() ||
!profile_->GetPrefs()->GetBoolean(prefs::kSyncAutofill))) {
- WebDataService* wds =
- profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (wds)
- wds->RemoveExpiredFormElements();
+ scoped_refptr<WebDataService> web_data_service =
+ WebDataServiceFactory::GetForProfile(profile_,
+ Profile::EXPLICIT_ACCESS);
+ if (web_data_service)
+ web_data_service->RemoveExpiredFormElements();
}
}
}
@@ -198,9 +200,9 @@ void PersonalDataManager::OnStateChanged() {
if (!profile_ || profile_->IsOffTheRecord())
return;
- WebDataService* web_data_service =
- profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!web_data_service) {
+ scoped_refptr<WebDataService> web_data_service =
+ WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
+ if (!web_data_service.get()) {
NOTREACHED();
return;
}
@@ -226,12 +228,12 @@ void PersonalDataManager::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED);
- WebDataService* web_data_service =
+ scoped_refptr<WebDataService> web_data_service =
content::Source<WebDataService>(source).ptr();
- DCHECK(web_data_service &&
- web_data_service ==
- profile_->GetWebDataService(Profile::EXPLICIT_ACCESS));
+ DCHECK(web_data_service.get() &&
+ web_data_service.get() == WebDataServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS).get());
Refresh();
}
@@ -364,8 +366,9 @@ void PersonalDataManager::AddProfile(const AutofillProfile& profile) {
if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
return;
- WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!wds)
+ scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS);
+ if (!wds.get())
return;
// Don't add a duplicate.
@@ -391,8 +394,9 @@ void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) {
return;
}
- WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!wds)
+ scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS);
+ if (!wds.get())
return;
// Make the update.
@@ -409,8 +413,9 @@ void PersonalDataManager::RemoveProfile(const std::string& guid) {
if (!FindByGUID<AutofillProfile>(web_profiles_, guid))
return;
- WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!wds)
+ scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS);
+ if (!wds.get())
return;
// Remove the profile.
@@ -440,8 +445,9 @@ void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) {
if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
return;
- WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!wds)
+ scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS);
+ if (!wds.get())
return;
// Don't add a duplicate.
@@ -467,8 +473,9 @@ void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) {
return;
}
- WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!wds)
+ scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS);
+ if (!wds.get())
return;
// Make the update.
@@ -485,8 +492,9 @@ void PersonalDataManager::RemoveCreditCard(const std::string& guid) {
if (!FindByGUID<CreditCard>(credit_cards_, guid))
return;
- WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!wds)
+ scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS);
+ if (!wds.get())
return;
// Remove the credit card.
@@ -572,9 +580,9 @@ void PersonalDataManager::Init(Profile* profile) {
metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled());
// WebDataService may not be available in tests.
- WebDataService* web_data_service =
- profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!web_data_service)
+ scoped_refptr<WebDataService> web_data_service =
+ WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
+ if (!web_data_service.get())
return;
LoadProfiles();
@@ -667,8 +675,9 @@ void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) {
address_of<AutofillProfile>);
AutofillProfile::AdjustInferredLabels(&profile_pointers);
- WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!wds)
+ scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS);
+ if (!wds.get())
return;
// Any profiles that are not in the new profile list should be removed from
@@ -718,8 +727,9 @@ void PersonalDataManager::SetCreditCards(
std::mem_fun_ref(&CreditCard::IsEmpty)),
credit_cards->end());
- WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!wds)
+ scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS);
+ if (!wds.get())
return;
// Any credit cards that are not in the new credit card list should be
@@ -757,9 +767,9 @@ void PersonalDataManager::SetCreditCards(
}
void PersonalDataManager::LoadProfiles() {
- WebDataService* web_data_service =
- profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!web_data_service) {
+ scoped_refptr<WebDataService> web_data_service =
+ WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
+ if (!web_data_service.get()) {
NOTREACHED();
return;
}
@@ -777,9 +787,9 @@ void PersonalDataManager::LoadAuxiliaryProfiles() const {
#endif
void PersonalDataManager::LoadCreditCards() {
- WebDataService* web_data_service =
- profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!web_data_service) {
+ scoped_refptr<WebDataService> web_data_service =
+ WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
+ if (!web_data_service.get()) {
NOTREACHED();
return;
}
@@ -828,9 +838,10 @@ void PersonalDataManager::ReceiveLoadedCreditCards(
void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) {
if (*handle) {
- WebDataService* web_data_service =
- profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!web_data_service) {
+ scoped_refptr<WebDataService> web_data_service =
+ WebDataServiceFactory::GetForProfile(profile_,
+ Profile::EXPLICIT_ACCESS);
+ if (!web_data_service.get()) {
NOTREACHED();
return;
}
@@ -898,9 +909,9 @@ void PersonalDataManager::EmptyMigrationTrash() {
if (!profile_ || profile_->IsOffTheRecord())
return;
- WebDataService* web_data_service =
- profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!web_data_service) {
+ scoped_refptr<WebDataService> web_data_service =
+ WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
+ if (!web_data_service.get()) {
NOTREACHED();
return;
}
diff --git a/chrome/browser/autofill/personal_data_manager_factory.cc b/chrome/browser/autofill/personal_data_manager_factory.cc
index 6ea4ded..5d13138 100644
--- a/chrome/browser/autofill/personal_data_manager_factory.cc
+++ b/chrome/browser/autofill/personal_data_manager_factory.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
// static
PersonalDataManager* PersonalDataManagerFactory::GetForProfile(
@@ -24,8 +25,7 @@ PersonalDataManagerFactory* PersonalDataManagerFactory::GetInstance() {
PersonalDataManagerFactory::PersonalDataManagerFactory()
: ProfileKeyedServiceFactory("PersonalDataManager",
ProfileDependencyManager::GetInstance()) {
- // TODO(erg): For Shutdown() order, we need to:
- // DependsOn(WebDataServiceFactory::GetInstance());
+ DependsOn(WebDataServiceFactory::GetInstance());
}
PersonalDataManagerFactory::~PersonalDataManagerFactory() {
diff --git a/chrome/browser/autofill/personal_data_manager_unittest.cc b/chrome/browser/autofill/personal_data_manager_unittest.cc
index 0daccb7..be512d0 100644
--- a/chrome/browser/autofill/personal_data_manager_unittest.cc
+++ b/chrome/browser/autofill/personal_data_manager_unittest.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/browser/autofill/personal_data_manager_observer.h"
#include "chrome/browser/password_manager/encryptor.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/guid.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
@@ -54,7 +55,7 @@ class PersonalDataManagerTest : public testing::Test {
db_thread_.Start();
profile_.reset(new TestingProfile);
- profile_->CreateWebDataService(false);
+ profile_->CreateWebDataService();
autofill_test::DisableSystemServices(profile_.get());
ResetPersonalDataManager();
@@ -438,8 +439,9 @@ TEST_F(PersonalDataManagerTest, Refresh) {
profile_pointers.push_back(&profile2);
AutofillProfile::AdjustInferredLabels(&profile_pointers);
- WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- ASSERT_TRUE(wds);
+ scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
+ profile_.get(), Profile::EXPLICIT_ACCESS);
+ ASSERT_TRUE(wds.get());
wds->AddAutofillProfile(profile2);
personal_data_->Refresh();
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index 93dc0f4..16685e4 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -127,7 +127,6 @@ class BrowserProcessImpl : public BrowserProcess,
#endif
void CreateTemplateURLService();
void CreateProfileManager();
- void CreateWebDataService();
void CreateLocalState();
void CreateViewedPageTracker();
void CreateIconManager();
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc
index 60c0863..0772e9f 100644
--- a/chrome/browser/browsing_data_remover.cc
+++ b/chrome/browser/browsing_data_remover.cc
@@ -40,6 +40,7 @@
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
@@ -343,10 +344,11 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask,
if (remove_mask & REMOVE_FORM_DATA) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
- WebDataService* web_data_service =
- profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ scoped_refptr<WebDataService> web_data_service =
+ WebDataServiceFactory::GetForProfile(profile_,
+ Profile::EXPLICIT_ACCESS);
- if (web_data_service) {
+ if (web_data_service.get()) {
web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
delete_end_);
web_data_service->RemoveAutofillProfilesAndCreditCardsModifiedBetween(
diff --git a/chrome/browser/chromeos/login/login_utils_browsertest.cc b/chrome/browser/chromeos/login/login_utils_browsertest.cc
index 8127816..aee7cda 100644
--- a/chrome/browser/chromeos/login/login_utils_browsertest.cc
+++ b/chrome/browser/chromeos/login/login_utils_browsertest.cc
@@ -110,6 +110,7 @@ class LoginUtilsTest : public testing::Test,
ui_thread_(content::BrowserThread::UI, &loop_),
file_thread_(content::BrowserThread::FILE, &loop_),
io_thread_(content::BrowserThread::IO),
+ db_thread_(content::BrowserThread::DB),
mock_async_method_caller_(NULL),
connector_(NULL),
cryptohome_(NULL),
@@ -370,6 +371,7 @@ class LoginUtilsTest : public testing::Test,
content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_;
content::TestBrowserThread io_thread_;
+ content::TestBrowserThread db_thread_;
scoped_ptr<IOThread> io_thread_state_;
MockDBusThreadManager mock_dbus_thread_manager_;
diff --git a/chrome/browser/extensions/app_notify_channel_setup_unittest.cc b/chrome/browser/extensions/app_notify_channel_setup_unittest.cc
index 6407243..dcfa45f 100644
--- a/chrome/browser/extensions/app_notify_channel_setup_unittest.cc
+++ b/chrome/browser/extensions/app_notify_channel_setup_unittest.cc
@@ -7,6 +7,7 @@
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
+#include "base/synchronization/waitable_event.h"
#include "chrome/browser/extensions/app_notify_channel_setup.h"
#include "chrome/browser/extensions/app_notify_channel_ui.h"
#include "chrome/browser/signin/token_service_factory.h"
@@ -172,6 +173,7 @@ class TestUI : public AppNotifyChannelUI {
class AppNotifyChannelSetupTest : public testing::Test {
public:
AppNotifyChannelSetupTest() : ui_thread_(BrowserThread::UI, &message_loop_),
+ db_thread_(BrowserThread::DB),
ui_(new TestUI()) {
}
@@ -233,9 +235,24 @@ class AppNotifyChannelSetupTest : public testing::Test {
delegate_.ExpectWasCalled(expected_code, expected_error);
}
+ virtual void SetUp() OVERRIDE {
+ db_thread_.Start();
+ }
+
+ virtual void TearDown() OVERRIDE {
+ // Schedule another task on the DB thread to notify us that it's safe to
+ // carry on with the test.
+ base::WaitableEvent done(false, false);
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
+ done.Wait();
+ db_thread_.Stop();
+ }
+
protected:
MessageLoop message_loop_;
content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread db_thread_;
TestProfile profile_;
TestDelegate delegate_;
scoped_ptr<TestUI> ui_;
diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc
index 9bbbee4..07a6257 100644
--- a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc
+++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc
@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/hash_tables.h"
#include "base/memory/scoped_vector.h"
+#include "base/synchronization/waitable_event.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
@@ -140,6 +141,7 @@ class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness {
virtual void TearDown() OVERRIDE;
content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread db_thread_;
// A map between renderer child id and a pair represending the bridge id and
// whether the requested permission was allowed.
@@ -148,7 +150,8 @@ class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness {
GeolocationPermissionContextTests::GeolocationPermissionContextTests()
: TabContentsWrapperTestHarness(),
- ui_thread_(BrowserThread::UI, MessageLoop::current()) {
+ ui_thread_(BrowserThread::UI, MessageLoop::current()),
+ db_thread_(BrowserThread::DB) {
}
GeolocationPermissionContextTests::~GeolocationPermissionContextTests() {
@@ -228,6 +231,7 @@ void GeolocationPermissionContextTests::CheckTabContentsState(
}
void GeolocationPermissionContextTests::SetUp() {
+ db_thread_.Start();
TabContentsWrapperTestHarness::SetUp();
geolocation_permission_context_ =
new ChromeGeolocationPermissionContext(profile());
@@ -236,6 +240,13 @@ void GeolocationPermissionContextTests::SetUp() {
void GeolocationPermissionContextTests::TearDown() {
extra_tabs_.reset();
TabContentsWrapperTestHarness::TearDown();
+ // Schedule another task on the DB thread to notify us that it's safe to
+ // carry on with the test.
+ base::WaitableEvent done(false, false);
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
+ done.Wait();
+ db_thread_.Stop();
}
diff --git a/chrome/browser/importer/profile_writer.cc b/chrome/browser/importer/profile_writer.cc
index 8519432..eb3b659 100644
--- a/chrome/browser/importer/profile_writer.cc
+++ b/chrome/browser/importer/profile_writer.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
@@ -94,7 +95,8 @@ void ProfileWriter::AddPasswordForm(const webkit::forms::PasswordForm& form) {
#if defined(OS_WIN)
void ProfileWriter::AddIE7PasswordInfo(const IE7PasswordInfo& info) {
- profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)->AddIE7Login(info);
+ WebDataServiceFactory::GetForProfile(
+ profile_, Profile::EXPLICIT_ACCESS)->AddIE7Login(info);
}
#endif
diff --git a/chrome/browser/intents/register_intent_handler_infobar_delegate_unittest.cc b/chrome/browser/intents/register_intent_handler_infobar_delegate_unittest.cc
index 559a09e..41986ca 100644
--- a/chrome/browser/intents/register_intent_handler_infobar_delegate_unittest.cc
+++ b/chrome/browser/intents/register_intent_handler_infobar_delegate_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/synchronization/waitable_event.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/intents/register_intent_handler_infobar_delegate.h"
#include "chrome/browser/intents/web_intents_registry.h"
@@ -38,12 +39,14 @@ class RegisterIntentHandlerInfoBarDelegateTest
: public TabContentsWrapperTestHarness {
protected:
RegisterIntentHandlerInfoBarDelegateTest()
- : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()) {}
+ : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()),
+ db_thread_(BrowserThread::DB) {}
virtual void SetUp() {
+ db_thread_.Start();
TabContentsWrapperTestHarness::SetUp();
- profile()->CreateWebDataService(false);
+ profile()->CreateWebDataService();
web_intents_registry_ = BuildForProfile(profile());
}
@@ -51,12 +54,20 @@ class RegisterIntentHandlerInfoBarDelegateTest
web_intents_registry_ = NULL;
TabContentsWrapperTestHarness::TearDown();
+ // Schedule another task on the DB thread to notify us that it's safe to
+ // carry on with the test.
+ base::WaitableEvent done(false, false);
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
+ done.Wait();
+ db_thread_.Stop();
}
MockWebIntentsRegistry* web_intents_registry_;
private:
content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread db_thread_;
DISALLOW_COPY_AND_ASSIGN(RegisterIntentHandlerInfoBarDelegateTest);
};
diff --git a/chrome/browser/intents/web_intents_registry_factory.cc b/chrome/browser/intents/web_intents_registry_factory.cc
index f6e75c9..7bbbdb4 100644
--- a/chrome/browser/intents/web_intents_registry_factory.cc
+++ b/chrome/browser/intents/web_intents_registry_factory.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/intents/web_intents_registry.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
// static
WebIntentsRegistry* WebIntentsRegistryFactory::GetForProfile(Profile* profile) {
@@ -19,8 +20,7 @@ WebIntentsRegistry* WebIntentsRegistryFactory::GetForProfile(Profile* profile) {
WebIntentsRegistryFactory::WebIntentsRegistryFactory()
: ProfileKeyedServiceFactory("WebIntentsRegistry",
ProfileDependencyManager::GetInstance()) {
- // TODO(erg): For Shutdown() order, we need to:
- // DependsOn(WebDataServiceFactory::GetInstance());
+ DependsOn(WebDataServiceFactory::GetInstance());
DependsOn(ExtensionSystemFactory::GetInstance());
}
@@ -35,7 +35,8 @@ WebIntentsRegistryFactory* WebIntentsRegistryFactory::GetInstance() {
ProfileKeyedService* WebIntentsRegistryFactory::BuildServiceInstanceFor(
Profile* profile) const {
WebIntentsRegistry* registry = new WebIntentsRegistry;
- registry->Initialize(profile->GetWebDataService(Profile::EXPLICIT_ACCESS),
+ registry->Initialize(WebDataServiceFactory::GetForProfile(
+ profile, Profile::EXPLICIT_ACCESS),
profile->GetExtensionService());
return registry;
}
diff --git a/chrome/browser/intents/web_intents_registry_unittest.cc b/chrome/browser/intents/web_intents_registry_unittest.cc
index 0554029..fb4eaf5 100644
--- a/chrome/browser/intents/web_intents_registry_unittest.cc
+++ b/chrome/browser/intents/web_intents_registry_unittest.cc
@@ -8,6 +8,7 @@
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/scoped_temp_dir.h"
+#include "base/synchronization/waitable_event.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/test_extension_service.h"
#include "chrome/browser/intents/default_web_intent_service.h"
@@ -102,9 +103,16 @@ class WebIntentsRegistryTest : public testing::Test {
}
virtual void TearDown() {
- if (wds_.get())
- wds_->Shutdown();
-
+ // Clear all references to wds to force it destruction.
+ wds_->ShutdownOnUIThread();
+ wds_ = NULL;
+
+ // Schedule another task on the DB thread to notify us that it's safe to
+ // carry on with the test.
+ base::WaitableEvent done(false, false);
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
+ done.Wait();
db_thread_.Stop();
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
MessageLoop::current()->Run();
diff --git a/chrome/browser/memory_purger.cc b/chrome/browser/memory_purger.cc
index 21cf2e9..d00ee17 100644
--- a/chrome/browser/memory_purger.cc
+++ b/chrome/browser/memory_purger.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/render_messages.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host.h"
@@ -114,9 +115,10 @@ void MemoryPurger::PurgeBrowser() {
history_service->UnloadBackend();
// Unload all web databases (freeing memory used to cache sqlite).
- WebDataService* web_data_service =
- profiles[i]->GetWebDataServiceWithoutCreating();
- if (web_data_service)
+ scoped_refptr<WebDataService> web_data_service =
+ WebDataServiceFactory::GetForProfileIfExists(
+ profiles[i], Profile::EXPLICIT_ACCESS);
+ if (web_data_service.get())
web_data_service->UnloadDatabase();
BrowserContext::PurgeMemory(profiles[i]);
diff --git a/chrome/browser/password_manager/password_store_factory.cc b/chrome/browser/password_manager/password_store_factory.cc
index 3878b63..57a135c 100644
--- a/chrome/browser/password_manager/password_store_factory.cc
+++ b/chrome/browser/password_manager/password_store_factory.cc
@@ -11,6 +11,8 @@
#include "chrome/browser/password_manager/password_store_default.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
@@ -63,10 +65,7 @@ PasswordStoreFactory::PasswordStoreFactory()
: RefcountedProfileKeyedServiceFactory(
"PasswordStore",
ProfileDependencyManager::GetInstance()) {
- // TODO(erg): We must always depend on WebDB; we don't want the dependency
- // graph to be different based on platform.
- //
- // DependsOn(WebDataServiceFactory::GetInstance());
+ DependsOn(WebDataServiceFactory::GetInstance());
}
PasswordStoreFactory::~PasswordStoreFactory() {}
@@ -108,7 +107,7 @@ PasswordStoreFactory::BuildServiceInstanceFor(Profile* profile) const {
#if defined(OS_WIN)
ps = new PasswordStoreWin(
login_db, profile,
- profile->GetWebDataService(Profile::IMPLICIT_ACCESS));
+ WebDataServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS));
#elif defined(OS_MACOSX)
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseMockKeychain)) {
ps = new PasswordStoreMac(new crypto::MockKeychain(), login_db);
diff --git a/chrome/browser/password_manager/password_store_win_unittest.cc b/chrome/browser/password_manager/password_store_win_unittest.cc
index 0d03e20..ddcfa60 100644
--- a/chrome/browser/password_manager/password_store_win_unittest.cc
+++ b/chrome/browser/password_manager/password_store_win_unittest.cc
@@ -120,8 +120,12 @@ class PasswordStoreWinTest : public testing::Test {
virtual void TearDown() {
if (store_.get())
store_->ShutdownOnUIThread();
- if (wds_.get())
- wds_->Shutdown();
+ wds_->ShutdownOnUIThread();
+ wds_ = NULL;
+ base::WaitableEvent done(false, false);
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
+ done.Wait();
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
MessageLoop::current()->Run();
db_thread_.Stop();
@@ -250,7 +254,6 @@ TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) {
// Release the PSW and the WDS before the query can return.
store_->ShutdownOnUIThread();
store_ = NULL;
- wds_->Shutdown();
wds_ = NULL;
MessageLoop::current()->RunAllPending();
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc
index 04550c7..533c192 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl.cc
@@ -246,19 +246,6 @@ history::ShortcutsBackend* OffTheRecordProfileImpl::GetShortcutsBackend() {
return NULL;
}
-WebDataService* OffTheRecordProfileImpl::GetWebDataService(
- ServiceAccessType sat) {
- if (sat == EXPLICIT_ACCESS)
- return profile_->GetWebDataService(sat);
-
- NOTREACHED() << "This profile is OffTheRecord";
- return NULL;
-}
-
-WebDataService* OffTheRecordProfileImpl::GetWebDataServiceWithoutCreating() {
- return profile_->GetWebDataServiceWithoutCreating();
-}
-
PrefService* OffTheRecordProfileImpl::GetPrefs() {
return prefs_;
}
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h
index a0193ca..9fd2f1e 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.h
+++ b/chrome/browser/profiles/off_the_record_profile_impl.h
@@ -52,8 +52,6 @@ class OffTheRecordProfileImpl : public Profile,
virtual FaviconService* GetFaviconService(ServiceAccessType sat) OVERRIDE;
virtual AutocompleteClassifier* GetAutocompleteClassifier() OVERRIDE;
virtual history::ShortcutsBackend* GetShortcutsBackend() OVERRIDE;
- virtual WebDataService* GetWebDataService(ServiceAccessType sat) OVERRIDE;
- virtual WebDataService* GetWebDataServiceWithoutCreating() OVERRIDE;
virtual PrefService* GetPrefs() OVERRIDE;
virtual PrefService* GetOffTheRecordPrefs() OVERRIDE;
virtual net::URLRequestContextGetter*
diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h
index e20f4f2..a08a48b 100644
--- a/chrome/browser/profiles/profile.h
+++ b/chrome/browser/profiles/profile.h
@@ -262,17 +262,6 @@ class Profile : public content::BrowserContext {
// this profile need to be sure they refcount the returned value.
virtual history::ShortcutsBackend* GetShortcutsBackend() = 0;
- // Returns the WebDataService for this profile. This is owned by
- // the Profile. Callers that outlive the life of this profile need to be
- // sure they refcount the returned value.
- //
- // |access| defines what the caller plans to do with the service. See
- // the ServiceAccessType definition above.
- virtual WebDataService* GetWebDataService(ServiceAccessType access) = 0;
-
- // Similar to GetWebDataService(), but won't create the web data service if it
- // doesn't already exist.
- virtual WebDataService* GetWebDataServiceWithoutCreating() = 0;
// Retrieves a pointer to the PrefService that manages the preferences
// for this user profile. The PrefService is lazily created the first
diff --git a/chrome/browser/profiles/profile_dependency_manager.cc b/chrome/browser/profiles/profile_dependency_manager.cc
index c6ea565..0b13f30 100644
--- a/chrome/browser/profiles/profile_dependency_manager.cc
+++ b/chrome/browser/profiles/profile_dependency_manager.cc
@@ -44,11 +44,10 @@
#include "chrome/browser/ui/webui/chrome_url_data_manager_factory.h"
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
#include "chrome/browser/user_style_sheet_watcher_factory.h"
-
#if defined(USE_AURA)
#include "chrome/browser/ui/gesture_prefs_observer_factory_aura.h"
#endif
-
+#include "chrome/browser/webdata/web_data_service_factory.h"
#ifndef NDEBUG
#include "base/command_line.h"
#include "base/file_util.h"
@@ -233,6 +232,7 @@ void ProfileDependencyManager::AssertFactoriesBuilt() {
#if defined(ENABLE_WEB_INTENTS)
WebIntentsRegistryFactory::GetInstance();
#endif
+ WebDataServiceFactory::GetInstance();
built_factories_ = true;
}
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 143c96d..9585dd0 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -226,7 +226,6 @@ ProfileImpl::ProfileImpl(const FilePath& path,
host_content_settings_map_(NULL),
history_service_created_(false),
favicon_service_created_(false),
- created_web_data_service_(false),
clear_local_state_on_exit_(false),
start_time_(Time::Now()),
delegate_(delegate),
@@ -510,14 +509,12 @@ ProfileImpl::~ProfileImpl() {
ProfileDependencyManager::GetInstance()->DestroyProfileServices(this);
- // Both HistoryService and WebDataService maintain threads for background
- // processing. Its possible each thread still has tasks on it that have
- // increased the ref count of the service. In such a situation, when we
- // decrement the refcount, it won't be 0, and the threads/databases aren't
- // properly shut down. By explicitly calling Cleanup/Shutdown we ensure the
- // databases are properly closed.
- if (web_data_service_.get())
- web_data_service_->Shutdown();
+ // The HistoryService maintains threads for background processing. Its
+ // possible each thread still has tasks on it that have increased the ref
+ // count of the service. In such a situation, when we decrement the refcount,
+ // it won't be 0, and the threads/databases aren't properly shut down. By
+ // explicitly calling Cleanup/Shutdown we ensure the databases are properly
+ // closed.
if (top_sites_.get())
top_sites_->Shutdown();
@@ -832,25 +829,6 @@ history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() {
return shortcuts_backend_.get();
}
-WebDataService* ProfileImpl::GetWebDataService(ServiceAccessType sat) {
- if (!created_web_data_service_)
- CreateWebDataService();
- return web_data_service_.get();
-}
-
-WebDataService* ProfileImpl::GetWebDataServiceWithoutCreating() {
- return web_data_service_.get();
-}
-
-void ProfileImpl::CreateWebDataService() {
- DCHECK(!created_web_data_service_ && web_data_service_.get() == NULL);
- created_web_data_service_ = true;
- scoped_refptr<WebDataService> wds(new WebDataService());
- if (!wds->Init(GetPath()))
- return;
- web_data_service_.swap(wds);
-}
-
DownloadManager* ProfileImpl::GetDownloadManager() {
return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager();
}
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index a9f51b2..8662ea0 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -89,8 +89,6 @@ class ProfileImpl : public Profile,
virtual HistoryService* GetHistoryServiceWithoutCreating() OVERRIDE;
virtual AutocompleteClassifier* GetAutocompleteClassifier() OVERRIDE;
virtual history::ShortcutsBackend* GetShortcutsBackend() OVERRIDE;
- virtual WebDataService* GetWebDataService(ServiceAccessType sat) OVERRIDE;
- virtual WebDataService* GetWebDataServiceWithoutCreating() OVERRIDE;
virtual PrefService* GetPrefs() OVERRIDE;
virtual PrefService* GetOffTheRecordPrefs() OVERRIDE;
virtual net::URLRequestContextGetter*
@@ -155,7 +153,6 @@ class ProfileImpl : public Profile,
// Does final prefs initialization and calls Init().
void OnPrefsLoaded(bool success);
- void CreateWebDataService();
FilePath GetPrefFilePath();
#if defined(ENABLE_SESSION_SERVICE)
@@ -225,10 +222,8 @@ class ProfileImpl : public Profile,
scoped_ptr<FaviconService> favicon_service_;
scoped_ptr<AutocompleteClassifier> autocomplete_classifier_;
scoped_refptr<history::ShortcutsBackend> shortcuts_backend_;
- scoped_refptr<WebDataService> web_data_service_;
bool history_service_created_;
bool favicon_service_created_;
- bool created_web_data_service_;
bool clear_local_state_on_exit_;
// Whether or not the last session exited cleanly. This is set only once.
diff --git a/chrome/browser/search_engines/search_provider_install_data.cc b/chrome/browser/search_engines/search_provider_install_data.cc
index c50ad08..7a0b0aa 100644
--- a/chrome/browser/search_engines/search_provider_install_data.cc
+++ b/chrome/browser/search_engines/search_provider_install_data.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/util.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_observer.h"
@@ -158,7 +159,8 @@ SearchProviderInstallData::SearchProviderInstallData(
Profile* profile,
int ui_death_notification,
const content::NotificationSource& ui_death_source)
- : web_service_(profile->GetWebDataService(Profile::EXPLICIT_ACCESS)),
+ : web_service_(WebDataServiceFactory::GetForProfile(profile,
+ Profile::EXPLICIT_ACCESS)),
load_handle_(0),
google_base_url_(UIThreadSearchTermsData(profile).GoogleBaseURLValue()) {
// GoogleURLObserver is responsible for killing itself when
diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc
index 530c6d8..688e681 100644
--- a/chrome/browser/search_engines/template_url_service.cc
+++ b/chrome/browser/search_engines/template_url_service.cc
@@ -35,6 +35,7 @@
#include "chrome/browser/search_engines/util.h"
#include "chrome/browser/sync/api/sync_change.h"
#include "chrome/browser/sync/api/sync_error_factory.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/env_vars.h"
@@ -555,8 +556,10 @@ void TemplateURLService::Load() {
if (loaded_ || load_handle_)
return;
- if (!service_.get())
- service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ if (!service_.get()) {
+ service_ = WebDataServiceFactory::GetForProfile(profile_,
+ Profile::EXPLICIT_ACCESS);
+ }
if (service_.get()) {
load_handle_ = service_->GetKeywords(this);
@@ -896,9 +899,9 @@ SyncError TemplateURLService::ProcessSyncChanges(
// . Trying to ADD a search engine that already exists.
NOTREACHED() << "Unexpected sync change state.";
error = sync_error_factory_->CreateAndUploadError(
- FROM_HERE,
- "ProcessSyncChanges failed on ChangeType " +
- SyncChange::ChangeTypeToString(iter->change_type()));
+ FROM_HERE,
+ "ProcessSyncChanges failed on ChangeType " +
+ SyncChange::ChangeTypeToString(iter->change_type()));
}
}
PreventDuplicateGUIDUpdates(&new_changes);
diff --git a/chrome/browser/search_engines/template_url_service_factory.cc b/chrome/browser/search_engines/template_url_service_factory.cc
index 5292074..b4c533f 100644
--- a/chrome/browser/search_engines/template_url_service_factory.cc
+++ b/chrome/browser/search_engines/template_url_service_factory.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/pref_names.h"
TemplateURLService* TemplateURLServiceFactory::GetForProfile(Profile* profile) {
@@ -23,8 +24,8 @@ TemplateURLServiceFactory::TemplateURLServiceFactory()
: ProfileKeyedServiceFactory("TemplateURLServiceFactory",
ProfileDependencyManager::GetInstance()) {
DependsOn(GoogleURLTrackerFactory::GetInstance());
+ DependsOn(WebDataServiceFactory::GetInstance());
// TODO(erg): For Shutdown() order, we need to:
- // DependsOn(WebDataServiceFactory::GetInstance());
// DependsOn(HistoryService::GetInstance());
// DependsOn(ExtensionService::GetInstance());
}
diff --git a/chrome/browser/search_engines/template_url_service_test_util.cc b/chrome/browser/search_engines/template_url_service_test_util.cc
index 881300c..f562c25 100644
--- a/chrome/browser/search_engines/template_url_service_test_util.cc
+++ b/chrome/browser/search_engines/template_url_service_test_util.cc
@@ -8,10 +8,12 @@
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/scoped_temp_dir.h"
+#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
#include "chrome/browser/search_engines/search_terms_data.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service.h"
@@ -62,9 +64,8 @@ class TemplateURLServiceTestingProfile : public TestingProfile {
io_thread_.StartIOThread();
}
- virtual WebDataService* GetWebDataService(ServiceAccessType access) {
- return service_.get();
- }
+ static scoped_refptr<RefcountedProfileKeyedService>
+ GetWebDataServiceForTemplateURLServiceTestingProfile(Profile* profile);
private:
scoped_refptr<WebDataService> service_;
@@ -73,6 +74,7 @@ class TemplateURLServiceTestingProfile : public TestingProfile {
content::TestBrowserThread io_thread_;
};
+
// Trivial subclass of TemplateURLService that records the last invocation of
// SetKeywordSearchTermsForURL.
class TestingTemplateURLService : public TemplateURLService {
@@ -128,15 +130,31 @@ void TemplateURLServiceTestingProfile::TearDown() {
io_thread_.Stop();
// Clean up the test directory.
- if (service_.get())
- service_->Shutdown();
+ if (service_.get()) {
+ service_->ShutdownOnUIThread();
+ service_ = NULL;
+ }
// Note that we must ensure the DB thread is stopped after WDS
// shutdown (so it can commit pending transactions) but before
// deleting the test profile directory, otherwise we may not be
// able to delete it due to an open transaction.
+ // Schedule another task on the DB thread to notify us that it's safe to
+ // carry on with the test.
+ base::WaitableEvent done(false, false);
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
+ done.Wait();
db_thread_.Stop();
}
+scoped_refptr<RefcountedProfileKeyedService>
+TemplateURLServiceTestingProfile::
+ GetWebDataServiceForTemplateURLServiceTestingProfile(Profile* profile) {
+ TemplateURLServiceTestingProfile* test_profile =
+ reinterpret_cast<TemplateURLServiceTestingProfile*>(profile);
+ return test_profile->service_;
+}
+
TemplateURLServiceTestUtil::TemplateURLServiceTestUtil()
: ui_thread_(BrowserThread::UI, &message_loop_),
changed_count_(0) {
@@ -147,6 +165,10 @@ TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() {
void TemplateURLServiceTestUtil::SetUp() {
profile_.reset(new TemplateURLServiceTestingProfile());
+ WebDataServiceFactory::GetInstance()->SetTestingFactory(
+ profile_.get(), TemplateURLServiceTestingProfile::
+ GetWebDataServiceForTemplateURLServiceTestingProfile);
+
profile_->SetUp();
TemplateURLService* service = static_cast<TemplateURLService*>(
TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
@@ -197,7 +219,8 @@ void TemplateURLServiceTestUtil::ChangeModelToLoadState() {
model()->ChangeToLoadedState();
// Initialize the web data service so that the database gets updated with
// any changes made.
- model()->service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ model()->service_ = WebDataServiceFactory::GetForProfile(
+ profile_.get(), Profile::EXPLICIT_ACCESS);
}
void TemplateURLServiceTestUtil::ClearModel() {
diff --git a/chrome/browser/search_engines/template_url_service_unittest.cc b/chrome/browser/search_engines/template_url_service_unittest.cc
index 9bf29c6..c37fc07 100644
--- a/chrome/browser/search_engines/template_url_service_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_unittest.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "chrome/browser/webdata/web_database.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/testing_profile.h"
#include "content/test/test_browser_thread.h"
@@ -1256,8 +1257,9 @@ TEST_F(TemplateURLServiceTest, FailedInit) {
test_util_.VerifyLoad();
test_util_.ClearModel();
- WebDataService* web_service =
- test_util_.profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ scoped_refptr<WebDataService> web_service =
+ WebDataServiceFactory::GetForProfile(test_util_.profile(),
+ Profile::EXPLICIT_ACCESS);
web_service->UnloadDatabase();
web_service->set_failed_init(true);
diff --git a/chrome/browser/signin/token_service.cc b/chrome/browser/signin/token_service.cc
index a317279..c815796 100644
--- a/chrome/browser/signin/token_service.cc
+++ b/chrome/browser/signin/token_service.cc
@@ -9,6 +9,7 @@
#include "base/string_util.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/net/gaia/gaia_auth_fetcher.h"
@@ -64,7 +65,8 @@ void TokenService::Initialize(const char* const source,
getter_ = profile->GetRequestContext();
// Since the user can create a bookmark in incognito, sync may be running.
// Thus we have to go for explicit access.
- web_data_service_ = profile->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ web_data_service_ = WebDataServiceFactory::GetForProfile(
+ profile, Profile::EXPLICIT_ACCESS);
source_ = std::string(source);
CommandLine* cmd_line = CommandLine::ForCurrentProcess();
diff --git a/chrome/browser/signin/token_service_factory.cc b/chrome/browser/signin/token_service_factory.cc
index 54d6581..bbf4b86 100644
--- a/chrome/browser/signin/token_service_factory.cc
+++ b/chrome/browser/signin/token_service_factory.cc
@@ -6,13 +6,12 @@
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/signin/token_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
TokenServiceFactory::TokenServiceFactory()
: ProfileKeyedServiceFactory("TokenService",
ProfileDependencyManager::GetInstance()) {
- // TODO(rlp): TokenService depends on WebDataService - when this is
- // converted to the ProfileKeyedService framework, uncomment this dependency.
- // DependsOn(WebDataServiceFactory::GetInstance());
+ DependsOn(WebDataServiceFactory::GetInstance());
}
TokenServiceFactory::~TokenServiceFactory() {}
diff --git a/chrome/browser/signin/token_service_unittest.cc b/chrome/browser/signin/token_service_unittest.cc
index c8c2882..763233f 100644
--- a/chrome/browser/signin/token_service_unittest.cc
+++ b/chrome/browser/signin/token_service_unittest.cc
@@ -13,6 +13,7 @@
#include "base/synchronization/waitable_event.h"
#include "chrome/browser/password_manager/encryptor.h"
#include "chrome/browser/signin/token_service_factory.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/net/gaia/mock_url_fetcher_factory.h"
@@ -72,7 +73,8 @@ void TokenServiceTestHarness::SetUp() {
ASSERT_TRUE(db_thread_.Start());
profile_.reset(new TestingProfile());
- profile_->CreateWebDataService(false);
+ profile_->CreateWebDataService();
+
WaitForDBLoadCompletion();
service_ = TokenServiceFactory::GetForProfile(profile_.get());
@@ -89,6 +91,12 @@ void TokenServiceTestHarness::TearDown() {
if (profile_.get()) {
profile_.reset(NULL);
}
+ // Schedule another task on the DB thread to notify us that it's safe to
+ // carry on with the test.
+ base::WaitableEvent done(false, false);
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
+ done.Wait();
db_thread_.Stop();
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
@@ -96,6 +104,10 @@ void TokenServiceTestHarness::TearDown() {
}
void TokenServiceTestHarness::WaitForDBLoadCompletion() {
+ // Force the loading of the WebDataService.
+ WebDataServiceFactory::GetForProfile(profile_.get(),
+ Profile::IMPLICIT_ACCESS);
+
// The WebDB does all work on the DB thread. This will add an event
// to the end of the DB thread, so when we reach this task, all DB
// operations should be complete.
diff --git a/chrome/browser/signin/ubertoken_fetcher_unittest.cc b/chrome/browser/signin/ubertoken_fetcher_unittest.cc
index b1b04e0..27de717 100644
--- a/chrome/browser/signin/ubertoken_fetcher_unittest.cc
+++ b/chrome/browser/signin/ubertoken_fetcher_unittest.cc
@@ -11,6 +11,8 @@
#include "content/test/test_url_fetcher_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
+using content::BrowserThread;
+
class MockUbertokenConsumer : public UbertokenConsumer {
public:
MockUbertokenConsumer()
diff --git a/chrome/browser/sync/glue/autofill_data_type_controller.cc b/chrome/browser/sync/glue/autofill_data_type_controller.cc
index b614b09..ac24c0e 100644
--- a/chrome/browser/sync/glue/autofill_data_type_controller.cc
+++ b/chrome/browser/sync/glue/autofill_data_type_controller.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/sync/api/sync_error.h"
#include "chrome/browser/sync/profile_sync_components_factory.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_source.h"
@@ -65,7 +66,8 @@ bool AutofillDataTypeController::StartModels() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK_EQ(MODEL_STARTING, state());
- web_data_service_ = profile()->GetWebDataService(Profile::IMPLICIT_ACCESS);
+ web_data_service_ = WebDataServiceFactory::GetForProfile(
+ profile(), Profile::IMPLICIT_ACCESS);
if (web_data_service_->IsDatabaseLoaded()) {
return true;
} else {
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 ba157ca..be9d27d 100644
--- a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
+++ b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/sync/profile_sync_components_factory_mock.h"
#include "chrome/browser/sync/profile_sync_service_mock.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/test/base/profile_mock.h"
#include "content/public/browser/notification_service.h"
@@ -54,6 +55,8 @@ class FakeWebDataService : public WebDataService {
return is_database_loaded_;
}
+ virtual void ShutdownOnUIThread() OVERRIDE {}
+
private:
virtual ~FakeWebDataService() {}
@@ -67,6 +70,7 @@ class SyncAutofillDataTypeControllerTest : public testing::Test {
SyncAutofillDataTypeControllerTest()
: weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
ui_thread_(BrowserThread::UI, &message_loop_),
+ db_thread_(BrowserThread::DB),
last_start_result_(DataTypeController::OK) {}
virtual ~SyncAutofillDataTypeControllerTest() {}
@@ -81,10 +85,8 @@ class SyncAutofillDataTypeControllerTest : public testing::Test {
CreateSharedChangeProcessor()).
WillRepeatedly(Return(change_processor_.get()));
- web_data_service_ = new FakeWebDataService();
-
- EXPECT_CALL(profile_, GetWebDataService(_)).
- WillRepeatedly(Return(web_data_service_.get()));
+ WebDataServiceFactory::GetInstance()->SetTestingFactory(
+ &profile_, BuildWebDataService);
autofill_dtc_ =
new AutofillDataTypeController(&profile_sync_factory_,
@@ -101,20 +103,24 @@ class SyncAutofillDataTypeControllerTest : public testing::Test {
virtual void TearDown() {
autofill_dtc_ = NULL;
- web_data_service_ = NULL;
change_processor_ = NULL;
}
+ static scoped_refptr<RefcountedProfileKeyedService>
+ BuildWebDataService(Profile* profile) {
+ return new FakeWebDataService();
+ }
+
protected:
base::WeakPtrFactory<SyncAutofillDataTypeControllerTest> weak_ptr_factory_;
MessageLoopForUI message_loop_;
content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread db_thread_;
scoped_refptr<NiceMock<SharedChangeProcessorMock> > change_processor_;
ProfileSyncComponentsFactoryMock profile_sync_factory_;
ProfileSyncServiceMock service_;
ProfileMock profile_;
- scoped_refptr<FakeWebDataService> web_data_service_;
scoped_refptr<AutofillDataTypeController> autofill_dtc_;
// Stores arguments of most recent call of OnStartFinished().
@@ -126,7 +132,10 @@ class SyncAutofillDataTypeControllerTest : public testing::Test {
// immediately try to start association and fail (due to missing DB
// thread).
TEST_F(SyncAutofillDataTypeControllerTest, StartWDSReady) {
- web_data_service_->LoadDatabase();
+ FakeWebDataService* web_db =
+ static_cast<FakeWebDataService*>(WebDataServiceFactory::GetForProfile(
+ &profile_, Profile::EXPLICIT_ACCESS).get());
+ web_db->LoadDatabase();
autofill_dtc_->Start(
base::Bind(&SyncAutofillDataTypeControllerTest::OnStartFinished,
weak_ptr_factory_.GetWeakPtr()));
@@ -149,7 +158,10 @@ TEST_F(SyncAutofillDataTypeControllerTest, StartWDSNotReady) {
EXPECT_FALSE(last_start_error_.IsSet());
EXPECT_EQ(DataTypeController::MODEL_STARTING, autofill_dtc_->state());
- web_data_service_->LoadDatabase();
+ FakeWebDataService* web_db =
+ static_cast<FakeWebDataService*>(WebDataServiceFactory::GetForProfile(
+ &profile_, Profile::EXPLICIT_ACCESS).get());
+ web_db->LoadDatabase();
EXPECT_EQ(DataTypeController::ASSOCIATION_FAILED, last_start_result_);
EXPECT_TRUE(last_start_error_.IsSet());
diff --git a/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc b/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc
index 4e891e4..0c04694 100644
--- a/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc
+++ b/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/sync/profile_sync_components_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
@@ -54,7 +55,8 @@ void AutofillProfileDataTypeController::OnPersonalDataChanged() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK_EQ(state(), MODEL_STARTING);
personal_data_->RemoveObserver(this);
- web_data_service_ = profile()->GetWebDataService(Profile::IMPLICIT_ACCESS);
+ web_data_service_ = WebDataServiceFactory::GetForProfile(
+ profile(), Profile::IMPLICIT_ACCESS);
if (web_data_service_.get() && web_data_service_->IsDatabaseLoaded()) {
DoStartAssociationAsync();
} else {
@@ -84,7 +86,8 @@ bool AutofillProfileDataTypeController::StartModels() {
return false;
}
- web_data_service_ = profile()->GetWebDataService(Profile::IMPLICIT_ACCESS);
+ web_data_service_ = WebDataServiceFactory::GetForProfile(
+ profile(), Profile::IMPLICIT_ACCESS);
if (web_data_service_.get() && web_data_service_->IsDatabaseLoaded()) {
return true;
} else {
diff --git a/chrome/browser/sync/profile_sync_components_factory_impl.cc b/chrome/browser/sync/profile_sync_components_factory_impl.cc
index e3e182df..f3f5e0d 100644
--- a/chrome/browser/sync/profile_sync_components_factory_impl.cc
+++ b/chrome/browser/sync/profile_sync_components_factory_impl.cc
@@ -47,6 +47,7 @@
#include "chrome/browser/webdata/autocomplete_syncable_service.h"
#include "chrome/browser/webdata/autofill_profile_syncable_service.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
@@ -87,7 +88,12 @@ ProfileSyncComponentsFactoryImpl::ProfileSyncComponentsFactoryImpl(
: profile_(profile),
command_line_(command_line),
extension_system_(
- ExtensionSystem::Get(profile)) {
+ ExtensionSystemFactory::GetForProfile(profile)),
+ web_data_service_(WebDataServiceFactory::GetForProfile(
+ profile_, Profile::IMPLICIT_ACCESS)) {
+}
+
+ProfileSyncComponentsFactoryImpl::~ProfileSyncComponentsFactoryImpl() {
}
void ProfileSyncComponentsFactoryImpl::RegisterDataTypes(
@@ -227,14 +233,14 @@ base::WeakPtr<SyncableService> ProfileSyncComponentsFactoryImpl::
return profile_->GetPrefs()->GetSyncableService()->AsWeakPtr();
case syncable::AUTOFILL:
case syncable::AUTOFILL_PROFILE: {
- WebDataService* wds =
- profile_->GetWebDataService(Profile::IMPLICIT_ACCESS);
- if (!wds)
+ if (!web_data_service_.get())
return base::WeakPtr<SyncableService>();
- if (type == syncable::AUTOFILL)
- return wds->GetAutocompleteSyncableService()->AsWeakPtr();
- else
- return wds->GetAutofillProfileSyncableService()->AsWeakPtr();
+ if (type == syncable::AUTOFILL) {
+ return web_data_service_->GetAutocompleteSyncableService()->AsWeakPtr();
+ } else {
+ return web_data_service_->
+ GetAutofillProfileSyncableService()->AsWeakPtr();
+ }
}
case syncable::APPS:
case syncable::EXTENSIONS:
diff --git a/chrome/browser/sync/profile_sync_components_factory_impl.h b/chrome/browser/sync/profile_sync_components_factory_impl.h
index 7e7ccf2..d5aa6a0 100644
--- a/chrome/browser/sync/profile_sync_components_factory_impl.h
+++ b/chrome/browser/sync/profile_sync_components_factory_impl.h
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chrome/browser/sync/profile_sync_components_factory.h"
+#include "chrome/browser/webdata/web_data_service.h"
class CommandLine;
class ExtensionSystem;
@@ -20,7 +21,7 @@ class ProfileSyncComponentsFactoryImpl : public ProfileSyncComponentsFactory {
public:
ProfileSyncComponentsFactoryImpl(Profile* profile,
CommandLine* command_line);
- virtual ~ProfileSyncComponentsFactoryImpl() {}
+ virtual ~ProfileSyncComponentsFactoryImpl();
virtual void RegisterDataTypes(ProfileSyncService* pss) OVERRIDE;
@@ -66,6 +67,7 @@ class ProfileSyncComponentsFactoryImpl : public ProfileSyncComponentsFactory {
// Set on the UI thread (since ExtensionSystemFactory is non-threadsafe);
// accessed on both the UI and FILE threads in GetSyncableServiceForType.
ExtensionSystem* extension_system_;
+ scoped_refptr<WebDataService> web_data_service_;
DISALLOW_COPY_AND_ASSIGN(ProfileSyncComponentsFactoryImpl);
};
diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
index ee33b8c..2e42c17 100644
--- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
@@ -42,6 +42,8 @@
#include "chrome/browser/webdata/autofill_profile_syncable_service.h"
#include "chrome/browser/webdata/autofill_table.h"
#include "chrome/browser/webdata/web_database.h"
+#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/net/gaia/gaia_constants.h"
#include "content/public/browser/notification_source.h"
@@ -160,11 +162,19 @@ syncable::ModelType GetModelType<AutofillProfile>() {
class WebDataServiceFake : public WebDataService {
public:
- explicit WebDataServiceFake(WebDatabase* web_database)
- : web_database_(web_database),
+ WebDataServiceFake()
+ : web_database_(NULL),
syncable_service_created_or_destroyed_(false, false) {
}
+ static scoped_refptr<RefcountedProfileKeyedService> Build(Profile* profile) {
+ return new WebDataServiceFake;
+ }
+
+ void SetDatabase(WebDatabase* web_database) {
+ web_database_ = web_database;
+ }
+
void StartSyncableService() {
// The |autofill_profile_syncable_service_| must be constructed on the DB
// thread.
@@ -219,6 +229,8 @@ class WebDataServiceFake : public WebDataService {
return autofill_profile_syncable_service_;
}
+ virtual void ShutdownOnUIThread() OVERRIDE {}
+
private:
virtual ~WebDataServiceFake() {}
@@ -345,6 +357,8 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest {
protected:
ProfileSyncServiceAutofillTest() {
}
+ virtual ~ProfileSyncServiceAutofillTest() {
+ }
AutofillProfileFactory profile_factory_;
AutofillEntryFactory entry_factory_;
@@ -364,7 +378,10 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest {
AbstractProfileSyncServiceTest::SetUp();
profile_.CreateRequestContext();
web_database_.reset(new WebDatabaseFake(&autofill_table_));
- web_data_service_ = new WebDataServiceFake(web_database_.get());
+ web_data_service_ = static_cast<WebDataServiceFake*>(
+ WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ &profile_, WebDataServiceFake::Build).get());
+ web_data_service_->SetDatabase(web_database_.get());
personal_data_manager_ = static_cast<PersonalDataManagerMock*>(
PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse(
&profile_, PersonalDataManagerMock::Build));
@@ -377,12 +394,7 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest {
WillRepeatedly(Return(static_cast<HistoryService*>(NULL)));
EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1);
EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1);
- EXPECT_CALL(profile_, GetWebDataService(_)).
- // TokenService::Initialize
- // AutofillDataTypeController::StartModels()
- // In some tests:
- // AutofillProfileSyncableService::AutofillProfileSyncableService()
- WillRepeatedly(Return(web_data_service_.get()));
+
personal_data_manager_->Init(&profile_);
// Note: This must be called *after* the notification service is created.
diff --git a/chrome/browser/sync/profile_sync_service_factory.cc b/chrome/browser/sync/profile_sync_service_factory.cc
index ddca10e..7ef2275 100644
--- a/chrome/browser/sync/profile_sync_service_factory.cc
+++ b/chrome/browser/sync/profile_sync_service_factory.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/global_error_service_factory.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/pref_names.h"
// static
@@ -54,13 +55,13 @@ ProfileSyncServiceFactory::ProfileSyncServiceFactory()
DependsOn(SigninManagerFactory::GetInstance());
DependsOn(PasswordStoreFactory::GetInstance());
DependsOn(ExtensionSystemFactory::GetInstance());
+ DependsOn(WebDataServiceFactory::GetInstance());
// The following have not been converted to ProfileKeyedServices yet, and for
// now they are explicitly destroyed after the ProfileDependencyManager is
// told to DestroyProfileServices, so they will be around when the
// ProfileSyncService is destroyed.
- // DependsOn(WebDataServiceFactory::GetInstance());
// DependsOn(HistoryServiceFactory::GetInstance());
// DependsOn(BookmarkBarModelFactory::GetInstance());
// DependsOn(FaviconServiceFactory::GetInstance());
diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
index fdf0790..2282a67 100644
--- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc
@@ -40,6 +40,7 @@ class ProfileSyncServiceStartupTest : public testing::Test {
public:
ProfileSyncServiceStartupTest()
: ui_thread_(BrowserThread::UI, &ui_loop_),
+ db_thread_(BrowserThread::DB),
file_thread_(BrowserThread::FILE),
io_thread_(BrowserThread::IO),
profile_(new TestingProfile) {}
@@ -98,6 +99,7 @@ class ProfileSyncServiceStartupTest : public testing::Test {
MessageLoop ui_loop_;
content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread db_thread_;
content::TestBrowserThread file_thread_;
content::TestBrowserThread io_thread_;
scoped_ptr<TestingProfile> profile_;
diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc
index 54bd7ac..d5ed7a8 100644
--- a/chrome/browser/sync/profile_sync_service_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_unittest.cc
@@ -47,6 +47,7 @@ class ProfileSyncServiceTest : public testing::Test {
protected:
ProfileSyncServiceTest()
: ui_thread_(BrowserThread::UI, &ui_loop_),
+ db_thread_(BrowserThread::DB),
file_thread_(BrowserThread::FILE),
io_thread_(BrowserThread::IO) {}
@@ -144,6 +145,7 @@ class ProfileSyncServiceTest : public testing::Test {
MessageLoop ui_loop_;
// Needed by |service_|.
content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread db_thread_;
// Needed by DisableAndEnableSyncTemporarily test case.
content::TestBrowserThread file_thread_;
// Needed by |service| and |profile_|'s request context.
diff --git a/chrome/browser/sync/test/integration/autofill_helper.cc b/chrome/browser/sync/test/integration/autofill_helper.cc
index 7f2dd3b..f9c7e31 100644
--- a/chrome/browser/sync/test/integration/autofill_helper.cc
+++ b/chrome/browser/sync/test/integration/autofill_helper.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/webdata/autofill_entry.h"
#include "chrome/browser/webdata/autofill_table.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/browser/webdata/web_database.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/test/base/thread_observer_helper.h"
@@ -60,7 +61,8 @@ void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) {
EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)).
WillOnce(SignalEvent(&done_event));
- WebDataService* wds = autofill_helper::GetWebDataService(profile);
+ scoped_refptr<WebDataService> wds =
+ autofill_helper::GetWebDataService(profile);
wds->RemoveFormValueForElementName(key.name(), key.value());
done_event.Wait();
}
@@ -146,8 +148,9 @@ AutofillProfile CreateAutofillProfile(ProfileType type) {
return profile;
}
-WebDataService* GetWebDataService(int index) {
- return test()->GetProfile(index)->GetWebDataService(Profile::EXPLICIT_ACCESS);
+scoped_refptr<WebDataService> GetWebDataService(int index) {
+ return WebDataServiceFactory::GetForProfile(
+ test()->GetProfile(index), Profile::EXPLICIT_ACCESS);
}
PersonalDataManager* GetPersonalDataManager(int index) {
@@ -172,7 +175,7 @@ void AddKeys(int profile, const std::set<AutofillKey>& keys) {
EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)).
WillOnce(SignalEvent(&done_event));
- WebDataService* wds = GetWebDataService(profile);
+ scoped_refptr<WebDataService> wds = GetWebDataService(profile);
wds->AddFormFields(form_fields);
done_event.Wait();
BlockForPendingDBThreadTasks();
@@ -193,7 +196,7 @@ void RemoveKeys(int profile) {
}
std::set<AutofillEntry> GetAllKeys(int profile) {
- WebDataService* wds = GetWebDataService(profile);
+ scoped_refptr<WebDataService> wds = GetWebDataService(profile);
std::vector<AutofillEntry> all_entries = GetAllAutofillEntries(wds);
std::set<AutofillEntry> all_keys;
for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin();
diff --git a/chrome/browser/sync/test/integration/autofill_helper.h b/chrome/browser/sync/test/integration/autofill_helper.h
index 51950ef..1df0316 100644
--- a/chrome/browser/sync/test/integration/autofill_helper.h
+++ b/chrome/browser/sync/test/integration/autofill_helper.h
@@ -11,6 +11,7 @@
#include <vector>
#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
#include "base/string16.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
@@ -31,7 +32,7 @@ enum ProfileType {
};
// Used to access the web data service within a particular sync profile.
-WebDataService* GetWebDataService(int index) WARN_UNUSED_RESULT;
+scoped_refptr<WebDataService> GetWebDataService(int index) WARN_UNUSED_RESULT;
// Used to access the personal data manager within a particular sync profile.
PersonalDataManager* GetPersonalDataManager(int index) WARN_UNUSED_RESULT;
diff --git a/chrome/browser/ui/intents/web_intent_picker_controller_browsertest.cc b/chrome/browser/ui/intents/web_intent_picker_controller_browsertest.cc
index 12cf715..df67227 100644
--- a/chrome/browser/ui/intents/web_intent_picker_controller_browsertest.cc
+++ b/chrome/browser/ui/intents/web_intent_picker_controller_browsertest.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/ui/intents/web_intent_picker_model_observer.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
@@ -230,8 +231,8 @@ class WebIntentPickerControllerBrowserTest : public InProcessBrowserTest {
fake_url_fetcher_factory_.reset(
new FakeURLFetcherFactory(default_url_fetcher_factory_.get()));
- web_data_service_ =
- GetBrowser()->profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ web_data_service_ = WebDataServiceFactory::GetForProfile(
+ GetBrowser()->profile(), Profile::EXPLICIT_ACCESS);
favicon_service_ =
GetBrowser()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS);
controller_ = GetBrowser()->
@@ -323,7 +324,7 @@ class WebIntentPickerControllerBrowserTest : public InProcessBrowserTest {
}
WebIntentPickerMock picker_;
- WebDataService* web_data_service_;
+ scoped_refptr<WebDataService> web_data_service_;
FaviconService* favicon_service_;
WebIntentPickerController* controller_;
scoped_ptr<DummyURLFetcherFactory> default_url_fetcher_factory_;
diff --git a/chrome/browser/ui/intents/web_intents_model_unittest.cc b/chrome/browser/ui/intents/web_intents_model_unittest.cc
index 7375727..05a84b4 100644
--- a/chrome/browser/ui/intents/web_intents_model_unittest.cc
+++ b/chrome/browser/ui/intents/web_intents_model_unittest.cc
@@ -34,9 +34,12 @@ class WebIntentsModelTest : public testing::Test {
}
virtual void TearDown() {
- if (wds_.get())
- wds_->Shutdown();
-
+ wds_->ShutdownOnUIThread();
+ wds_ = NULL;
+ base::WaitableEvent done(false, false);
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
+ done.Wait();
db_thread_.Stop();
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
MessageLoop::current()->Run();
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index 6cf2631..ee99257 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -28,6 +28,9 @@
#include "chrome/browser/webdata/web_intents_table.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_notification_types.h"
+#ifdef DEBUG
+#include "content/public/browser/browser_thread.h"
+#endif
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
@@ -78,14 +81,19 @@ WDKeywordsResult::WDKeywordsResult()
WDKeywordsResult::~WDKeywordsResult() {}
WebDataService::WebDataService()
- : is_running_(false),
- db_(NULL),
- autocomplete_syncable_service_(NULL),
- autofill_profile_syncable_service_(NULL),
- failed_init_(false),
- should_commit_(false),
- next_request_handle_(1),
- main_loop_(MessageLoop::current()) {
+ : RefcountedProfileKeyedService(BrowserThread::UI),
+ is_running_(false),
+ db_(NULL),
+ autocomplete_syncable_service_(NULL),
+ autofill_profile_syncable_service_(NULL),
+ failed_init_(false),
+ should_commit_(false),
+ next_request_handle_(1),
+ main_loop_(MessageLoop::current()) {
+ // WebDataService requires DB thread if instantiated.
+ // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL)
+ // if you do not want to instantiate WebDataService in your test.
+ DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB));
}
// static
@@ -102,18 +110,18 @@ void WebDataService::NotifyOfMultipleAutofillChanges(
make_scoped_refptr(web_data_service)));
}
+void WebDataService::ShutdownOnUIThread() {
+ ScheduleTask(FROM_HERE,
+ Bind(&WebDataService::ShutdownSyncableServices, this));
+ UnloadDatabase();
+}
+
bool WebDataService::Init(const FilePath& profile_path) {
FilePath path = profile_path;
path = path.Append(chrome::kWebDataFilename);
return InitWithPath(path);
}
-void WebDataService::Shutdown() {
- ScheduleTask(FROM_HERE,
- Bind(&WebDataService::ShutdownSyncableServices, this));
- UnloadDatabase();
-}
-
bool WebDataService::IsRunning() const {
return is_running_;
}
@@ -554,6 +562,7 @@ void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween(
WebDataService::~WebDataService() {
if (is_running_ && db_) {
DLOG_ASSERT("WebDataService dtor called without Shutdown");
+ NOTREACHED();
}
}
@@ -565,7 +574,9 @@ bool WebDataService::InitWithPath(const FilePath& path) {
// [ http://crbug.com/100745 ], call |AutofillCountry::ApplicationLocale()| to
// cache the application locale before we try to access it on the DB thread.
// This should be safe to remove once [ http://crbug.com/100845 ] is fixed.
- AutofillCountry::ApplicationLocale();
+ // Do not do it if the thread is not UI (can happen only in some tests).
+ if (BrowserThread::CurrentlyOn(BrowserThread::UI))
+ AutofillCountry::ApplicationLocale();
ScheduleTask(FROM_HERE,
Bind(&WebDataService::InitializeDatabaseIfNecessary, this));
diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h
index aea638a..49d327c 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -20,6 +20,7 @@
#include "base/message_loop_helpers.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
+#include "chrome/browser/profiles/refcounted_profile_keyed_service.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_id.h"
#include "chrome/browser/webdata/keyword_table.h"
@@ -184,9 +185,7 @@ template <class T> class WDObjectResult : public WDTypedResult {
class WebDataServiceConsumer;
-class WebDataService
- : public base::RefCountedThreadSafe<
- WebDataService, content::BrowserThread::DeleteOnUIThread> {
+class WebDataService : public RefcountedProfileKeyedService {
public:
// All requests return an opaque handle of the following type.
typedef int Handle;
@@ -300,14 +299,15 @@ class WebDataService
// |web_data_service| may be NULL for testing purposes.
static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service);
+ // RefcountedProfileKeyedService override:
+ // Shutdown the web data service. The service can no longer be used after this
+ // call.
+ virtual void ShutdownOnUIThread() OVERRIDE;
+
// Initializes the web data service. Returns false on failure
// Takes the path of the profile directory as its argument.
bool Init(const FilePath& profile_path);
- // Shutdown the web data service. The service can no longer be used after this
- // call.
- void Shutdown();
-
// Returns false if Shutdown() has been called.
bool IsRunning() const;
diff --git a/chrome/browser/webdata/web_data_service_factory.cc b/chrome/browser/webdata/web_data_service_factory.cc
new file mode 100644
index 0000000..d86b80d
--- /dev/null
+++ b/chrome/browser/webdata/web_data_service_factory.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2012 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 "chrome/browser/webdata/web_data_service_factory.h"
+
+#include "base/file_path.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/common/chrome_constants.h"
+
+WebDataServiceFactory::WebDataServiceFactory()
+ : RefcountedProfileKeyedServiceFactory(
+ "WebDataService",
+ ProfileDependencyManager::GetInstance()) {
+ // WebDataServiceFactory has no dependecies.
+}
+
+WebDataServiceFactory::~WebDataServiceFactory() {}
+
+// static
+scoped_refptr<WebDataService> WebDataServiceFactory::GetForProfile(
+ Profile* profile, Profile::ServiceAccessType access_type) {
+ DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
+ return static_cast<WebDataService*>(
+ GetInstance()->GetServiceForProfile(profile, true).get());
+}
+
+// static
+scoped_refptr<WebDataService> WebDataServiceFactory::GetForProfileIfExists(
+ Profile* profile, Profile::ServiceAccessType access_type) {
+ DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
+ return static_cast<WebDataService*>(
+ GetInstance()->GetServiceForProfile(profile, false).get());
+}
+
+// static
+WebDataServiceFactory* WebDataServiceFactory::GetInstance() {
+ return Singleton<WebDataServiceFactory>::get();
+}
+
+bool WebDataServiceFactory::ServiceRedirectedInIncognito() {
+ return false;
+}
+
+scoped_refptr<RefcountedProfileKeyedService>
+WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const {
+ DCHECK(profile);
+
+ FilePath path = profile->GetPath();
+ path = path.Append(chrome::kWebDataFilename);
+
+ scoped_refptr<WebDataService> wds(new WebDataService());
+ if (!wds->Init(profile->GetPath()))
+ NOTREACHED();
+ return wds.get();
+}
+
+bool WebDataServiceFactory::ServiceIsNULLWhileTesting() {
+ return true;
+}
diff --git a/chrome/browser/webdata/web_data_service_factory.h b/chrome/browser/webdata/web_data_service_factory.h
new file mode 100644
index 0000000..78c179b
--- /dev/null
+++ b/chrome/browser/webdata/web_data_service_factory.h
@@ -0,0 +1,44 @@
+// Copyright (c) 2012 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 CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__
+#define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/memory/singleton.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h"
+
+class WebDataService;
+
+class WebDataServiceFactory : public RefcountedProfileKeyedServiceFactory {
+ public:
+ // Returns the |WebDataService| associated with the |profile|.
+ // |access_type| is either EXPLICIT_ACCESS or IMPLICIT_ACCESS
+ // (see its definition).
+ static scoped_refptr<WebDataService> GetForProfile(
+ Profile* profile, Profile::ServiceAccessType access_type);
+
+ // Similar to GetForProfile(), but won't create the web data service if it
+ // doesn't already exist.
+ static scoped_refptr<WebDataService> GetForProfileIfExists(
+ Profile* profile, Profile::ServiceAccessType access_type);
+
+ static WebDataServiceFactory* GetInstance();
+
+ private:
+ friend struct DefaultSingletonTraits<WebDataServiceFactory>;
+
+ WebDataServiceFactory();
+ virtual ~WebDataServiceFactory();
+
+ // |ProfileKeyedBaseFactory| methods:
+ virtual bool ServiceRedirectedInIncognito() OVERRIDE;
+ virtual scoped_refptr<RefcountedProfileKeyedService> BuildServiceInstanceFor(
+ Profile* profile) const OVERRIDE;
+ virtual bool ServiceIsNULLWhileTesting() OVERRIDE;
+};
+
+#endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_FACTORY_H__
diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc
index 4cb1927..1023bb1 100644
--- a/chrome/browser/webdata/web_data_service_unittest.cc
+++ b/chrome/browser/webdata/web_data_service_unittest.cc
@@ -88,8 +88,12 @@ class WebDataServiceTest : public testing::Test {
}
virtual void TearDown() {
- if (wds_.get())
- wds_->Shutdown();
+ wds_->ShutdownOnUIThread();
+ wds_ = NULL;
+ base::WaitableEvent done(false, false);
+ BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
+ done.Wait();
db_thread_.Stop();
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());