Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/test/scoped_task_scheduler.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/task_scheduler/scheduler_worker_pool_params.h" | |
| 11 #include "base/task_scheduler/task_scheduler.h" | |
| 12 #include "base/threading/platform_thread.h" | |
| 13 #include "base/time/time.h" | |
| 14 | |
| 15 namespace base { | |
| 16 namespace test { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 size_t GetWorkerPoolIndexForTraits(const TaskTraits&) { | |
| 21 // All TaskTraits are mapped to the single worker pool. | |
| 22 return 0; | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 ScopedTaskScheduler::ScopedTaskScheduler() { | |
| 28 DCHECK(!TaskScheduler::GetInstance()); | |
| 29 | |
| 30 // Create a TaskScheduler with a single thread to make tests deterministic. | |
| 31 std::vector<SchedulerWorkerPoolParams> worker_pool_params_vector; | |
| 32 worker_pool_params_vector.emplace_back( | |
| 33 "Test", ThreadPriority::NORMAL, | |
| 34 SchedulerWorkerPoolParams::IORestriction::ALLOWED, 1, TimeDelta::Max()); | |
| 35 TaskScheduler::CreateAndSetDefaultTaskScheduler( | |
| 36 worker_pool_params_vector, Bind(&GetWorkerPoolIndexForTraits)); | |
| 37 } | |
| 38 | |
| 39 ScopedTaskScheduler::~ScopedTaskScheduler() { | |
| 40 DCHECK(TaskScheduler::GetInstance()); | |
|
robliao
2016/11/16 21:23:05
Maybe we can keep a pointer and check the pointer
fdoray
2016/11/16 22:04:45
Done.
| |
| 41 TaskScheduler::GetInstance()->Shutdown(); | |
| 42 TaskScheduler::GetInstance()->JoinForTesting(); | |
| 43 TaskScheduler::SetInstance(nullptr); | |
| 44 } | |
| 45 | |
| 46 } // namespace test | |
| 47 } // namespace base | |
| OLD | NEW |