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

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

Issue 2622633004: Add base::test::ScopedAsyncTaskScheduler. (Closed)
Patch Set: CR gab #11 (grammar) Created 3 years, 11 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_async_task_scheduler.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/test/scoped_async_task_scheduler.h"
6
7 #include <vector>
8
9 #include "base/bind.h"
10 #include "base/logging.h"
11 #include "base/task_scheduler/scheduler_worker_pool_params.h"
12 #include "base/task_scheduler/task_scheduler.h"
13
14 namespace base {
15 namespace test {
16
17 ScopedAsyncTaskScheduler::ScopedAsyncTaskScheduler() {
18 DCHECK(!TaskScheduler::GetInstance());
19 constexpr int kMaxThreads = 1;
20 const TimeDelta kSuggestedReclaimTime = TimeDelta::Max();
21 std::vector<SchedulerWorkerPoolParams> worker_pool_params_vector;
22 worker_pool_params_vector.emplace_back(
23 "ScopedAsyncTaskScheduler", ThreadPriority::NORMAL,
24 SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY, kMaxThreads,
25 kSuggestedReclaimTime);
26 TaskScheduler::CreateAndSetDefaultTaskScheduler(
27 worker_pool_params_vector,
28 Bind([](const TaskTraits&) -> size_t { return 0; }));
29 task_scheduler_ = TaskScheduler::GetInstance();
30 }
31
32 ScopedAsyncTaskScheduler::~ScopedAsyncTaskScheduler() {
33 DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_);
34 TaskScheduler::GetInstance()->Shutdown();
35 TaskScheduler::SetInstance(nullptr);
36 }
37
38 } // namespace test
39 } // namespace base
OLDNEW
« no previous file with comments | « base/test/scoped_async_task_scheduler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698