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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/test/scoped_async_task_scheduler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/scoped_async_task_scheduler.cc
diff --git a/base/test/scoped_async_task_scheduler.cc b/base/test/scoped_async_task_scheduler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..824b07fba930680f9a019f4a10fc044a1269ba55
--- /dev/null
+++ b/base/test/scoped_async_task_scheduler.cc
@@ -0,0 +1,39 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/test/scoped_async_task_scheduler.h"
+
+#include <vector>
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/task_scheduler/scheduler_worker_pool_params.h"
+#include "base/task_scheduler/task_scheduler.h"
+
+namespace base {
+namespace test {
+
+ScopedAsyncTaskScheduler::ScopedAsyncTaskScheduler() {
+ DCHECK(!TaskScheduler::GetInstance());
+ constexpr int kMaxThreads = 1;
+ const TimeDelta kSuggestedReclaimTime = TimeDelta::Max();
+ std::vector<SchedulerWorkerPoolParams> worker_pool_params_vector;
+ worker_pool_params_vector.emplace_back(
+ "ScopedAsyncTaskScheduler", ThreadPriority::NORMAL,
+ SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY, kMaxThreads,
+ kSuggestedReclaimTime);
+ TaskScheduler::CreateAndSetDefaultTaskScheduler(
+ worker_pool_params_vector,
+ Bind([](const TaskTraits&) -> size_t { return 0; }));
+ task_scheduler_ = TaskScheduler::GetInstance();
+}
+
+ScopedAsyncTaskScheduler::~ScopedAsyncTaskScheduler() {
+ DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_);
+ TaskScheduler::GetInstance()->Shutdown();
+ TaskScheduler::SetInstance(nullptr);
+}
+
+} // namespace test
+} // namespace base
« 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