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

Unified Diff: chrome/browser/search_engines/template_url_service_test_util.cc

Issue 12871006: Second try at splitting WebDataService (minus ownership changes) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head for commit. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/search_engines/template_url_service_test_util.cc
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 244046e4848afb903065da334133e6f0e2a04cbc..fb03fd306c5466b7279ea4c360981ed9be85027f 100644
--- a/chrome/browser/search_engines/template_url_service_test_util.cc
+++ b/chrome/browser/search_engines/template_url_service_test_util.cc
@@ -5,7 +5,6 @@
#include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "base/bind.h"
-#include "base/files/scoped_temp_dir.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/synchronization/waitable_event.h"
@@ -53,35 +52,6 @@ static void WaitForThreadToProcessRequests(BrowserThread::ID identifier) {
} // namespace
-// Subclass the TestingProfile so that it can return a WebDataService.
-class TemplateURLServiceTestingProfile : public TestingProfile {
- public:
- TemplateURLServiceTestingProfile()
- : TestingProfile(),
- db_thread_(BrowserThread::DB),
- io_thread_(BrowserThread::IO) {
- }
-
- void SetUp();
- void TearDown();
-
- // Starts the I/O thread. This isn't done automatically because not every test
- // needs this.
- void StartIOThread() {
- io_thread_.StartIOThread();
- }
-
- static scoped_refptr<RefcountedProfileKeyedService>
- GetWebDataServiceForTemplateURLServiceTestingProfile(Profile* profile);
-
- private:
- scoped_refptr<WebDataService> service_;
- base::ScopedTempDir temp_dir_;
- content::TestBrowserThread db_thread_;
- content::TestBrowserThread io_thread_;
-};
-
-
// Trivial subclass of TemplateURLService that records the last invocation of
// SetKeywordSearchTermsForURL.
class TestingTemplateURLService : public TemplateURLService {
@@ -113,21 +83,40 @@ class TestingTemplateURLService : public TemplateURLService {
DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLService);
};
-void TemplateURLServiceTestingProfile::SetUp() {
- db_thread_.Start();
+TemplateURLServiceTestUtil::TemplateURLServiceTestUtil()
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ db_thread_(BrowserThread::DB),
+ io_thread_(BrowserThread::IO),
+ changed_count_(0) {
+}
+TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() {
+}
+
+void TemplateURLServiceTestUtil::SetUp() {
// Make unique temp directory.
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ profile_.reset(new TestingProfile(temp_dir_.path()));
+ db_thread_.Start();
+ profile_->CreateWebDataService();
+
+ TemplateURLService* service = static_cast<TemplateURLService*>(
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile_.get(), TestingTemplateURLService::Build));
+ service->AddObserver(this);
- base::FilePath path = temp_dir_.path().AppendASCII("TestDataService.db");
- service_ = new WebDataService;
- ASSERT_TRUE(service_->InitWithPath(path));
+#if defined(OS_CHROMEOS)
+ google_util::chromeos::ClearBrandForCurrentSession();
+#endif
}
-void TemplateURLServiceTestingProfile::TearDown() {
- // Clear the request context so it will get deleted. This should be done
- // before shutting down the I/O thread to avoid memory leaks.
- ResetRequestContext();
+void TemplateURLServiceTestUtil::TearDown() {
+ if (profile_.get()) {
+ // Clear the request context so it will get deleted. This should be done
+ // before shutting down the I/O thread to avoid memory leaks.
+ profile_->ResetRequestContext();
+ profile_.reset();
+ }
// Wait for the delete of the request context to happen.
if (io_thread_.IsRunning())
@@ -136,11 +125,6 @@ void TemplateURLServiceTestingProfile::TearDown() {
// The I/O thread must be shutdown before the DB thread.
io_thread_.Stop();
- // Clean up the test directory.
- 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
@@ -151,47 +135,10 @@ void TemplateURLServiceTestingProfile::TearDown() {
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();
-}
-
-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) {
-}
-
-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(
- profile_.get(), TestingTemplateURLService::Build));
- service->AddObserver(this);
-
-#if defined(OS_CHROMEOS)
- google_util::chromeos::ClearBrandForCurrentSession();
-#endif
-}
-
-void TemplateURLServiceTestUtil::TearDown() {
- if (profile_.get()) {
- profile_->TearDown();
- profile_.reset();
- }
UIThreadSearchTermsData::SetGoogleBaseURL(std::string());
// Flush the message loop to make application verifiers happy.
@@ -233,6 +180,7 @@ void TemplateURLServiceTestUtil::ChangeModelToLoadState() {
model()->service_ = WebDataServiceFactory::GetForProfile(
profile_.get(), Profile::EXPLICIT_ACCESS);
+ BlockTillServiceProcessesRequests();
}
void TemplateURLServiceTestUtil::ClearModel() {
@@ -330,7 +278,7 @@ TestingProfile* TemplateURLServiceTestUtil::profile() const {
}
void TemplateURLServiceTestUtil::StartIOThread() {
- profile_->StartIOThread();
+ io_thread_.StartIOThread();
}
void TemplateURLServiceTestUtil::PumpLoop() {

Powered by Google App Engine
This is Rietveld 408576698