Commit c5f35620 authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Migrate BrowsingDataRemover TestUtils from FlushForTesting to FlushAsyncForTesting

ProfileHelperTest.DeleteInactiveProfile and UkmBrowserTest.HistoryDeleteCheck
need the waiting thread to process tasks or they will deadlock.

BUG=749312

Change-Id: I9d18fd55647d32e6e6a33a72be2a0fa8fcd89524
Reviewed-on: https://chromium-review.googlesource.com/988243
Commit-Queue: Robert Liao <robliao@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547819}
parent 0fe34285
......@@ -19,12 +19,25 @@ BrowsingDataRemoverCompletionObserver::
~BrowsingDataRemoverCompletionObserver() {}
void BrowsingDataRemoverCompletionObserver::BlockUntilCompletion() {
base::TaskScheduler::GetInstance()->FlushForTesting();
base::TaskScheduler::GetInstance()->FlushAsyncForTesting(base::BindOnce(
[](BrowsingDataRemoverCompletionObserver* observer) {
observer->flush_for_testing_complete_ = true;
observer->QuitRunLoopWhenTasksComplete();
},
base::Unretained(this)));
run_loop_.Run();
}
void BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone() {
browsing_data_remover_done_ = true;
observer_.RemoveAll();
QuitRunLoopWhenTasksComplete();
}
void BrowsingDataRemoverCompletionObserver::QuitRunLoopWhenTasksComplete() {
if (!flush_for_testing_complete_ || !browsing_data_remover_done_)
return;
run_loop_.QuitWhenIdle();
}
......@@ -52,9 +65,16 @@ void BrowsingDataRemoverCompletionInhibitor::Reset() {
}
void BrowsingDataRemoverCompletionInhibitor::BlockUntilNearCompletion() {
base::TaskScheduler::GetInstance()->FlushForTesting();
base::TaskScheduler::GetInstance()->FlushAsyncForTesting(base::BindOnce(
[](BrowsingDataRemoverCompletionInhibitor* inhibitor) {
inhibitor->flush_for_testing_complete_ = true;
inhibitor->QuitRunLoopWhenTasksComplete();
},
base::Unretained(this)));
run_loop_->Run();
run_loop_ = std::make_unique<base::RunLoop>();
flush_for_testing_complete_ = false;
browsing_data_remover_would_complete_done_ = false;
}
void BrowsingDataRemoverCompletionInhibitor::ContinueToCompletion() {
......@@ -67,6 +87,16 @@ void BrowsingDataRemoverCompletionInhibitor::OnBrowsingDataRemoverWouldComplete(
const base::Closure& continue_to_completion) {
DCHECK(continue_to_completion_callback_.is_null());
continue_to_completion_callback_ = continue_to_completion;
browsing_data_remover_would_complete_done_ = true;
QuitRunLoopWhenTasksComplete();
}
void BrowsingDataRemoverCompletionInhibitor::QuitRunLoopWhenTasksComplete() {
if (!flush_for_testing_complete_ ||
!browsing_data_remover_would_complete_done_) {
return;
}
run_loop_->QuitWhenIdle();
}
......
......@@ -29,6 +29,15 @@ class BrowsingDataRemoverCompletionObserver
void OnBrowsingDataRemoverDone() override;
private:
void QuitRunLoopWhenTasksComplete();
// Tracks when the Task Scheduler task flushing is done.
bool flush_for_testing_complete_ = false;
// Tracks when BrowsingDataRemover::Observer::OnBrowsingDataRemoverDone() is
// called.
bool browsing_data_remover_done_ = false;
base::RunLoop run_loop_;
ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> observer_;
......@@ -57,6 +66,14 @@ class BrowsingDataRemoverCompletionInhibitor {
const base::Closure& continue_to_completion);
private:
void QuitRunLoopWhenTasksComplete();
// Tracks when the Task Scheduler task flushing is done.
bool flush_for_testing_complete_ = false;
// Tracks when OnBrowsingDataRemoverWouldComplete() is called.
bool browsing_data_remover_would_complete_done_ = false;
// Not owned by this class. If the pointer becomes invalid, the owner of
// this class is responsible for calling Reset().
BrowsingDataRemover* remover_;
......
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