ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / renderer / scheduler / single_thread_idle_task_runner.cc
blobb6eb5ce9c64079a9b601e9c0f1467c164c63341c
1 // Copyright 2014 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.
5 #include "content/renderer/scheduler/single_thread_idle_task_runner.h"
7 #include "base/location.h"
8 #include "base/trace_event/trace_event.h"
10 namespace content {
12 SingleThreadIdleTaskRunner::SingleThreadIdleTaskRunner(
13 scoped_refptr<base::SingleThreadTaskRunner> idle_priority_task_runner,
14 scoped_refptr<base::SingleThreadTaskRunner> after_wakeup_task_runner,
15 base::Callback<void(base::TimeTicks*)> deadline_supplier)
16 : idle_priority_task_runner_(idle_priority_task_runner),
17 after_wakeup_task_runner_(after_wakeup_task_runner),
18 deadline_supplier_(deadline_supplier) {
19 DCHECK(idle_priority_task_runner_->RunsTasksOnCurrentThread());
20 DCHECK(after_wakeup_task_runner_->RunsTasksOnCurrentThread());
23 SingleThreadIdleTaskRunner::~SingleThreadIdleTaskRunner() {
26 bool SingleThreadIdleTaskRunner::RunsTasksOnCurrentThread() const {
27 return idle_priority_task_runner_->RunsTasksOnCurrentThread();
30 void SingleThreadIdleTaskRunner::PostIdleTask(
31 const tracked_objects::Location& from_here,
32 const IdleTask& idle_task) {
33 idle_priority_task_runner_->PostTask(
34 from_here,
35 base::Bind(&SingleThreadIdleTaskRunner::RunTask, this, idle_task));
38 void SingleThreadIdleTaskRunner::PostIdleTaskAfterWakeup(
39 const tracked_objects::Location& from_here,
40 const IdleTask& idle_task) {
41 after_wakeup_task_runner_->PostTask(
42 FROM_HERE, base::Bind(&SingleThreadIdleTaskRunner::PostIdleTask, this,
43 from_here, idle_task));
46 void SingleThreadIdleTaskRunner::RunTask(IdleTask idle_task) {
47 base::TimeTicks deadline;
48 deadline_supplier_.Run(&deadline);
49 TRACE_EVENT1("renderer.scheduler",
50 "SingleThreadIdleTaskRunner::RunTask", "allotted_time_ms",
51 (deadline - base::TimeTicks::Now()).InMillisecondsF());
52 idle_task.Run(deadline);
53 bool is_tracing;
54 TRACE_EVENT_CATEGORY_GROUP_ENABLED("renderer.scheduler", &is_tracing);
55 if (is_tracing && base::TimeTicks::Now() > deadline) {
56 TRACE_EVENT_INSTANT0("renderer.scheduler",
57 "SingleThreadIdleTaskRunner::DidOverrunDeadline",
58 TRACE_EVENT_SCOPE_THREAD);
62 } // namespace content