1 // Copyright 2015 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 #ifndef CONTENT_CHILD_SCHEDULER_WORKER_SCHEDULER_H_
6 #define CONTENT_CHILD_SCHEDULER_WORKER_SCHEDULER_H_
8 #include "base/message_loop/message_loop.h"
9 #include "content/child/scheduler/single_thread_idle_task_runner.h"
10 #include "content/common/content_export.h"
18 class CONTENT_EXPORT WorkerScheduler
{
20 virtual ~WorkerScheduler();
21 static scoped_ptr
<WorkerScheduler
> Create(base::MessageLoop
* message_loop
);
23 // Must be called before the scheduler can be used. Does any post construction
24 // initialization needed such as initializing idle period detection.
25 virtual void Init() = 0;
27 // Returns the default task runner.
28 virtual scoped_refptr
<base::SingleThreadTaskRunner
> DefaultTaskRunner() = 0;
30 // Returns the idle task runner. Tasks posted to this runner may be reordered
31 // relative to other task types and may be starved for an arbitrarily long
32 // time if no idle time is available.
33 virtual scoped_refptr
<SingleThreadIdleTaskRunner
> IdleTaskRunner() = 0;
35 // Returns true if a currently running idle task could exceed its deadline
36 // without impacting user experience too much. This should only be used if
37 // there is a task which cannot be pre-empted and is likely to take longer
38 // than the largest expected idle task deadline. It should NOT be polled to
39 // check whether more work can be performed on the current idle task after
40 // its deadline has expired - post a new idle task for the continuation of the
42 // Must be called from the worker's thread.
43 virtual bool CanExceedIdleDeadlineIfRequired() const = 0;
45 // Adds or removes a task observer from the scheduler. The observer will be
46 // notified before and after every executed task. These functions can only be
47 // called on the main thread.
48 virtual void AddTaskObserver(
49 base::MessageLoop::TaskObserver
* task_observer
) = 0;
50 virtual void RemoveTaskObserver(
51 base::MessageLoop::TaskObserver
* task_observer
) = 0;
53 // Shuts down the scheduler by dropping any remaining pending work in the work
54 // queues. After this call any work posted to the task runners will be
56 virtual void Shutdown() = 0;
60 DISALLOW_COPY_AND_ASSIGN(WorkerScheduler
);
63 } // namespace content
65 #endif // CONTENT_CHILD_SCHEDULER_WORKER_SCHEDULER_H_