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 850b5e36c73f9b6e24027a0a0f15e75c3117515e..5c5e43c0b379d36c2490d2e99841a3e33c2a8b29 100644 |
--- a/chrome/browser/search_engines/template_url_service_test_util.cc |
+++ b/chrome/browser/search_engines/template_url_service_test_util.cc |
@@ -5,9 +5,7 @@ |
#include "chrome/browser/search_engines/template_url_service_test_util.h" |
#include "base/bind.h" |
-#include "base/message_loop/message_loop.h" |
-#include "base/path_service.h" |
-#include "base/synchronization/waitable_event.h" |
+#include "base/run_loop.h" |
#include "base/threading/thread.h" |
#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/google/google_url_tracker.h" |
@@ -20,43 +18,12 @@ |
#include "chrome/test/base/testing_pref_service_syncable.h" |
#include "chrome/test/base/testing_profile.h" |
#include "content/public/browser/notification_service.h" |
-#include "content/public/test/test_browser_thread.h" |
#include "testing/gtest/include/gtest/gtest.h" |
- |
#if defined(OS_CHROMEOS) |
#include "chrome/browser/google/google_util_chromeos.h" |
#endif |
-using content::BrowserThread; |
- |
-namespace { |
- |
-// A callback used to coordinate when the database has finished processing |
-// requests. See note in BlockTillServiceProcessesRequests for details. |
-// |
-// Schedules a QuitClosure on the message loop it was created with. |
-void QuitCallback(base::MessageLoop* message_loop) { |
- message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); |
-} |
- |
-// Blocks the caller until thread has finished servicing all pending |
-// requests. |
-static void WaitForThreadToProcessRequests(BrowserThread::ID identifier) { |
- // Schedule a task on the thread that is processed after all |
- // pending requests on the thread. |
- BrowserThread::PostTask( |
- identifier, |
- FROM_HERE, |
- base::Bind(&QuitCallback, base::MessageLoop::current())); |
- base::MessageLoop::current()->Run(); |
-} |
- |
-} // namespace |
- |
- |
-// TestingTemplateURLService -------------------------------------------------- |
- |
// Trivial subclass of TemplateURLService that records the last invocation of |
// SetKeywordSearchTermsForURL. |
class TestingTemplateURLService : public TemplateURLService { |
@@ -88,14 +55,14 @@ class TestingTemplateURLService : public TemplateURLService { |
DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLService); |
}; |
- |
// TemplateURLServiceTestUtilBase --------------------------------------------- |
TemplateURLServiceTestUtilBase::TemplateURLServiceTestUtilBase() |
: changed_count_(0) { |
} |
-TemplateURLServiceTestUtilBase::~TemplateURLServiceTestUtilBase() {} |
+TemplateURLServiceTestUtilBase::~TemplateURLServiceTestUtilBase() { |
+} |
void TemplateURLServiceTestUtilBase::CreateTemplateUrlService() { |
profile()->CreateWebDataService(); |
@@ -118,18 +85,10 @@ void TemplateURLServiceTestUtilBase::ResetObserverCount() { |
changed_count_ = 0; |
} |
-void TemplateURLServiceTestUtilBase::BlockTillServiceProcessesRequests() { |
- WaitForThreadToProcessRequests(BrowserThread::DB); |
-} |
- |
-void TemplateURLServiceTestUtilBase::BlockTillIOThreadProcessesRequests() { |
- WaitForThreadToProcessRequests(BrowserThread::IO); |
-} |
- |
void TemplateURLServiceTestUtilBase::VerifyLoad() { |
ASSERT_FALSE(model()->loaded()); |
model()->Load(); |
- BlockTillServiceProcessesRequests(); |
+ base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(1, GetObserverCount()); |
ResetObserverCount(); |
} |
@@ -140,7 +99,7 @@ void TemplateURLServiceTestUtilBase::ChangeModelToLoadState() { |
// any changes made. |
model()->service_ = WebDataService::FromBrowserContext(profile()); |
- BlockTillServiceProcessesRequests(); |
+ base::RunLoop().RunUntilIdle(); |
} |
void TemplateURLServiceTestUtilBase::ClearModel() { |
@@ -238,9 +197,7 @@ TemplateURLService* TemplateURLServiceTestUtilBase::model() const { |
// TemplateURLServiceTestUtil ------------------------------------------------- |
TemplateURLServiceTestUtil::TemplateURLServiceTestUtil() |
- : ui_thread_(BrowserThread::UI, &message_loop_), |
- db_thread_(BrowserThread::DB), |
- io_thread_(BrowserThread::IO) { |
+ : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
} |
TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() { |
@@ -250,7 +207,6 @@ void TemplateURLServiceTestUtil::SetUp() { |
// Make unique temp directory. |
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
profile_.reset(new TestingProfile(temp_dir_.path())); |
- db_thread_.Start(); |
TemplateURLServiceTestUtilBase::CreateTemplateUrlService(); |
@@ -260,49 +216,14 @@ void TemplateURLServiceTestUtil::SetUp() { |
} |
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()) |
- TemplateURLServiceTestUtilBase::BlockTillIOThreadProcessesRequests(); |
- |
- // The I/O thread must be shutdown before the DB thread. |
- io_thread_.Stop(); |
- |
- // 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(); |
- base::MessageLoop::current()->PostTask(FROM_HERE, |
- base::MessageLoop::QuitClosure()); |
- base::MessageLoop::current()->Run(); |
- db_thread_.Stop(); |
+ profile_.reset(); |
UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); |
// Flush the message loop to make application verifiers happy. |
- message_loop_.RunUntilIdle(); |
+ base::RunLoop().RunUntilIdle(); |
} |
TestingProfile* TemplateURLServiceTestUtil::profile() const { |
return profile_.get(); |
} |
- |
-void TemplateURLServiceTestUtil::StartIOThread() { |
- io_thread_.StartIOThread(); |
-} |
- |
-void TemplateURLServiceTestUtil::PumpLoop() { |
- message_loop_.RunUntilIdle(); |
-} |