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

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

Issue 2511473004: Create base::test::ScopedTaskScheduler. (Closed)
Patch Set: Use CreateAndSetSimpleTaskScheduler add const 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/test/scoped_task_scheduler.h ('k') | base/threading/sequenced_worker_pool_unittest.cc » ('j') | 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 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&) {
danakj 2016/11/17 00:48:01 Not used?
fdoray 2016/11/17 13:25:25 Done.
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 TaskScheduler::CreateAndSetSimpleTaskScheduler(1, base::TimeDelta::Max());
32 task_scheduler_ = TaskScheduler::GetInstance();
33 }
34
35 ScopedTaskScheduler::~ScopedTaskScheduler() {
36 DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance());
37 TaskScheduler::GetInstance()->Shutdown();
38 TaskScheduler::GetInstance()->JoinForTesting();
39 TaskScheduler::SetInstance(nullptr);
40 }
41
42 } // namespace test
43 } // namespace base
OLDNEW
« no previous file with comments | « base/test/scoped_task_scheduler.h ('k') | base/threading/sequenced_worker_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698