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

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

Issue 2445763002: Disallow posting tasks to SequencedWorkerPools by default. (Closed)
Patch Set: self-review Created 4 years 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/service/service_process.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 SequencedWorkerPool::ResetRedirectToTaskSchedulerForProcessForTesting(); 257
258 SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); 258 // Unit tests run in an environment where SequencedWorkerPool is enabled
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();
259 } 263 }
260 } 264 }
261 265
262 void TearDown() override { 266 void TearDown() override {
263 // Wait until all references to the SequencedWorkerPool are gone and destroy 267 // Wait until all references to the SequencedWorkerPool are gone and destroy
264 // it. This must be done before destroying the TaskScheduler. Otherwise, the 268 // it. This must be done before destroying the TaskScheduler. Otherwise, the
265 // SequencedWorkerPool could try to redirect tasks to a destroyed 269 // SequencedWorkerPool could try to redirect tasks to a destroyed
266 // TaskScheduler. 270 // TaskScheduler.
267 DeletePool(); 271 DeletePool();
268 272
269 if (RedirectedToTaskScheduler()) { 273 if (RedirectedToTaskScheduler()) {
270 SequencedWorkerPool::ResetRedirectToTaskSchedulerForProcessForTesting(); 274 // Reset SequencedWorkerPool to its original state (i.e. enabled without
275 // redirection to TaskScheduler).
276 SequencedWorkerPool::DisableForProcessForTesting();
277 SequencedWorkerPool::EnableForProcess();
278
279 // Delete the registered TaskScheduler.
271 DeleteTaskScheduler(); 280 DeleteTaskScheduler();
272 } 281 }
273 } 282 }
274 283
275 bool RedirectedToTaskScheduler() const { 284 bool RedirectedToTaskScheduler() const {
276 return GetParam() == SequencedWorkerPoolRedirection::TO_TASK_SCHEDULER; 285 return GetParam() == SequencedWorkerPoolRedirection::TO_TASK_SCHEDULER;
277 } 286 }
278 287
279 const scoped_refptr<SequencedWorkerPool>& pool() { 288 const scoped_refptr<SequencedWorkerPool>& pool() {
280 return pool_owner_->pool(); 289 return pool_owner_->pool();
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest, 1241 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest,
1233 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 1242 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
1234 INSTANTIATE_TYPED_TEST_CASE_P( 1243 INSTANTIATE_TYPED_TEST_CASE_P(
1235 SequencedWorkerPoolSequencedTaskRunner, 1244 SequencedWorkerPoolSequencedTaskRunner,
1236 SequencedTaskRunnerDelayedTest, 1245 SequencedTaskRunnerDelayedTest,
1237 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 1246 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
1238 1247
1239 } // namespace 1248 } // namespace
1240 1249
1241 } // namespace base 1250 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/sequenced_worker_pool.cc ('k') | chrome/service/service_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698