Commit ec5b5700 authored by Olivier Li's avatar Olivier Li Committed by Commit Bot

Create a function to allow clients of TestingProfile to wait on the...

Create a function to allow clients of TestingProfile to wait on the destruction of its HistoryBackend.

The HistoryServiceUsesTaskScheduler feature will soon be flipped to ENABLED_BY_DEFAULT.
This will make HistoryServiceBackend's task runner dispatch to the ThreadPool instead of a
dedicated base::Thread. Tests using TestingProfile need to be prepared to stay functional when that happens.

This is done as the last mile of the chrome-wide effort to coalesce as much work as possible
to the ThreadPool.

Bug: 661143
Change-Id: Iddb851d00ea64693f669bcb656829abcb2303b10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1868913Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Oliver Li <olivierli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707810}
parent ffe6dd7f
...@@ -653,6 +653,23 @@ void TestingProfile::CreateWebDataService() { ...@@ -653,6 +653,23 @@ void TestingProfile::CreateWebDataService() {
this, base::BindRepeating(&BuildWebDataService)); this, base::BindRepeating(&BuildWebDataService));
} }
void TestingProfile::BlockUntilHistoryBackendDestroyed() {
// Only get the history service if it actually exists since the caller of the
// test should explicitly call CreateHistoryService to build it.
history::HistoryService* history_service =
HistoryServiceFactory::GetForProfileWithoutCreating(this);
// Nothing to destroy
if (!history_service) {
return;
}
base::RunLoop run_loop;
history_service->SetOnBackendDestroyTask(run_loop.QuitClosure());
HistoryServiceFactory::ShutdownForProfile(this);
run_loop.Run();
}
void TestingProfile::BlockUntilHistoryIndexIsRefreshed() { void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
// Only get the history service if it actually exists since the caller of the // Only get the history service if it actually exists since the caller of the
// test should explicitly call CreateHistoryService to build it. // test should explicitly call CreateHistoryService to build it.
......
...@@ -250,6 +250,11 @@ class TestingProfile : public Profile { ...@@ -250,6 +250,11 @@ class TestingProfile : public Profile {
// This is NOT invoked from CreateHistoryService. // This is NOT invoked from CreateHistoryService.
void BlockUntilHistoryIndexIsRefreshed(); void BlockUntilHistoryIndexIsRefreshed();
// Blocks until the HistoryBackend is completely destroyed. This is mostly
// useful to ensure the destruction tasks do not outlive this class on which
// they depend.
void BlockUntilHistoryBackendDestroyed();
// Allow setting a profile as Guest after-the-fact to simplify some tests. // Allow setting a profile as Guest after-the-fact to simplify some tests.
void SetGuestSession(bool guest); void SetGuestSession(bool guest);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment