[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / components / scheduler / child / worker_scheduler_impl.cc
blobb5b9c83af8c21e8c3e04772c5cf711343e8a7c54
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/nestable_single_thread_task_runner.h"
12 namespace scheduler {
14 WorkerSchedulerImpl::WorkerSchedulerImpl(
15 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner)
16 : helper_(main_task_runner,
17 "worker.scheduler",
18 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"),
19 TRACE_DISABLED_BY_DEFAULT("worker.scheduler.debug"),
20 TASK_QUEUE_COUNT),
21 idle_helper_(&helper_,
22 this,
23 IDLE_TASK_QUEUE,
24 "worker.scheduler",
25 TRACE_DISABLED_BY_DEFAULT("worker.scheduler"),
26 "WorkerSchedulerIdlePeriod",
27 base::TimeDelta::FromMilliseconds(300)) {
28 initialized_ = false;
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() {
39 initialized_ = true;
40 idle_helper_.EnableLongIdlePeriod();
43 scoped_refptr<base::SingleThreadTaskRunner>
44 WorkerSchedulerImpl::DefaultTaskRunner() {
45 DCHECK(initialized_);
46 return helper_.DefaultTaskRunner();
49 scoped_refptr<SingleThreadIdleTaskRunner>
50 WorkerSchedulerImpl::IdleTaskRunner() {
51 DCHECK(initialized_);
52 return idle_helper_.IdleTaskRunner();
55 bool WorkerSchedulerImpl::CanExceedIdleDeadlineIfRequired() const {
56 DCHECK(initialized_);
57 return idle_helper_.CanExceedIdleDeadlineIfRequired();
60 bool WorkerSchedulerImpl::ShouldYieldForHighPriorityWork() {
61 // We don't consider any work as being high priority on workers.
62 return false;
65 void WorkerSchedulerImpl::AddTaskObserver(
66 base::MessageLoop::TaskObserver* task_observer) {
67 DCHECK(initialized_);
68 helper_.AddTaskObserver(task_observer);
71 void WorkerSchedulerImpl::RemoveTaskObserver(
72 base::MessageLoop::TaskObserver* task_observer) {
73 DCHECK(initialized_);
74 helper_.RemoveTaskObserver(task_observer);
77 void WorkerSchedulerImpl::Shutdown() {
78 DCHECK(initialized_);
79 helper_.Shutdown();
82 SchedulerHelper* WorkerSchedulerImpl::GetSchedulerHelperForTesting() {
83 return &helper_;
86 bool WorkerSchedulerImpl::CanEnterLongIdlePeriod(base::TimeTicks,
87 base::TimeDelta*) {
88 return true;
91 base::TimeTicks WorkerSchedulerImpl::CurrentIdleTaskDeadlineForTesting() const {
92 return idle_helper_.CurrentIdleTaskDeadline();
95 } // namespace scheduler