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/scheduler_task_runner_delegate.h"
11 #include "components/scheduler/child/task_queue.h"
15 WorkerSchedulerImpl::WorkerSchedulerImpl(
16 scoped_refptr
<SchedulerTaskRunnerDelegate
> main_task_runner
)
17 : helper_(main_task_runner
,
19 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"),
20 TRACE_DISABLED_BY_DEFAULT("worker.scheduler.debug")),
21 idle_helper_(&helper_
,
24 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"),
25 "WorkerSchedulerIdlePeriod",
26 base::TimeDelta::FromMilliseconds(300)) {
28 TRACE_EVENT_OBJECT_CREATED_WITH_ID(
29 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"), "WorkerScheduler", this);
32 WorkerSchedulerImpl::~WorkerSchedulerImpl() {
33 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
34 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"), "WorkerScheduler", this);
37 void WorkerSchedulerImpl::Init() {
39 idle_helper_
.EnableLongIdlePeriod();
42 scoped_refptr
<TaskQueue
> WorkerSchedulerImpl::DefaultTaskRunner() {
44 return helper_
.DefaultTaskRunner();
47 scoped_refptr
<SingleThreadIdleTaskRunner
>
48 WorkerSchedulerImpl::IdleTaskRunner() {
50 return idle_helper_
.IdleTaskRunner();
53 bool WorkerSchedulerImpl::CanExceedIdleDeadlineIfRequired() const {
55 return idle_helper_
.CanExceedIdleDeadlineIfRequired();
58 bool WorkerSchedulerImpl::ShouldYieldForHighPriorityWork() {
59 // We don't consider any work as being high priority on workers.
63 void WorkerSchedulerImpl::AddTaskObserver(
64 base::MessageLoop::TaskObserver
* task_observer
) {
66 helper_
.AddTaskObserver(task_observer
);
69 void WorkerSchedulerImpl::RemoveTaskObserver(
70 base::MessageLoop::TaskObserver
* task_observer
) {
72 helper_
.RemoveTaskObserver(task_observer
);
75 void WorkerSchedulerImpl::Shutdown() {
80 SchedulerHelper
* WorkerSchedulerImpl::GetSchedulerHelperForTesting() {
84 bool WorkerSchedulerImpl::CanEnterLongIdlePeriod(base::TimeTicks
,
89 base::TimeTicks
WorkerSchedulerImpl::CurrentIdleTaskDeadlineForTesting() const {
90 return idle_helper_
.CurrentIdleTaskDeadline();
93 } // namespace scheduler