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

Side by Side Diff: base/threading/sequenced_worker_pool_unittest.cc

Issue 2519543002: Revert of Disallow posting tasks to SequencedWorkerPools by default. (Closed)
Patch Set: Created 4 years, 1 month 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/threading/sequenced_worker_pool.cc ('k') | chrome/browser/chrome_browser_main.cc » ('j') | 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 "base/threading/sequenced_worker_pool.h" 5 #include "base/threading/sequenced_worker_pool.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 if (RedirectedToTaskScheduler()) { 247 if (RedirectedToTaskScheduler()) {
248 std::vector<SchedulerWorkerPoolParams> worker_pool_params; 248 std::vector<SchedulerWorkerPoolParams> worker_pool_params;
249 worker_pool_params.emplace_back( 249 worker_pool_params.emplace_back(
250 "SchedulerWorkerPoolName", ThreadPriority::NORMAL, 250 "SchedulerWorkerPoolName", ThreadPriority::NORMAL,
251 SchedulerWorkerPoolParams::IORestriction::ALLOWED, 251 SchedulerWorkerPoolParams::IORestriction::ALLOWED,
252 SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY, 252 SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY,
253 kNumWorkerThreads, TimeDelta::Max()); 253 kNumWorkerThreads, TimeDelta::Max());
254 TaskScheduler::CreateAndSetDefaultTaskScheduler( 254 TaskScheduler::CreateAndSetDefaultTaskScheduler(
255 std::move(worker_pool_params), 255 std::move(worker_pool_params),
256 base::Bind([](const TaskTraits&) -> size_t { return 0U; })); 256 base::Bind([](const TaskTraits&) -> size_t { return 0U; }));
257 257 SequencedWorkerPool::ResetRedirectToTaskSchedulerForProcessForTesting();
258 // Unit tests run in an environment where SequencedWorkerPool is enabled 258 SequencedWorkerPool::RedirectToTaskSchedulerForProcess();
259 // without redirection to TaskScheduler. For the current unit test,
260 // disable it and re-enable it with redirection to TaskScheduler.
261 SequencedWorkerPool::DisableForProcessForTesting();
262 SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess();
263 } 259 }
264 } 260 }
265 261
266 void TearDown() override { 262 void TearDown() override {
267 // Wait until all references to the SequencedWorkerPool are gone and destroy 263 // Wait until all references to the SequencedWorkerPool are gone and destroy
268 // it. This must be done before destroying the TaskScheduler. Otherwise, the 264 // it. This must be done before destroying the TaskScheduler. Otherwise, the
269 // SequencedWorkerPool could try to redirect tasks to a destroyed 265 // SequencedWorkerPool could try to redirect tasks to a destroyed
270 // TaskScheduler. 266 // TaskScheduler.
271 DeletePool(); 267 DeletePool();
272 268
273 if (RedirectedToTaskScheduler()) { 269 if (RedirectedToTaskScheduler()) {
274 // Reset SequencedWorkerPool to its original state (i.e. enabled without 270 SequencedWorkerPool::ResetRedirectToTaskSchedulerForProcessForTesting();
275 // redirection to TaskScheduler).
276 SequencedWorkerPool::DisableForProcessForTesting();
277 SequencedWorkerPool::EnableForProcess();
278
279 // Delete the registered TaskScheduler.
280 DeleteTaskScheduler(); 271 DeleteTaskScheduler();
281 } 272 }
282 } 273 }
283 274
284 bool RedirectedToTaskScheduler() const { 275 bool RedirectedToTaskScheduler() const {
285 return GetParam() == SequencedWorkerPoolRedirection::TO_TASK_SCHEDULER; 276 return GetParam() == SequencedWorkerPoolRedirection::TO_TASK_SCHEDULER;
286 } 277 }
287 278
288 const scoped_refptr<SequencedWorkerPool>& pool() { 279 const scoped_refptr<SequencedWorkerPool>& pool() {
289 return pool_owner_->pool(); 280 return pool_owner_->pool();
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest, 1232 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest,
1242 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 1233 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
1243 INSTANTIATE_TYPED_TEST_CASE_P( 1234 INSTANTIATE_TYPED_TEST_CASE_P(
1244 SequencedWorkerPoolSequencedTaskRunner, 1235 SequencedWorkerPoolSequencedTaskRunner,
1245 SequencedTaskRunnerDelayedTest, 1236 SequencedTaskRunnerDelayedTest,
1246 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 1237 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
1247 1238
1248 } // namespace 1239 } // namespace
1249 1240
1250 } // namespace base 1241 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/sequenced_worker_pool.cc ('k') | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698