1 // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that can
3 // be found in the LICENSE file.
4
5 #include "include/cef_task.h"
6 #include "libcef/common/task_runner_impl.h"
7
8 #include "base/bind.h"
9 #include "base/location.h"
10 #include "base/logging.h"
11
CefCurrentlyOn(CefThreadId threadId)12 bool CefCurrentlyOn(CefThreadId threadId) {
13 scoped_refptr<base::SequencedTaskRunner> task_runner =
14 CefTaskRunnerImpl::GetTaskRunner(threadId);
15 if (task_runner.get()) {
16 return task_runner->RunsTasksInCurrentSequence();
17 }
18
19 LOG(WARNING) << "No task runner for threadId " << threadId;
20 return false;
21 }
22
CefPostTask(CefThreadId threadId,CefRefPtr<CefTask> task)23 bool CefPostTask(CefThreadId threadId, CefRefPtr<CefTask> task) {
24 scoped_refptr<base::SequencedTaskRunner> task_runner =
25 CefTaskRunnerImpl::GetTaskRunner(threadId);
26 if (task_runner.get()) {
27 return task_runner->PostTask(FROM_HERE,
28 base::BindOnce(&CefTask::Execute, task.get()));
29 }
30
31 LOG(WARNING) << "No task runner for threadId " << threadId;
32 return false;
33 }
34
CefPostDelayedTask(CefThreadId threadId,CefRefPtr<CefTask> task,int64 delay_ms)35 bool CefPostDelayedTask(CefThreadId threadId,
36 CefRefPtr<CefTask> task,
37 int64 delay_ms) {
38 scoped_refptr<base::SequencedTaskRunner> task_runner =
39 CefTaskRunnerImpl::GetTaskRunner(threadId);
40 if (task_runner.get()) {
41 return task_runner->PostDelayedTask(
42 FROM_HERE, base::BindOnce(&CefTask::Execute, task.get()),
43 base::Milliseconds(delay_ms));
44 }
45
46 LOG(WARNING) << "No task runner for threadId " << threadId;
47 return false;
48 }
49