Roll src/third_party/WebKit 605a979:06cb9e9 (svn 202556:202558)
[chromium-blink-merge.git] / components / scheduler / child / worker_scheduler_impl.cc
blob78103420ecb3d7ef8c0ea0ab29bce0f609fb6014
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"
7 #include "base/bind.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"
13 namespace scheduler {
15 WorkerSchedulerImpl::WorkerSchedulerImpl(
16 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner)
17 : helper_(main_task_runner,
18 "worker.scheduler",
19 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"),
20 TRACE_DISABLED_BY_DEFAULT("worker.scheduler.debug")),
21 idle_helper_(&helper_,
22 this,
23 "worker.scheduler",
24 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"),
25 "WorkerSchedulerIdlePeriod",
26 base::TimeDelta::FromMilliseconds(300)) {
27 initialized_ = false;
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() {
38 initialized_ = true;
39 idle_helper_.EnableLongIdlePeriod();
42 scoped_refptr<TaskQueue> WorkerSchedulerImpl::DefaultTaskRunner() {
43 DCHECK(initialized_);
44 return helper_.DefaultTaskRunner();
47 scoped_refptr<SingleThreadIdleTaskRunner>
48 WorkerSchedulerImpl::IdleTaskRunner() {
49 DCHECK(initialized_);
50 return idle_helper_.IdleTaskRunner();
53 bool WorkerSchedulerImpl::CanExceedIdleDeadlineIfRequired() const {
54 DCHECK(initialized_);
55 return idle_helper_.CanExceedIdleDeadlineIfRequired();
58 bool WorkerSchedulerImpl::ShouldYieldForHighPriorityWork() {
59 // We don't consider any work as being high priority on workers.
60 return false;
63 void WorkerSchedulerImpl::AddTaskObserver(
64 base::MessageLoop::TaskObserver* task_observer) {
65 DCHECK(initialized_);
66 helper_.AddTaskObserver(task_observer);
69 void WorkerSchedulerImpl::RemoveTaskObserver(
70 base::MessageLoop::TaskObserver* task_observer) {
71 DCHECK(initialized_);
72 helper_.RemoveTaskObserver(task_observer);
75 void WorkerSchedulerImpl::Shutdown() {
76 DCHECK(initialized_);
77 helper_.Shutdown();
80 SchedulerHelper* WorkerSchedulerImpl::GetSchedulerHelperForTesting() {
81 return &helper_;
84 bool WorkerSchedulerImpl::CanEnterLongIdlePeriod(base::TimeTicks,
85 base::TimeDelta*) {
86 return true;
89 base::TimeTicks WorkerSchedulerImpl::CurrentIdleTaskDeadlineForTesting() const {
90 return idle_helper_.CurrentIdleTaskDeadline();
93 } // namespace scheduler