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 "components/scheduler/child/worker_scheduler_impl.h"
8 #include "base/trace_event/trace_event.h"
9 #include "base/trace_event/trace_event_argument.h"
10 #include "components/scheduler/child/nestable_single_thread_task_runner.h"
14 WorkerSchedulerImpl::WorkerSchedulerImpl(
15 scoped_refptr
<NestableSingleThreadTaskRunner
> main_task_runner
)
16 : helper_(main_task_runner
,
18 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"),
19 TRACE_DISABLED_BY_DEFAULT("worker.scheduler.debug"),
21 idle_helper_(&helper_
,
25 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"),
26 "WorkerSchedulerIdlePeriod",
27 base::TimeDelta::FromMilliseconds(300)) {
29 TRACE_EVENT_OBJECT_CREATED_WITH_ID(
30 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"), "WorkerScheduler", this);
33 WorkerSchedulerImpl::~WorkerSchedulerImpl() {
34 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
35 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"), "WorkerScheduler", this);
38 void WorkerSchedulerImpl::Init() {
40 idle_helper_
.EnableLongIdlePeriod();
43 scoped_refptr
<base::SingleThreadTaskRunner
>
44 WorkerSchedulerImpl::DefaultTaskRunner() {
46 return helper_
.DefaultTaskRunner();
49 scoped_refptr
<SingleThreadIdleTaskRunner
>
50 WorkerSchedulerImpl::IdleTaskRunner() {
52 return idle_helper_
.IdleTaskRunner();
55 bool WorkerSchedulerImpl::CanExceedIdleDeadlineIfRequired() const {
57 return idle_helper_
.CanExceedIdleDeadlineIfRequired();
60 bool WorkerSchedulerImpl::ShouldYieldForHighPriorityWork() {
61 // We don't consider any work as being high priority on workers.
65 void WorkerSchedulerImpl::AddTaskObserver(
66 base::MessageLoop::TaskObserver
* task_observer
) {
68 helper_
.AddTaskObserver(task_observer
);
71 void WorkerSchedulerImpl::RemoveTaskObserver(
72 base::MessageLoop::TaskObserver
* task_observer
) {
74 helper_
.RemoveTaskObserver(task_observer
);
77 void WorkerSchedulerImpl::Shutdown() {
82 SchedulerHelper
* WorkerSchedulerImpl::GetSchedulerHelperForTesting() {
86 bool WorkerSchedulerImpl::CanEnterLongIdlePeriod(base::TimeTicks
,
91 base::TimeTicks
WorkerSchedulerImpl::CurrentIdleTaskDeadlineForTesting() const {
92 return idle_helper_
.CurrentIdleTaskDeadline();
95 } // namespace scheduler