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

Unified Diff: content/public/test/test_utils.cc

Issue 2402553005: Do not run a nested loop in content::DeferredQuitRunLoop. (Closed)
Patch Set: fix OneClickSigninDialogViewTest Created 4 years, 2 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
« no previous file with comments | « content/public/test/test_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/test/test_utils.cc
diff --git a/content/public/test/test_utils.cc b/content/public/test/test_utils.cc
index 14e3c4b128fc5636024786377120c9576f41a292..cc8757da101ae39a2ac59bc4a86bcdcdf27eabc7 100644
--- a/content/public/test/test_utils.cc
+++ b/content/public/test/test_utils.cc
@@ -45,10 +45,10 @@ namespace {
// animating page, the potential delay to quitting the RunLoop would be
// kNumQuitDeferrals * frame_render_time. Some perf tests run slow, such as
// 200ms/frame.
-static const int kNumQuitDeferrals = 10;
+constexpr int kNumQuitDeferrals = 10;
-static void DeferredQuitRunLoop(const base::Closure& quit_task,
- int num_quit_deferrals) {
+void DeferredQuitRunLoop(const base::Closure& quit_task,
+ int num_quit_deferrals) {
if (num_quit_deferrals <= 0) {
quit_task.Run();
} else {
@@ -58,12 +58,6 @@ static void DeferredQuitRunLoop(const base::Closure& quit_task,
}
}
-void RunAllPendingMessageAndSendQuit(BrowserThread::ID thread_id,
- const base::Closure& quit_task) {
- RunAllPendingInMessageLoop();
- BrowserThread::PostTask(thread_id, FROM_HERE, quit_task);
-}
-
// Class used to handle result callbacks for ExecuteScriptAndGetValue.
class ScriptCallback {
public:
@@ -139,6 +133,7 @@ void RunThisRunLoop(base::RunLoop* run_loop) {
}
void RunAllPendingInMessageLoop() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, GetQuitTaskForRunLoop(&run_loop));
@@ -146,20 +141,23 @@ void RunAllPendingInMessageLoop() {
}
void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) {
- if (BrowserThread::CurrentlyOn(thread_id)) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ if (thread_id == BrowserThread::UI) {
RunAllPendingInMessageLoop();
return;
}
- BrowserThread::ID current_thread_id;
- if (!BrowserThread::GetCurrentThreadIdentifier(&current_thread_id)) {
- NOTREACHED();
- return;
- }
+ // Post a DeferredQuitRunLoop() task to |thread_id|. Then, run a RunLoop on
+ // this thread. When a few generations of pending tasks have run on
+ // |thread_id|, a task will be posted to this thread to exit the RunLoop.
base::RunLoop run_loop;
- BrowserThread::PostTask(thread_id, FROM_HERE,
- base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id,
- run_loop.QuitClosure()));
+ const base::Closure post_quit_run_loop_to_ui_thread = base::Bind(
+ base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask),
+ base::ThreadTaskRunnerHandle::Get(), FROM_HERE, run_loop.QuitClosure());
+ BrowserThread::PostTask(
+ thread_id, FROM_HERE,
+ base::Bind(&DeferredQuitRunLoop, post_quit_run_loop_to_ui_thread,
+ kNumQuitDeferrals));
RunThisRunLoop(&run_loop);
}
« no previous file with comments | « content/public/test/test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698