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"
12 SingleThreadIdleTaskRunner::SingleThreadIdleTaskRunner(
13 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner
,
14 base::Callback
<void(base::TimeTicks
*)> deadline_supplier
)
15 : task_runner_(task_runner
), deadline_supplier_(deadline_supplier
) {
18 SingleThreadIdleTaskRunner::~SingleThreadIdleTaskRunner() {
21 bool SingleThreadIdleTaskRunner::RunsTasksOnCurrentThread() const {
22 return task_runner_
->RunsTasksOnCurrentThread();
25 void SingleThreadIdleTaskRunner::PostIdleTask(
26 const tracked_objects::Location
& from_here
,
27 const IdleTask
& idle_task
) {
28 task_runner_
->PostTask(
30 base::Bind(&SingleThreadIdleTaskRunner::RunTask
, this, idle_task
));
33 void SingleThreadIdleTaskRunner::RunTask(IdleTask idle_task
) {
34 base::TimeTicks deadline
;
35 deadline_supplier_
.Run(&deadline
);
36 TRACE_EVENT1("renderer.scheduler",
37 "SingleThreadIdleTaskRunner::RunTask", "allotted_time_ms",
38 (deadline
- base::TimeTicks::Now()).InMillisecondsF());
39 idle_task
.Run(deadline
);
41 TRACE_EVENT_CATEGORY_GROUP_ENABLED("renderer.scheduler", &is_tracing
);
42 if (is_tracing
&& base::TimeTicks::Now() > deadline
) {
43 TRACE_EVENT_INSTANT0("renderer.scheduler",
44 "SingleThreadIdleTaskRunner::DidOverrunDeadline",
45 TRACE_EVENT_SCOPE_THREAD
);
49 } // namespace content