Andreas Haas | c13cae8 | 2017-11-16 12:54:38 | [diff] [blame] | 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 "gin/v8_foreground_task_runner.h" |
| 6 | |
| 7 | #include "base/bind.h" |
| 8 | #include "base/bind_helpers.h" |
| 9 | #include "base/single_thread_task_runner.h" |
| 10 | #include "base/threading/thread_task_runner_handle.h" |
| 11 | |
| 12 | namespace gin { |
| 13 | |
| 14 | V8ForegroundTaskRunner::V8ForegroundTaskRunner( |
| 15 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 16 | : task_runner_(std::move(task_runner)) { |
| 17 | DCHECK(task_runner_); |
| 18 | } |
| 19 | |
Chris Watkins | 756035a | 2017-12-01 03:03:27 | [diff] [blame] | 20 | V8ForegroundTaskRunner::~V8ForegroundTaskRunner() = default; |
Andreas Haas | c13cae8 | 2017-11-16 12:54:38 | [diff] [blame] | 21 | |
| 22 | void V8ForegroundTaskRunner::PostTask(std::unique_ptr<v8::Task> task) { |
| 23 | task_runner_->PostTask(FROM_HERE, |
| 24 | base::BindOnce(&v8::Task::Run, std::move(task))); |
| 25 | } |
| 26 | |
| 27 | void V8ForegroundTaskRunner::PostDelayedTask(std::unique_ptr<v8::Task> task, |
| 28 | double delay_in_seconds) { |
| 29 | task_runner_->PostDelayedTask( |
| 30 | FROM_HERE, base::BindOnce(&v8::Task::Run, std::move(task)), |
| 31 | base::TimeDelta::FromSecondsD(delay_in_seconds)); |
| 32 | } |
| 33 | |
| 34 | void V8ForegroundTaskRunner::PostIdleTask(std::unique_ptr<v8::IdleTask> task) { |
| 35 | DCHECK(IdleTasksEnabled()); |
Jeremy Roman | 4ab1ed7 | 2018-06-12 13:42:21 | [diff] [blame^] | 36 | idle_task_runner()->PostIdleTask(std::move(task)); |
Andreas Haas | c13cae8 | 2017-11-16 12:54:38 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | } // namespace gin |