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

Side by Side Diff: content/public/test/test_utils.cc

Issue 2750823002: Flush TaskScheduler in content::RunAllBlockingPoolTasksUntilIdle(). (Closed)
Patch Set: fix test error Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « content/public/test/test_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/public/test/test_utils.h" 5 #include "content/public/test/test_utils.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/task_scheduler/task_scheduler.h"
16 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/values.h" 19 #include "base/values.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "content/common/site_isolation_policy.h" 21 #include "content/common/site_isolation_policy.h"
21 #include "content/common/url_schemes.h" 22 #include "content/common/url_schemes.h"
22 #include "content/public/browser/browser_child_process_host_iterator.h" 23 #include "content/public/browser/browser_child_process_host_iterator.h"
23 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/render_process_host.h" 26 #include "content/public/browser/render_process_host.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 thread_id, FROM_HERE, 153 thread_id, FROM_HERE,
153 base::Bind(&DeferredQuitRunLoop, post_quit_run_loop_to_ui_thread, 154 base::Bind(&DeferredQuitRunLoop, post_quit_run_loop_to_ui_thread,
154 kNumQuitDeferrals)); 155 kNumQuitDeferrals));
155 RunThisRunLoop(&run_loop); 156 RunThisRunLoop(&run_loop);
156 } 157 }
157 158
158 void RunAllBlockingPoolTasksUntilIdle() { 159 void RunAllBlockingPoolTasksUntilIdle() {
159 while (true) { 160 while (true) {
160 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 161 content::BrowserThread::GetBlockingPool()->FlushForTesting();
161 162
163 // Setup a task observer to determine if MessageLoop tasks run in the
164 // current loop iteration. This must be done before
165 // TaskScheduler::FlushForTesting() since this may spin the MessageLoop.
162 TaskObserver task_observer; 166 TaskObserver task_observer;
163 base::MessageLoop::current()->AddTaskObserver(&task_observer); 167 base::MessageLoop::current()->AddTaskObserver(&task_observer);
168
169 // Since all blocking pool call sites are being migrated to TaskScheduler,
170 // flush TaskScheduler in addition to the blocking pool.
171 base::TaskScheduler::GetInstance()->FlushForTesting();
172
164 base::RunLoop().RunUntilIdle(); 173 base::RunLoop().RunUntilIdle();
165 base::MessageLoop::current()->RemoveTaskObserver(&task_observer); 174 base::MessageLoop::current()->RemoveTaskObserver(&task_observer);
166 175
167 if (!task_observer.processed()) 176 if (!task_observer.processed())
168 break; 177 break;
169 } 178 }
170 } 179 }
171 180
172 base::Closure GetDeferredQuitTaskForRunLoop(base::RunLoop* run_loop) { 181 base::Closure GetDeferredQuitTaskForRunLoop(base::RunLoop* run_loop) {
173 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(), 182 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(),
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 397
389 void WebContentsDestroyedWatcher::Wait() { 398 void WebContentsDestroyedWatcher::Wait() {
390 run_loop_.Run(); 399 run_loop_.Run();
391 } 400 }
392 401
393 void WebContentsDestroyedWatcher::WebContentsDestroyed() { 402 void WebContentsDestroyedWatcher::WebContentsDestroyed() {
394 run_loop_.Quit(); 403 run_loop_.Quit();
395 } 404 }
396 405
397 } // namespace content 406 } // namespace content
OLDNEW
« 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