summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--android_webview/browser/aw_form_database_service.cc8
-rw-r--r--android_webview/browser/aw_form_database_service.h4
-rw-r--r--android_webview/native/aw_form_database.cc2
-rw-r--r--chrome/browser/browsing_data/browsing_data_remover.cc8
-rw-r--r--chrome/browser/search_engines/template_url_service_test_util.cc32
-rw-r--r--chrome/browser/signin/token_service.cc7
-rw-r--r--chrome/browser/signin/token_service.h6
-rw-r--r--chrome/browser/sync/glue/autofill_data_type_controller.cc6
-rw-r--r--chrome/browser/sync/glue/autofill_data_type_controller.h5
-rw-r--r--chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc12
-rw-r--r--chrome/browser/sync/glue/autofill_profile_data_type_controller.cc2
-rw-r--r--chrome/browser/sync/glue/autofill_profile_data_type_controller.h2
-rw-r--r--chrome/browser/sync/profile_sync_components_factory_impl.cc6
-rw-r--r--chrome/browser/sync/profile_sync_components_factory_impl.h2
-rw-r--r--chrome/browser/sync/profile_sync_service_autofill_unittest.cc12
-rw-r--r--chrome/browser/sync/test/integration/autofill_helper.cc28
-rw-r--r--chrome/browser/sync/test/integration/autofill_helper.h2
-rw-r--r--chrome/browser/webdata/token_web_data.cc6
-rw-r--r--chrome/browser/webdata/token_web_data.h7
-rw-r--r--chrome/browser/webdata/web_data_service.h11
-rw-r--r--chrome/browser/webdata/web_data_service_factory.cc33
-rw-r--r--chrome/browser/webdata/web_data_service_factory.h9
-rw-r--r--chrome/chrome_tests_unit.gypi4
-rw-r--r--components/autofill/browser/autocomplete_history_manager.cc8
-rw-r--r--components/autofill/browser/autocomplete_history_manager.h2
-rw-r--r--components/autofill/browser/autocomplete_history_manager_unittest.cc60
-rw-r--r--components/autofill/browser/personal_data_manager.cc72
-rw-r--r--components/autofill/browser/personal_data_manager_unittest.cc4
-rw-r--r--components/autofill/browser/webdata/autofill_webdata_service.h6
-rw-r--r--components/autofill/browser/webdata/web_data_service_unittest.cc14
-rw-r--r--components/webdata/common/web_data_service_base.h17
-rw-r--r--components/webdata/common/web_data_service_test_util.cc12
-rw-r--r--components/webdata/common/web_data_service_test_util.h13
33 files changed, 225 insertions, 197 deletions
diff --git a/android_webview/browser/aw_form_database_service.cc b/android_webview/browser/aw_form_database_service.cc
index d08ed0e..4958cb8 100644
--- a/android_webview/browser/aw_form_database_service.cc
+++ b/android_webview/browser/aw_form_database_service.cc
@@ -34,8 +34,8 @@ AwFormDatabaseService::AwFormDatabaseService(const base::FilePath path)
l10n_util::GetDefaultLocale())));
web_database_->LoadDatabase();
- autofill_data_ = new autofill::AutofillWebDataService(
- web_database_, base::Bind(&DatabaseErrorCallback));
+ autofill_data_ .reset(new autofill::AutofillWebDataService(
+ web_database_, base::Bind(&DatabaseErrorCallback)));
autofill_data_->Init();
}
@@ -58,9 +58,9 @@ void AwFormDatabaseService::CancelPendingQuery() {
}
}
-scoped_refptr<autofill::AutofillWebDataService>
+autofill::AutofillWebDataService*
AwFormDatabaseService::get_autofill_webdata_service() {
- return autofill_data_;
+ return autofill_data_.get();
}
void AwFormDatabaseService::ClearFormData() {
diff --git a/android_webview/browser/aw_form_database_service.h b/android_webview/browser/aw_form_database_service.h
index cb66d4e..ad1af3ee 100644
--- a/android_webview/browser/aw_form_database_service.h
+++ b/android_webview/browser/aw_form_database_service.h
@@ -33,7 +33,7 @@ class AwFormDatabaseService : public WebDataServiceConsumer {
// Clear any saved form data. Executes asynchronously.
void ClearFormData();
- scoped_refptr<autofill::AutofillWebDataService>
+ autofill::AutofillWebDataService*
get_autofill_webdata_service();
// WebDataServiceConsumer implementation.
@@ -52,7 +52,7 @@ class AwFormDatabaseService : public WebDataServiceConsumer {
bool has_form_data_;
base::WaitableEvent completion_;
- scoped_refptr<autofill::AutofillWebDataService> autofill_data_;
+ scoped_ptr<autofill::AutofillWebDataService> autofill_data_;
scoped_refptr<WebDatabaseService> web_database_;
DISALLOW_COPY_AND_ASSIGN(AwFormDatabaseService);
diff --git a/android_webview/native/aw_form_database.cc b/android_webview/native/aw_form_database.cc
index 5ebdf12..6979b0b 100644
--- a/android_webview/native/aw_form_database.cc
+++ b/android_webview/native/aw_form_database.cc
@@ -14,7 +14,7 @@
#include "jni/AwFormDatabase_jni.h"
// static
-scoped_refptr<autofill::AutofillWebDataService>
+autofill::AutofillWebDataService*
autofill::AutofillWebDataService::FromBrowserContext(
content::BrowserContext* context) {
diff --git a/chrome/browser/browsing_data/browsing_data_remover.cc b/chrome/browser/browsing_data/browsing_data_remover.cc
index 1b74264..e1114c4 100644
--- a/chrome/browser/browsing_data/browsing_data_remover.cc
+++ b/chrome/browser/browsing_data/browsing_data_remover.cc
@@ -314,9 +314,9 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask,
// The saved Autofill profiles and credit cards can include the origin from
// which these profiles and credit cards were learned. These are a form of
// history, so clear them as well.
- scoped_refptr<autofill::AutofillWebDataService> web_data_service =
+ autofill::AutofillWebDataService* web_data_service =
autofill::AutofillWebDataService::FromBrowserContext(profile_);
- if (web_data_service.get()) {
+ if (web_data_service) {
waiting_for_clear_autofill_origin_urls_ = true;
web_data_service->RemoveOriginURLsModifiedBetween(
delete_begin_, delete_end_);
@@ -462,10 +462,10 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask,
if (remove_mask & REMOVE_FORM_DATA) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
- scoped_refptr<autofill::AutofillWebDataService> web_data_service =
+ autofill::AutofillWebDataService* web_data_service =
autofill::AutofillWebDataService::FromBrowserContext(profile_);
- if (web_data_service.get()) {
+ if (web_data_service) {
waiting_for_clear_form_ = true;
web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
delete_end_);
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 34894ab..d5bfdcf 100644
--- a/chrome/browser/search_engines/template_url_service_test_util.cc
+++ b/chrome/browser/search_engines/template_url_service_test_util.cc
@@ -19,6 +19,8 @@
#include "chrome/test/automation/value_conversion_util.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
+#include "components/webdata/common/web_data_service_test_util.h"
+#include "components/webdata/common/web_database_service.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -54,6 +56,32 @@ static void WaitForThreadToProcessRequests(BrowserThread::ID identifier) {
} // namespace
+class MockWebDataServiceWrapperDB : public MockWebDataServiceWrapper {
+ public:
+ static BrowserContextKeyedService* Build(content::BrowserContext* profile) {
+ return new MockWebDataServiceWrapperDB(static_cast<Profile*>(profile));
+ }
+
+ explicit MockWebDataServiceWrapperDB(Profile* profile)
+ : MockWebDataServiceWrapper(NULL, NULL, NULL) {
+ base::FilePath profile_path = profile->GetPath();
+ base::FilePath path = profile_path.AppendASCII("TestWebDB");
+ web_database_ = new WebDatabaseService(path);
+ web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new KeywordTable()));
+ fake_web_data_ = new WebDataService(
+ web_database_, WebDataServiceBase::ProfileErrorCallback());
+ fake_web_data_->Init();
+ }
+
+ virtual void Shutdown() OVERRIDE {
+ fake_web_data_->ShutdownDatabase();
+ }
+
+ private:
+ scoped_refptr<WebDatabaseService> web_database_;
+ DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapperDB);
+};
+
// Trivial subclass of TemplateURLService that records the last invocation of
// SetKeywordSearchTermsForURL.
class TestingTemplateURLService : public TemplateURLService {
@@ -100,7 +128,9 @@ void TemplateURLServiceTestUtil::SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
profile_.reset(new TestingProfile(temp_dir_.path()));
db_thread_.Start();
- profile_->CreateWebDataService();
+
+ WebDataServiceFactory::GetInstance()->SetTestingFactory(
+ profile_.get(), MockWebDataServiceWrapperDB::Build);
TemplateURLService* service = static_cast<TemplateURLService*>(
TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
diff --git a/chrome/browser/signin/token_service.cc b/chrome/browser/signin/token_service.cc
index 2237ada..51eee1e 100644
--- a/chrome/browser/signin/token_service.cc
+++ b/chrome/browser/signin/token_service.cc
@@ -49,6 +49,7 @@ const char* kServices[] = {
TokenService::TokenService()
: profile_(NULL),
+ token_web_data_(NULL),
token_loading_query_(0),
tokens_loaded_(false) {
// Allow constructor to be called outside the UI thread, so it can be mocked
@@ -175,20 +176,20 @@ void TokenService::UpdateCredentialsWithOAuth2(
void TokenService::LoadTokensFromDB() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (token_web_data_.get())
+ if (token_web_data_)
token_loading_query_ = token_web_data_->GetAllTokens(this);
}
void TokenService::SaveAuthTokenToDB(const std::string& service,
const std::string& auth_token) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (token_web_data_.get())
+ if (token_web_data_)
token_web_data_->SetTokenForService(service, auth_token);
}
void TokenService::EraseTokensFromDB() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (token_web_data_.get())
+ if (token_web_data_)
token_web_data_->RemoveAllTokens();
content::NotificationService::current()->Notify(
diff --git a/chrome/browser/signin/token_service.h b/chrome/browser/signin/token_service.h
index 5ab612cc..ebe9595 100644
--- a/chrome/browser/signin/token_service.h
+++ b/chrome/browser/signin/token_service.h
@@ -228,8 +228,10 @@ class TokenService : public GaiaAuthConsumer,
// The profile with which this instance was initialized, or NULL.
Profile* profile_;
- // Web data service to access tokens from.
- scoped_refptr<TokenWebData> token_web_data_;
+ // Web data service to access tokens from. Owned by WebDataServiceWrapper,
+ // which outlives TokenService.
+ TokenWebData* token_web_data_;
+
// Getter to use for fetchers.
scoped_refptr<net::URLRequestContextGetter> getter_;
// Request handle to load Gaia tokens from DB.
diff --git a/chrome/browser/sync/glue/autofill_data_type_controller.cc b/chrome/browser/sync/glue/autofill_data_type_controller.cc
index a9d666a..d53f47d 100644
--- a/chrome/browser/sync/glue/autofill_data_type_controller.cc
+++ b/chrome/browser/sync/glue/autofill_data_type_controller.cc
@@ -86,7 +86,7 @@ void AutofillDataTypeController::StartAssociating(
ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile(
profile());
DCHECK(sync);
- scoped_refptr<autofill::AutofillWebDataService> web_data_service =
+ autofill::AutofillWebDataService* web_data_service =
autofill::AutofillWebDataService::FromBrowserContext(profile());
bool cull_expired_entries = sync->current_experiments().autofill_culling;
// First, post the update task to the DB thread, which guarantees us it
@@ -104,10 +104,10 @@ void AutofillDataTypeController::StartAssociating(
void AutofillDataTypeController::UpdateAutofillCullingSettings(
bool cull_expired_entries,
- scoped_refptr<autofill::AutofillWebDataService> web_data_service) {
+ autofill::AutofillWebDataService* web_data_service) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
AutocompleteSyncableService* service =
- AutocompleteSyncableService::FromWebDataService(web_data_service.get());
+ AutocompleteSyncableService::FromWebDataService(web_data_service);
if (!service) {
DVLOG(1) << "Can't update culling, no AutocompleteSyncableService.";
return;
diff --git a/chrome/browser/sync/glue/autofill_data_type_controller.h b/chrome/browser/sync/glue/autofill_data_type_controller.h
index bb513d3..3991436 100644
--- a/chrome/browser/sync/glue/autofill_data_type_controller.h
+++ b/chrome/browser/sync/glue/autofill_data_type_controller.h
@@ -52,8 +52,9 @@ class AutofillDataTypeController
// Self-invoked on the DB thread to call the AutocompleteSyncableService with
// an updated value of autofill culling settings.
- void UpdateAutofillCullingSettings(bool cull_expired_entries,
- scoped_refptr<autofill::AutofillWebDataService> web_data_service);
+ void UpdateAutofillCullingSettings(
+ bool cull_expired_entries,
+ autofill::AutofillWebDataService* web_data_service);
// Callback once WebDatabase has loaded.
void WebDatabaseLoaded();
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 ce020f9..b506b08 100644
--- a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
+++ b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
@@ -106,10 +106,10 @@ class FakeWebDataService : public AutofillWebDataService {
return result;
}
- private:
virtual ~FakeWebDataService() {
}
+ private:
void CreateSyncableService() {
ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
// These services are deleted in DestroySyncableService().
@@ -226,7 +226,7 @@ class SyncAutofillDataTypeControllerTest : public testing::Test {
TEST_F(SyncAutofillDataTypeControllerTest, StartWDSReady) {
FakeWebDataService* web_db =
static_cast<FakeWebDataService*>(
- AutofillWebDataService::FromBrowserContext(&profile_).get());
+ AutofillWebDataService::FromBrowserContext(&profile_));
web_db->LoadDatabase();
autofill_dtc_->LoadModels(
base::Bind(&SyncAutofillDataTypeControllerTest::OnLoadFinished,
@@ -259,7 +259,7 @@ TEST_F(SyncAutofillDataTypeControllerTest, StartWDSNotReady) {
FakeWebDataService* web_db =
static_cast<FakeWebDataService*>(
- AutofillWebDataService::FromBrowserContext(&profile_).get());
+ AutofillWebDataService::FromBrowserContext(&profile_));
web_db->LoadDatabase();
EXPECT_CALL(*change_processor_.get(), Connect(_, _, _, _, _))
@@ -278,13 +278,13 @@ TEST_F(SyncAutofillDataTypeControllerTest, StartWDSNotReady) {
TEST_F(SyncAutofillDataTypeControllerTest, UpdateAutofillCullingSettings) {
FakeWebDataService* web_db =
static_cast<FakeWebDataService*>(
- AutofillWebDataService::FromBrowserContext(&profile_).get());
+ AutofillWebDataService::FromBrowserContext(&profile_));
// Set up the experiments state.
- ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile(
- &profile_);
syncer::Experiments experiments;
experiments.autofill_culling = true;
+ ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile(
+ &profile_);
sync->OnExperimentsChanged(experiments);
web_db->LoadDatabase();
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 a480737..ce416f1 100644
--- a/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc
+++ b/chrome/browser/sync/glue/autofill_profile_data_type_controller.cc
@@ -112,4 +112,4 @@ void AutofillProfileDataTypeController::StopModels() {
personal_data_->RemoveObserver(this);
}
-} // namepsace browser_sync
+} // namespace browser_sync
diff --git a/chrome/browser/sync/glue/autofill_profile_data_type_controller.h b/chrome/browser/sync/glue/autofill_profile_data_type_controller.h
index 3e00748..8e5d4cc 100644
--- a/chrome/browser/sync/glue/autofill_profile_data_type_controller.h
+++ b/chrome/browser/sync/glue/autofill_profile_data_type_controller.h
@@ -48,6 +48,8 @@ class AutofillProfileDataTypeController
void WebDatabaseLoaded();
autofill::PersonalDataManager* personal_data_;
+
+ // Flag to ensure we don't register the WebDB callback multiple times.
bool callback_registered_;
DISALLOW_COPY_AND_ASSIGN(AutofillProfileDataTypeController);
diff --git a/chrome/browser/sync/profile_sync_components_factory_impl.cc b/chrome/browser/sync/profile_sync_components_factory_impl.cc
index 5c997c3..79382a0 100644
--- a/chrome/browser/sync/profile_sync_components_factory_impl.cc
+++ b/chrome/browser/sync/profile_sync_components_factory_impl.cc
@@ -347,14 +347,14 @@ base::WeakPtr<syncer::SyncableService> ProfileSyncComponentsFactoryImpl::
syncer::PRIORITY_PREFERENCES)->AsWeakPtr();
case syncer::AUTOFILL:
case syncer::AUTOFILL_PROFILE: {
- if (!web_data_service_.get())
+ if (!web_data_service_)
return base::WeakPtr<syncer::SyncableService>();
if (type == syncer::AUTOFILL) {
return AutocompleteSyncableService::FromWebDataService(
- web_data_service_.get())->AsWeakPtr();
+ web_data_service_)->AsWeakPtr();
} else {
return AutofillProfileSyncableService::FromWebDataService(
- web_data_service_.get())->AsWeakPtr();
+ web_data_service_)->AsWeakPtr();
}
}
case syncer::APPS:
diff --git a/chrome/browser/sync/profile_sync_components_factory_impl.h b/chrome/browser/sync/profile_sync_components_factory_impl.h
index 03295c2..9502d8c 100644
--- a/chrome/browser/sync/profile_sync_components_factory_impl.h
+++ b/chrome/browser/sync/profile_sync_components_factory_impl.h
@@ -78,7 +78,7 @@ class ProfileSyncComponentsFactoryImpl : public ProfileSyncComponentsFactory {
// non-threadsafe); accessed on both the UI and FILE threads in
// GetSyncableServiceForType.
extensions::ExtensionSystem* extension_system_;
- scoped_refptr<autofill::AutofillWebDataService> web_data_service_;
+ autofill::AutofillWebDataService* 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 f32b7e2..c909fb0 100644
--- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
@@ -226,6 +226,8 @@ class WebDataServiceFake : public AutofillWebDataService {
syncable_service_created_or_destroyed_(false, false) {
}
+ virtual ~WebDataServiceFake() {}
+
void SetDatabase(WebDatabase* web_database) {
web_database_ = web_database;
}
@@ -290,8 +292,6 @@ class WebDataServiceFake : public AutofillWebDataService {
}
private:
- virtual ~WebDataServiceFake() {}
-
void CreateSyncableService(const base::Closure& on_changed_callback) {
ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
// These services are deleted in DestroySyncableService().
@@ -511,7 +511,7 @@ class ProfileSyncServiceAutofillTest
WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse(
profile_.get(), BuildMockWebDataServiceWrapper));
web_data_service_ =
- static_cast<WebDataServiceFake*>(wrapper->GetAutofillWebData().get());
+ static_cast<WebDataServiceFake*>(wrapper->GetAutofillWebData());
web_data_service_->SetDatabase(web_database_.get());
MockPersonalDataManagerService* personal_data_manager_service =
@@ -577,7 +577,7 @@ class ProfileSyncServiceAutofillTest
sync_service_);
factory->SetExpectation(components,
sync_service_,
- web_data_service_.get(),
+ web_data_service_,
data_type_controller);
EXPECT_CALL(*components, CreateDataTypeManager(_, _, _, _, _, _)).
@@ -757,7 +757,7 @@ class ProfileSyncServiceAutofillTest
scoped_ptr<ProfileMock> profile_;
AutofillTableMock autofill_table_;
scoped_ptr<WebDatabaseFake> web_database_;
- scoped_refptr<WebDataServiceFake> web_data_service_;
+ WebDataServiceFake* web_data_service_;
MockPersonalDataManager* personal_data_manager_;
syncer::DataTypeAssociationStats association_stats_;
base::WeakPtrFactory<DataTypeDebugInfoListener> debug_ptr_factory_;
@@ -935,7 +935,7 @@ bool IncludesField(const AutofillProfile& profile1,
return true;
}
-};
+}; // namespace
// TODO(skrul): Test abort startup.
// TODO(skrul): Test processing of cloud changes.
diff --git a/chrome/browser/sync/test/integration/autofill_helper.cc b/chrome/browser/sync/test/integration/autofill_helper.cc
index 31f86e4..eebe432 100644
--- a/chrome/browser/sync/test/integration/autofill_helper.cc
+++ b/chrome/browser/sync/test/integration/autofill_helper.cc
@@ -34,6 +34,8 @@ using autofill::CreditCard;
using autofill::FormFieldData;
using autofill::PersonalDataManager;
using autofill::PersonalDataManagerObserver;
+using base::Bind;
+using base::Unretained;
using base::WaitableEvent;
using content::BrowserThread;
using sync_datatype_helper::test;
@@ -80,13 +82,15 @@ void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) {
EXPECT_CALL(mock_observer, AutofillEntriesChanged(_))
.WillOnce(SignalEvent(&done_event));
- scoped_refptr<AutofillWebDataService> wds =
+ AutofillWebDataService* wds =
autofill_helper::GetWebDataService(profile);
void(AutofillWebDataService::*add_observer_func)(
AutofillWebDataServiceObserverOnDBThread*) =
&AutofillWebDataService::AddObserver;
- RunOnDBThreadAndBlock(Bind(add_observer_func, wds, &mock_observer));
+ RunOnDBThreadAndBlock(Bind(add_observer_func,
+ Unretained(wds),
+ &mock_observer));
wds->RemoveFormValueForElementName(key.name(), key.value());
done_event.Wait();
@@ -94,7 +98,9 @@ void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) {
void(AutofillWebDataService::*remove_observer_func)(
AutofillWebDataServiceObserverOnDBThread*) =
&AutofillWebDataService::RemoveObserver;
- RunOnDBThreadAndBlock(Bind(remove_observer_func, wds, &mock_observer));
+ RunOnDBThreadAndBlock(Bind(remove_observer_func,
+ Unretained(wds),
+ &mock_observer));
}
void GetAllAutofillEntriesOnDBThread(AutofillWebDataService* wds,
@@ -163,7 +169,7 @@ AutofillProfile CreateAutofillProfile(ProfileType type) {
return profile;
}
-scoped_refptr<AutofillWebDataService> GetWebDataService(int index) {
+AutofillWebDataService* GetWebDataService(int index) {
return AutofillWebDataService::FromBrowserContext(test()->GetProfile(index));
}
@@ -188,12 +194,14 @@ void AddKeys(int profile, const std::set<AutofillKey>& keys) {
EXPECT_CALL(mock_observer, AutofillEntriesChanged(_))
.WillOnce(SignalEvent(&done_event));
- scoped_refptr<AutofillWebDataService> wds = GetWebDataService(profile);
+ AutofillWebDataService* wds = GetWebDataService(profile);
void(AutofillWebDataService::*add_observer_func)(
AutofillWebDataServiceObserverOnDBThread*) =
&AutofillWebDataService::AddObserver;
- RunOnDBThreadAndBlock(Bind(add_observer_func, wds, &mock_observer));
+ RunOnDBThreadAndBlock(Bind(add_observer_func,
+ Unretained(wds),
+ &mock_observer));
wds->AddFormFields(form_fields);
done_event.Wait();
@@ -202,7 +210,9 @@ void AddKeys(int profile, const std::set<AutofillKey>& keys) {
void(AutofillWebDataService::*remove_observer_func)(
AutofillWebDataServiceObserverOnDBThread*) =
&AutofillWebDataService::RemoveObserver;
- RunOnDBThreadAndBlock(Bind(remove_observer_func, wds, &mock_observer));
+ RunOnDBThreadAndBlock(Bind(remove_observer_func,
+ Unretained(wds),
+ &mock_observer));
}
void RemoveKey(int profile, const AutofillKey& key) {
@@ -220,8 +230,8 @@ void RemoveKeys(int profile) {
}
std::set<AutofillEntry> GetAllKeys(int profile) {
- scoped_refptr<AutofillWebDataService> wds = GetWebDataService(profile);
- std::vector<AutofillEntry> all_entries = GetAllAutofillEntries(wds.get());
+ AutofillWebDataService* 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();
it != all_entries.end(); ++it) {
diff --git a/chrome/browser/sync/test/integration/autofill_helper.h b/chrome/browser/sync/test/integration/autofill_helper.h
index 03e9f68..8e8b3f0 100644
--- a/chrome/browser/sync/test/integration/autofill_helper.h
+++ b/chrome/browser/sync/test/integration/autofill_helper.h
@@ -34,7 +34,7 @@ enum ProfileType {
};
// Used to access the web data service within a particular sync profile.
-scoped_refptr<autofill::AutofillWebDataService> GetWebDataService(
+autofill::AutofillWebDataService* GetWebDataService(
int index) WARN_UNUSED_RESULT;
// Used to access the personal data manager within a particular sync profile.
diff --git a/chrome/browser/webdata/token_web_data.cc b/chrome/browser/webdata/token_web_data.cc
index cd636da..0ce9a51 100644
--- a/chrome/browser/webdata/token_web_data.cc
+++ b/chrome/browser/webdata/token_web_data.cc
@@ -63,6 +63,9 @@ TokenWebData::TokenWebData(scoped_refptr<WebDatabaseService> wdbs,
token_backend_(new TokenWebDataBackend()) {
}
+TokenWebData::~TokenWebData() {
+}
+
void TokenWebData::SetTokenForService(const std::string& service,
const std::string& token) {
wdbs_->ScheduleDBTask(FROM_HERE,
@@ -86,6 +89,3 @@ TokenWebData::TokenWebData()
: WebDataServiceBase(NULL, ProfileErrorCallback()),
token_backend_(new TokenWebDataBackend()) {
}
-
-TokenWebData::~TokenWebData() {
-}
diff --git a/chrome/browser/webdata/token_web_data.h b/chrome/browser/webdata/token_web_data.h
index f74f230..9666621 100644
--- a/chrome/browser/webdata/token_web_data.h
+++ b/chrome/browser/webdata/token_web_data.h
@@ -35,12 +35,13 @@ class BrowserContext;
class TokenWebData : public WebDataServiceBase {
public:
// Retrieve a WebDataService for the given context.
- static scoped_refptr<TokenWebData> FromBrowserContext(
- content::BrowserContext* context);
+ static TokenWebData* FromBrowserContext(content::BrowserContext* context);
TokenWebData(scoped_refptr<WebDatabaseService> wdbs,
const ProfileErrorCallback& callback);
+ virtual ~TokenWebData();
+
// Set a token to use for a specified service.
void SetTokenForService(const std::string& service,
const std::string& token);
@@ -55,8 +56,6 @@ class TokenWebData : public WebDataServiceBase {
// For unit tests, passes a null callback.
TokenWebData();
- virtual ~TokenWebData();
-
private:
scoped_refptr<TokenWebDataBackend> token_backend_;
diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h
index 2904e2e..a2c3caa 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -25,6 +25,7 @@
#include "components/webdata/common/web_data_service_base.h"
#include "components/webdata/common/web_data_service_consumer.h"
#include "components/webdata/common/web_database.h"
+#include "content/public/browser/browser_thread.h"
struct DefaultWebIntentService;
class GURL;
@@ -91,7 +92,9 @@ struct WDKeywordsResult {
class WebDataServiceConsumer;
-class WebDataService : public WebDataServiceBase {
+class WebDataService : public WebDataServiceBase,
+ public base::RefCountedThreadSafe<WebDataService,
+ content::BrowserThread::DeleteOnUIThread> {
public:
// Retrieve a WebDataService for the given context.
static scoped_refptr<WebDataService> FromBrowserContext(
@@ -223,6 +226,12 @@ class WebDataService : public WebDataServiceBase {
virtual ~WebDataService();
private:
+ friend struct content::BrowserThread::DeleteOnThread<
+ content::BrowserThread::UI>;
+ friend class base::DeleteHelper<WebDataService>;
+ // We have to friend RCTS<> so WIN shared-lib build is happy (crbug/112250).
+ friend class base::RefCountedThreadSafe<WebDataService,
+ content::BrowserThread::DeleteOnUIThread>;
//////////////////////////////////////////////////////////////////////////////
//
// The following methods are only invoked on the DB thread.
diff --git a/chrome/browser/webdata/web_data_service_factory.cc b/chrome/browser/webdata/web_data_service_factory.cc
index 91ec3be..f11a296 100644
--- a/chrome/browser/webdata/web_data_service_factory.cc
+++ b/chrome/browser/webdata/web_data_service_factory.cc
@@ -41,7 +41,7 @@ void ProfileErrorCallback(sql::InitStatus status) {
}
void InitSyncableServicesOnDBThread(
- scoped_refptr<AutofillWebDataService> autofill_web_data,
+ AutofillWebDataService* autofill_web_data,
const base::FilePath& profile_path,
const std::string& app_locale,
autofill::AutofillWebDataBackend* autofill_backend) {
@@ -50,13 +50,13 @@ void InitSyncableServicesOnDBThread(
// Currently only Autocomplete and Autofill profiles use the new Sync API, but
// all the database data should migrate to this API over time.
AutocompleteSyncableService::CreateForWebDataServiceAndBackend(
- autofill_web_data.get(), autofill_backend);
- AutocompleteSyncableService::FromWebDataService(autofill_web_data.get())
+ autofill_web_data, autofill_backend);
+ AutocompleteSyncableService::FromWebDataService(autofill_web_data)
->InjectStartSyncFlare(
sync_start_util::GetFlareForSyncableService(profile_path));
AutofillProfileSyncableService::CreateForWebDataServiceAndBackend(
- autofill_web_data.get(), autofill_backend, app_locale);
- AutofillProfileSyncableService::FromWebDataService(autofill_web_data.get())
+ autofill_web_data, autofill_backend, app_locale);
+ AutofillProfileSyncableService::FromWebDataService(autofill_web_data)
->InjectStartSyncFlare(
sync_start_util::GetFlareForSyncableService(profile_path));
}
@@ -94,12 +94,12 @@ WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) {
web_database_->LoadDatabase();
- autofill_web_data_ = new AutofillWebDataService(
- web_database_, base::Bind(&ProfileErrorCallback));
+ autofill_web_data_.reset(new AutofillWebDataService(
+ web_database_, base::Bind(&ProfileErrorCallback)));
autofill_web_data_->Init();
- token_web_data_ = new TokenWebData(
- web_database_, base::Bind(&ProfileErrorCallback));
+ token_web_data_.reset(new TokenWebData(
+ web_database_, base::Bind(&ProfileErrorCallback)));
token_web_data_->Init();
web_data_ = new WebDataService(
@@ -108,7 +108,7 @@ WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) {
autofill_web_data_->GetAutofillBackend(
base::Bind(&InitSyncableServicesOnDBThread,
- autofill_web_data_,
+ autofill_web_data_.get(),
profile_path,
g_browser_process->GetApplicationLocale()));
}
@@ -123,8 +123,7 @@ void WebDataServiceWrapper::Shutdown() {
web_database_->ShutdownDatabase();
}
-scoped_refptr<AutofillWebDataService>
-WebDataServiceWrapper::GetAutofillWebData() {
+AutofillWebDataService* WebDataServiceWrapper::GetAutofillWebData() {
return autofill_web_data_.get();
}
@@ -132,12 +131,12 @@ scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() {
return web_data_.get();
}
-scoped_refptr<TokenWebData> WebDataServiceWrapper::GetTokenWebData() {
+TokenWebData* WebDataServiceWrapper::GetTokenWebData() {
return token_web_data_.get();
}
// static
-scoped_refptr<AutofillWebDataService>
+AutofillWebDataService*
AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) {
// For this service, the implicit/explicit distinction doesn't
// really matter; it's just used for a DCHECK. So we currently
@@ -148,11 +147,11 @@ AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) {
if (wrapper)
return wrapper->GetAutofillWebData();
// |wrapper| can be NULL in Incognito mode.
- return scoped_refptr<AutofillWebDataService>(NULL);
+ return NULL;
}
// static
-scoped_refptr<TokenWebData> TokenWebData::FromBrowserContext(
+TokenWebData* TokenWebData::FromBrowserContext(
content::BrowserContext* context) {
// For this service, the implicit/explicit distinction doesn't
// really matter; it's just used for a DCHECK. So we currently
@@ -163,7 +162,7 @@ scoped_refptr<TokenWebData> TokenWebData::FromBrowserContext(
if (wrapper)
return wrapper->GetTokenWebData();
// |wrapper| can be NULL in Incognito mode.
- return scoped_refptr<TokenWebData>(NULL);
+ return NULL;
}
// static
diff --git a/chrome/browser/webdata/web_data_service_factory.h b/chrome/browser/webdata/web_data_service_factory.h
index cb80c23..1f25e47 100644
--- a/chrome/browser/webdata/web_data_service_factory.h
+++ b/chrome/browser/webdata/web_data_service_factory.h
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "chrome/browser/profiles/profile.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
@@ -33,17 +34,17 @@ class WebDataServiceWrapper : public BrowserContextKeyedService {
// BrowserContextKeyedService:
virtual void Shutdown() OVERRIDE;
- virtual scoped_refptr<autofill::AutofillWebDataService> GetAutofillWebData();
+ virtual autofill::AutofillWebDataService* GetAutofillWebData();
virtual scoped_refptr<WebDataService> GetWebData();
- virtual scoped_refptr<TokenWebData> GetTokenWebData();
+ virtual TokenWebData* GetTokenWebData();
private:
scoped_refptr<WebDatabaseService> web_database_;
- scoped_refptr<autofill::AutofillWebDataService> autofill_web_data_;
- scoped_refptr<TokenWebData> token_web_data_;
+ scoped_ptr<autofill::AutofillWebDataService> autofill_web_data_;
+ scoped_ptr<TokenWebData> token_web_data_;
scoped_refptr<WebDataService> web_data_;
DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper);
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index c3ae1c6..35b634b 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -275,6 +275,8 @@
'../components/autofill/browser/test_autofill_manager_delegate.h',
'../components/autofill/browser/test_personal_data_manager.cc',
'../components/autofill/browser/test_personal_data_manager.h',
+ '../components/webdata/common/web_data_service_test_util.cc',
+ '../components/webdata/common/web_data_service_test_util.h',
'../ui/gfx/image/image_unittest_util.h',
'../ui/gfx/image/image_unittest_util.cc',
@@ -1787,8 +1789,6 @@
'../components/autofill/browser/webdata/autofill_table_unittest.cc',
'../components/autofill/browser/webdata/web_data_service_unittest.cc',
'../components/webdata/common/web_database_migration_unittest.cc',
- '../components/webdata/common/web_data_service_test_util.cc',
- '../components/webdata/common/web_data_service_test_util.h',
# TODO(joi): Move the google_apis tests to a separate
# google_apis_unittests executable.
diff --git a/components/autofill/browser/autocomplete_history_manager.cc b/components/autofill/browser/autocomplete_history_manager.cc
index 2f6ce63..2ff85ca 100644
--- a/components/autofill/browser/autocomplete_history_manager.cc
+++ b/components/autofill/browser/autocomplete_history_manager.cc
@@ -117,7 +117,7 @@ void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
return;
}
- if (autofill_data_.get()) {
+ if (autofill_data_) {
pending_query_handle_ = autofill_data_->GetFormValuesForElementName(
name, prefix, kMaxAutocompleteMenuItems, this);
}
@@ -153,13 +153,13 @@ void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) {
}
}
- if (!values.empty() && autofill_data_.get())
+ if (!values.empty() && autofill_data_)
autofill_data_->AddFormFields(values);
}
void AutocompleteHistoryManager::OnRemoveAutocompleteEntry(
const base::string16& name, const base::string16& value) {
- if (autofill_data_.get())
+ if (autofill_data_)
autofill_data_->RemoveFormValueForElementName(name, value);
}
@@ -170,7 +170,7 @@ void AutocompleteHistoryManager::SetExternalDelegate(
void AutocompleteHistoryManager::CancelPendingQuery() {
if (pending_query_handle_) {
- if (autofill_data_.get())
+ if (autofill_data_)
autofill_data_->CancelRequest(pending_query_handle_);
pending_query_handle_ = 0;
}
diff --git a/components/autofill/browser/autocomplete_history_manager.h b/components/autofill/browser/autocomplete_history_manager.h
index 9a55fa4..4bba83a 100644
--- a/components/autofill/browser/autocomplete_history_manager.h
+++ b/components/autofill/browser/autocomplete_history_manager.h
@@ -69,7 +69,7 @@ class AutocompleteHistoryManager : public content::WebContentsObserver,
void CancelPendingQuery();
content::BrowserContext* browser_context_;
- scoped_refptr<AutofillWebDataService> autofill_data_;
+ AutofillWebDataService* autofill_data_;
BooleanPrefMember autofill_enabled_;
diff --git a/components/autofill/browser/autocomplete_history_manager_unittest.cc b/components/autofill/browser/autocomplete_history_manager_unittest.cc
index 0a3680d..39d1c58 100644
--- a/components/autofill/browser/autocomplete_history_manager_unittest.cc
+++ b/components/autofill/browser/autocomplete_history_manager_unittest.cc
@@ -38,43 +38,11 @@ class MockWebDataService : public AutofillWebDataService {
public:
MockWebDataService()
: AutofillWebDataService() {
- current_mock_web_data_service_ = this;
}
MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&));
- static scoped_refptr<MockWebDataService> GetCurrent() {
- if (!current_mock_web_data_service_) {
- return new MockWebDataService();
- }
- return current_mock_web_data_service_;
- }
-
- protected:
virtual ~MockWebDataService() {}
-
- private:
- // Keep track of the most recently created instance, so that it can be
- // associated with the current profile when Build() is called.
- static MockWebDataService* current_mock_web_data_service_;
-};
-
-MockWebDataService* MockWebDataService::current_mock_web_data_service_ = NULL;
-
-class MockWebDataServiceWrapperCurrent : public MockWebDataServiceWrapperBase {
- public:
- static BrowserContextKeyedService* Build(content::BrowserContext* profile) {
- return new MockWebDataServiceWrapperCurrent();
- }
-
- MockWebDataServiceWrapperCurrent() {}
-
- virtual scoped_refptr<AutofillWebDataService> GetAutofillWebData() OVERRIDE {
- return MockWebDataService::GetCurrent();
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapperCurrent);
};
class MockAutofillManagerDelegate
@@ -90,25 +58,37 @@ class MockAutofillManagerDelegate
DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
};
+BrowserContextKeyedService* BuildMockWebDataServiceWrapper(
+ content::BrowserContext* profile) {
+ return new MockWebDataServiceWrapper(
+ NULL,
+ new MockWebDataService(),
+ NULL);
+}
+
} // namespace
class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness {
protected:
virtual void SetUp() OVERRIDE {
ChromeRenderViewHostTestHarness::SetUp();
- web_data_service_ = new MockWebDataService();
- WebDataServiceFactory::GetInstance()->SetTestingFactory(
- profile(), MockWebDataServiceWrapperCurrent::Build);
+ MockWebDataServiceWrapper* wrapper =
+ static_cast<MockWebDataServiceWrapper*>(
+ WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile(), BuildMockWebDataServiceWrapper));
+ web_data_service_ =
+ static_cast<MockWebDataService*>(wrapper->GetAutofillWebData());
autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents()));
}
virtual void TearDown() OVERRIDE {
autocomplete_manager_.reset();
+ web_data_service_->ShutdownOnUIThread();
web_data_service_ = NULL;
ChromeRenderViewHostTestHarness::TearDown();
}
- scoped_refptr<MockWebDataService> web_data_service_;
+ MockWebDataService* web_data_service_;
scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_;
MockAutofillManagerDelegate manager_delegate;
};
@@ -130,7 +110,7 @@ TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) {
valid_cc.form_control_type = "text";
form.fields.push_back(valid_cc);
- EXPECT_CALL(*web_data_service_.get(), AddFormFields(_)).Times(0);
+ EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0);
autocomplete_manager_->OnFormSubmitted(form);
}
@@ -153,7 +133,7 @@ TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) {
invalid_cc.form_control_type = "text";
form.fields.push_back(invalid_cc);
- EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1);
+ EXPECT_CALL(*(web_data_service_), AddFormFields(_)).Times(1);
autocomplete_manager_->OnFormSubmitted(form);
}
@@ -173,7 +153,7 @@ TEST_F(AutocompleteHistoryManagerTest, SSNValue) {
ssn.form_control_type = "text";
form.fields.push_back(ssn);
- EXPECT_CALL(*web_data_service_.get(), AddFormFields(_)).Times(0);
+ EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0);
autocomplete_manager_->OnFormSubmitted(form);
}
@@ -194,7 +174,7 @@ TEST_F(AutocompleteHistoryManagerTest, SearchField) {
search_field.form_control_type = "search";
form.fields.push_back(search_field);
- EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1);
+ EXPECT_CALL(*(web_data_service_), AddFormFields(_)).Times(1);
autocomplete_manager_->OnFormSubmitted(form);
}
diff --git a/components/autofill/browser/personal_data_manager.cc b/components/autofill/browser/personal_data_manager.cc
index 6a7fb1f..07e5527 100644
--- a/components/autofill/browser/personal_data_manager.cc
+++ b/components/autofill/browser/personal_data_manager.cc
@@ -146,11 +146,11 @@ void PersonalDataManager::Init(BrowserContext* browser_context) {
if (!browser_context_->IsOffTheRecord())
metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled());
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
// WebDataService may not be available in tests.
- if (!autofill_data.get())
+ if (!autofill_data)
return;
LoadProfiles();
@@ -166,9 +166,9 @@ PersonalDataManager::~PersonalDataManager() {
if (!browser_context_)
return;
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (autofill_data.get())
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
+ if (autofill_data)
autofill_data->RemoveObserver(this);
}
@@ -375,9 +375,9 @@ void PersonalDataManager::AddProfile(const AutofillProfile& profile) {
if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
return;
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
+ if (!autofill_data)
return;
// Don't add a duplicate.
@@ -408,9 +408,9 @@ void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) {
return;
}
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
+ if (!autofill_data)
return;
// Make the update.
@@ -441,9 +441,9 @@ void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) {
if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
return;
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
+ if (!autofill_data)
return;
// Don't add a duplicate.
@@ -474,9 +474,9 @@ void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) {
return;
}
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
+ if (!autofill_data)
return;
// Make the update.
@@ -496,9 +496,9 @@ void PersonalDataManager::RemoveByGUID(const std::string& guid) {
if (!is_credit_card && !is_profile)
return;
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
+ if (!autofill_data)
return;
if (is_credit_card)
@@ -784,9 +784,9 @@ void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) {
address_of<AutofillProfile>);
AutofillProfile::AdjustInferredLabels(&profile_pointers);
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
+ if (!autofill_data)
return;
// Any profiles that are not in the new profile list should be removed from
@@ -838,9 +838,9 @@ void PersonalDataManager::SetCreditCards(
it++;
}
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get())
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
+ if (!autofill_data)
return;
// Any credit cards that are not in the new credit card list should be
@@ -878,9 +878,9 @@ void PersonalDataManager::SetCreditCards(
}
void PersonalDataManager::LoadProfiles() {
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get()) {
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
+ if (!autofill_data) {
NOTREACHED();
return;
}
@@ -898,9 +898,9 @@ void PersonalDataManager::LoadAuxiliaryProfiles() {
#endif
void PersonalDataManager::LoadCreditCards() {
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get()) {
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
+ if (!autofill_data) {
NOTREACHED();
return;
}
@@ -949,9 +949,9 @@ void PersonalDataManager::ReceiveLoadedCreditCards(
void PersonalDataManager::CancelPendingQuery(
WebDataServiceBase::Handle* handle) {
if (*handle) {
- scoped_refptr<AutofillWebDataService> autofill_data(
- AutofillWebDataService::FromBrowserContext(browser_context_));
- if (!autofill_data.get()) {
+ AutofillWebDataService* autofill_data =
+ AutofillWebDataService::FromBrowserContext(browser_context_);
+ if (!autofill_data) {
NOTREACHED();
return;
}
diff --git a/components/autofill/browser/personal_data_manager_unittest.cc b/components/autofill/browser/personal_data_manager_unittest.cc
index 6c20883..1a4ffd5 100644
--- a/components/autofill/browser/personal_data_manager_unittest.cc
+++ b/components/autofill/browser/personal_data_manager_unittest.cc
@@ -539,9 +539,9 @@ TEST_F(PersonalDataManagerTest, Refresh) {
profile_pointers.push_back(&profile2);
AutofillProfile::AdjustInferredLabels(&profile_pointers);
- scoped_refptr<AutofillWebDataService> wds =
+ AutofillWebDataService* wds =
AutofillWebDataService::FromBrowserContext(profile_.get());
- ASSERT_TRUE(wds.get());
+ ASSERT_TRUE(wds);
wds->AddAutofillProfile(profile2);
personal_data_->Refresh();
diff --git a/components/autofill/browser/webdata/autofill_webdata_service.h b/components/autofill/browser/webdata/autofill_webdata_service.h
index b861c64..a85896d 100644
--- a/components/autofill/browser/webdata/autofill_webdata_service.h
+++ b/components/autofill/browser/webdata/autofill_webdata_service.h
@@ -43,9 +43,11 @@ class AutofillWebDataService : public AutofillWebData,
AutofillWebDataService(scoped_refptr<WebDatabaseService> wdbs,
const ProfileErrorCallback& callback);
+ virtual ~AutofillWebDataService();
+
// Retrieve an AutofillWebDataService for the given context.
// Can return NULL in some contexts.
- static scoped_refptr<AutofillWebDataService> FromBrowserContext(
+ static AutofillWebDataService* FromBrowserContext(
content::BrowserContext* context);
// WebDataServiceBase implementation.
@@ -101,8 +103,6 @@ class AutofillWebDataService : public AutofillWebData,
const base::Callback<void(AutofillWebDataBackend*)>& callback);
protected:
- virtual ~AutofillWebDataService();
-
virtual void NotifyAutofillMultipleChangedOnUIThread();
base::WeakPtr<AutofillWebDataService> AsWeakPtr() {
diff --git a/components/autofill/browser/webdata/web_data_service_unittest.cc b/components/autofill/browser/webdata/web_data_service_unittest.cc
index ed64064..fefb8bb 100644
--- a/components/autofill/browser/webdata/web_data_service_unittest.cc
+++ b/components/autofill/browser/webdata/web_data_service_unittest.cc
@@ -76,15 +76,15 @@ class WebDataServiceTest : public testing::Test {
wdbs_->AddTable(scoped_ptr<WebDatabaseTable>(new AutofillTable("en-US")));
wdbs_->LoadDatabase();
- wds_ = new AutofillWebDataService(
- wdbs_, WebDataServiceBase::ProfileErrorCallback());
+ wds_.reset(new AutofillWebDataService(
+ wdbs_, WebDataServiceBase::ProfileErrorCallback()));
wds_->Init();
}
virtual void TearDown() {
wds_->ShutdownOnUIThread();
wdbs_->ShutdownDatabase();
- wds_ = NULL;
+ wds_.reset();
wdbs_ = NULL;
WaitForDatabaseThread();
@@ -107,7 +107,7 @@ class WebDataServiceTest : public testing::Test {
content::TestBrowserThread ui_thread_;
content::TestBrowserThread db_thread_;
base::FilePath profile_dir_;
- scoped_refptr<AutofillWebDataService> wds_;
+ scoped_ptr<AutofillWebDataService> wds_;
scoped_refptr<WebDatabaseService> wdbs_;
base::ScopedTempDir temp_dir_;
};
@@ -135,7 +135,8 @@ class WebDataServiceAutofillTest : public WebDataServiceTest {
BrowserThread::PostTask(
BrowserThread::DB,
FROM_HERE,
- base::Bind(add_observer_func, wds_, &observer_));
+ base::Bind(add_observer_func,
+ base::Unretained(wds_.get()), &observer_));
WaitForDatabaseThread();
}
@@ -146,7 +147,8 @@ class WebDataServiceAutofillTest : public WebDataServiceTest {
BrowserThread::PostTask(
BrowserThread::DB,
FROM_HERE,
- base::Bind(remove_observer_func, wds_, &observer_));
+ base::Bind(remove_observer_func,
+ base::Unretained(wds_.get()), &observer_));
WaitForDatabaseThread();
WebDataServiceTest::TearDown();
diff --git a/components/webdata/common/web_data_service_base.h b/components/webdata/common/web_data_service_base.h
index a3abd9b..c261fec 100644
--- a/components/webdata/common/web_data_service_base.h
+++ b/components/webdata/common/web_data_service_base.h
@@ -22,9 +22,7 @@ class Thread;
}
// Base for WebDataService class hierarchy.
-class WEBDATA_EXPORT WebDataServiceBase
- : public base::RefCountedThreadSafe<WebDataServiceBase,
- content::BrowserThread::DeleteOnUIThread> {
+class WEBDATA_EXPORT WebDataServiceBase {
public:
// All requests return an opaque handle of the following type.
typedef int Handle;
@@ -47,6 +45,8 @@ class WEBDATA_EXPORT WebDataServiceBase
WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs,
const ProfileErrorCallback& callback);
+ virtual ~WebDataServiceBase();
+
// Cancel any pending request. You need to call this method if your
// WebDataServiceConsumer is about to be deleted.
virtual void CancelRequest(Handle h);
@@ -83,20 +83,13 @@ class WEBDATA_EXPORT WebDataServiceBase
virtual WebDatabase* GetDatabase();
protected:
- virtual ~WebDataServiceBase();
-
// Our database service.
scoped_refptr<WebDatabaseService> wdbs_;
private:
- friend struct content::BrowserThread::DeleteOnThread<
- content::BrowserThread::UI>;
- friend class base::DeleteHelper<WebDataServiceBase>;
- // We have to friend RCTS<> so WIN shared-lib build is happy (crbug/112250).
- friend class base::RefCountedThreadSafe<WebDataServiceBase,
- content::BrowserThread::DeleteOnUIThread>;
-
ProfileErrorCallback profile_error_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebDataServiceBase);
};
#endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_
diff --git a/components/webdata/common/web_data_service_test_util.cc b/components/webdata/common/web_data_service_test_util.cc
index 2720721..0ece6a4 100644
--- a/components/webdata/common/web_data_service_test_util.cc
+++ b/components/webdata/common/web_data_service_test_util.cc
@@ -22,8 +22,8 @@ void MockWebDataServiceWrapperBase::Shutdown() {
// all the webdatas in.
MockWebDataServiceWrapper::MockWebDataServiceWrapper(
scoped_refptr<WebDataService> fake_service,
- scoped_refptr<AutofillWebDataService> fake_autofill,
- scoped_refptr<TokenWebData> fake_token)
+ AutofillWebDataService* fake_autofill,
+ TokenWebData* fake_token)
: fake_autofill_web_data_(fake_autofill),
fake_token_web_data_(fake_token),
fake_web_data_(fake_service) {
@@ -32,13 +32,13 @@ MockWebDataServiceWrapper::MockWebDataServiceWrapper(
MockWebDataServiceWrapper::~MockWebDataServiceWrapper() {
}
-scoped_refptr<AutofillWebDataService>
+AutofillWebDataService*
MockWebDataServiceWrapper::GetAutofillWebData() {
- return fake_autofill_web_data_;
+ return fake_autofill_web_data_.get();
}
-scoped_refptr<TokenWebData> MockWebDataServiceWrapper::GetTokenWebData() {
- return fake_token_web_data_;
+TokenWebData* MockWebDataServiceWrapper::GetTokenWebData() {
+ return fake_token_web_data_.get();
}
scoped_refptr<WebDataService> MockWebDataServiceWrapper::GetWebData() {
diff --git a/components/webdata/common/web_data_service_test_util.h b/components/webdata/common/web_data_service_test_util.h
index 4f0f6e5..6fb3b63 100644
--- a/components/webdata/common/web_data_service_test_util.h
+++ b/components/webdata/common/web_data_service_test_util.h
@@ -58,21 +58,20 @@ class MockWebDataServiceWrapper : public MockWebDataServiceWrapperBase {
public:
MockWebDataServiceWrapper(
scoped_refptr<WebDataService> fake_service,
- scoped_refptr<autofill::AutofillWebDataService> fake_autofill,
- scoped_refptr<TokenWebData> fake_token);
+ autofill::AutofillWebDataService* fake_autofill,
+ TokenWebData* fake_token);
virtual ~MockWebDataServiceWrapper();
- virtual scoped_refptr<autofill::AutofillWebDataService>
- GetAutofillWebData() OVERRIDE;
+ virtual autofill::AutofillWebDataService* GetAutofillWebData() OVERRIDE;
- virtual scoped_refptr<TokenWebData> GetTokenWebData() OVERRIDE;
+ virtual TokenWebData* GetTokenWebData() OVERRIDE;
virtual scoped_refptr<WebDataService> GetWebData() OVERRIDE;
protected:
- scoped_refptr<autofill::AutofillWebDataService> fake_autofill_web_data_;
- scoped_refptr<TokenWebData> fake_token_web_data_;
+ scoped_ptr<autofill::AutofillWebDataService> fake_autofill_web_data_;
+ scoped_ptr<TokenWebData> fake_token_web_data_;
scoped_refptr<WebDataService> fake_web_data_;
private: