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

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

Issue 2517443002: 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 void SetUp() override { 246 void SetUp() override {
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, kNumWorkerThreads, 251 SchedulerWorkerPoolParams::IORestriction::ALLOWED, kNumWorkerThreads,
252 TimeDelta::Max()); 252 TimeDelta::Max());
253 TaskScheduler::CreateAndSetDefaultTaskScheduler( 253 TaskScheduler::CreateAndSetDefaultTaskScheduler(
254 std::move(worker_pool_params), 254 std::move(worker_pool_params),
255 base::Bind([](const TaskTraits&) -> size_t { return 0U; })); 255 base::Bind([](const TaskTraits&) -> size_t { return 0U; }));
256 256 SequencedWorkerPool::ResetRedirectToTaskSchedulerForProcessForTesting();
257 // Unit tests run in an environment where SequencedWorkerPool is enabled 257 SequencedWorkerPool::RedirectToTaskSchedulerForProcess();
258 // without redirection to TaskScheduler. For the current unit test,
259 // disable it and re-enable it with redirection to TaskScheduler.
260 SequencedWorkerPool::DisableForProcessForTesting();
261 SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess();
262 } 258 }
263 } 259 }
264 260
265 void TearDown() override { 261 void TearDown() override {
266 // Wait until all references to the SequencedWorkerPool are gone and destroy 262 // Wait until all references to the SequencedWorkerPool are gone and destroy
267 // it. This must be done before destroying the TaskScheduler. Otherwise, the 263 // it. This must be done before destroying the TaskScheduler. Otherwise, the
268 // SequencedWorkerPool could try to redirect tasks to a destroyed 264 // SequencedWorkerPool could try to redirect tasks to a destroyed
269 // TaskScheduler. 265 // TaskScheduler.
270 DeletePool(); 266 DeletePool();
271 267
272 if (RedirectedToTaskScheduler()) { 268 if (RedirectedToTaskScheduler()) {
273 // Reset SequencedWorkerPool to its original state (i.e. enabled without 269 SequencedWorkerPool::ResetRedirectToTaskSchedulerForProcessForTesting();
274 // redirection to TaskScheduler).
275 SequencedWorkerPool::DisableForProcessForTesting();
276 SequencedWorkerPool::EnableForProcess();
277
278 // Delete the registered TaskScheduler.
279 DeleteTaskScheduler(); 270 DeleteTaskScheduler();
280 } 271 }
281 } 272 }
282 273
283 bool RedirectedToTaskScheduler() const { 274 bool RedirectedToTaskScheduler() const {
284 return GetParam() == SequencedWorkerPoolRedirection::TO_TASK_SCHEDULER; 275 return GetParam() == SequencedWorkerPoolRedirection::TO_TASK_SCHEDULER;
285 } 276 }
286 277
287 const scoped_refptr<SequencedWorkerPool>& pool() { 278 const scoped_refptr<SequencedWorkerPool>& pool() {
288 return pool_owner_->pool(); 279 return pool_owner_->pool();
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest, 1231 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest,
1241 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 1232 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
1242 INSTANTIATE_TYPED_TEST_CASE_P( 1233 INSTANTIATE_TYPED_TEST_CASE_P(
1243 SequencedWorkerPoolSequencedTaskRunner, 1234 SequencedWorkerPoolSequencedTaskRunner,
1244 SequencedTaskRunnerDelayedTest, 1235 SequencedTaskRunnerDelayedTest,
1245 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 1236 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
1246 1237
1247 } // namespace 1238 } // namespace
1248 1239
1249 } // namespace base 1240 } // 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