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

Side by Side Diff: base/test/scoped_task_environment.cc

Issue 2876583002: Do not flush main thread tasks in ~ScopedTaskEnvironment. (Closed)
Patch Set: Created 3 years, 7 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 | « base/test/scoped_task_environment.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "base/test/scoped_task_environment.h" 5 #include "base/test/scoped_task_environment.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/task_scheduler/scheduler_worker_pool_params.h" 8 #include "base/task_scheduler/scheduler_worker_pool_params.h"
9 #include "base/task_scheduler/task_scheduler.h" 9 #include "base/task_scheduler/task_scheduler.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 const SchedulerWorkerPoolParams worker_pool_params( 48 const SchedulerWorkerPoolParams worker_pool_params(
49 SchedulerWorkerPoolParams::StandbyThreadPolicy::ONE, kMaxThreads, 49 SchedulerWorkerPoolParams::StandbyThreadPolicy::ONE, kMaxThreads,
50 kSuggestedReclaimTime); 50 kSuggestedReclaimTime);
51 TaskScheduler::Create("ScopedTaskEnvironment"); 51 TaskScheduler::Create("ScopedTaskEnvironment");
52 task_scheduler_ = TaskScheduler::GetInstance(); 52 task_scheduler_ = TaskScheduler::GetInstance();
53 TaskScheduler::GetInstance()->Start({worker_pool_params, worker_pool_params, 53 TaskScheduler::GetInstance()->Start({worker_pool_params, worker_pool_params,
54 worker_pool_params, worker_pool_params}); 54 worker_pool_params, worker_pool_params});
55 } 55 }
56 56
57 ScopedTaskEnvironment::~ScopedTaskEnvironment() { 57 ScopedTaskEnvironment::~ScopedTaskEnvironment() {
58 RunLoop().RunUntilIdle();
gab 2017/05/10 15:46:49 Replace with: // Intentionally do not RunLoop().R
fdoray 2017/05/10 16:01:46 Done.
59
60 DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_); 58 DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_);
61 // Without FlushForTesting(), DeleteSoon() and ReleaseSoon() tasks could be 59 // Without FlushForTesting(), DeleteSoon() and ReleaseSoon() tasks could be
62 // skipped, resulting in memory leaks. 60 // skipped, resulting in memory leaks.
63 TaskScheduler::GetInstance()->FlushForTesting(); 61 TaskScheduler::GetInstance()->FlushForTesting();
64 TaskScheduler::GetInstance()->Shutdown(); 62 TaskScheduler::GetInstance()->Shutdown();
65 TaskScheduler::GetInstance()->JoinForTesting(); 63 TaskScheduler::GetInstance()->JoinForTesting();
66 TaskScheduler::SetInstance(nullptr); 64 TaskScheduler::SetInstance(nullptr);
67 } 65 }
68 66
69 void ScopedTaskEnvironment::RunUntilIdle() { 67 void ScopedTaskEnvironment::RunUntilIdle() {
70 for (;;) { 68 for (;;) {
71 TaskScheduler::GetInstance()->FlushForTesting(); 69 TaskScheduler::GetInstance()->FlushForTesting();
72 70
73 TaskObserver task_observer; 71 TaskObserver task_observer;
74 MessageLoop::current()->AddTaskObserver(&task_observer); 72 MessageLoop::current()->AddTaskObserver(&task_observer);
75 RunLoop().RunUntilIdle(); 73 RunLoop().RunUntilIdle();
76 MessageLoop::current()->RemoveTaskObserver(&task_observer); 74 MessageLoop::current()->RemoveTaskObserver(&task_observer);
77 75
78 if (!task_observer.ran_task()) 76 if (!task_observer.ran_task())
79 return; 77 return;
80 } 78 }
81 } 79 }
82 80
83 } // namespace test 81 } // namespace test
84 } // namespace base 82 } // namespace base
OLDNEW
« no previous file with comments | « base/test/scoped_task_environment.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698