Roll src/third_party/WebKit 605a979:06cb9e9 (svn 202556:202558)
[chromium-blink-merge.git] / components / scheduler / child / child_scheduler.h
blob028b12c315d62ce5c20b9e5f222c6294cc7d46fe
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 COMPONENTS_SCHEDULER_CHILD_CHILD_SCHEDULER_H_
6 #define COMPONENTS_SCHEDULER_CHILD_CHILD_SCHEDULER_H_
8 #include "base/message_loop/message_loop.h"
9 #include "components/scheduler/child/single_thread_idle_task_runner.h"
10 #include "components/scheduler/child/task_queue.h"
11 #include "components/scheduler/scheduler_export.h"
13 namespace base {
14 class MessageLoop;
17 namespace scheduler {
19 class SCHEDULER_EXPORT ChildScheduler {
20 public:
21 virtual ~ChildScheduler() {}
23 // Returns the default task runner.
24 // TODO(alexclarke): Change this to return a SingleThreadIdleTaskRunner.
25 virtual scoped_refptr<TaskQueue> DefaultTaskRunner() = 0;
27 // Returns the idle task runner. Tasks posted to this runner may be reordered
28 // relative to other task types and may be starved for an arbitrarily long
29 // time if no idle time is available.
30 virtual scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() = 0;
32 // Returns true if there is high priority work pending on the main thread
33 // and the caller should yield to let the scheduler service that work. Note
34 // that this is a stricter condition than |IsHighPriorityWorkAnticipated|,
35 // restricted to the case where real work is pending.
36 // Must be called from the thread this scheduler was created on.
37 virtual bool ShouldYieldForHighPriorityWork() = 0;
39 // Returns true if a currently running idle task could exceed its deadline
40 // without impacting user experience too much. This should only be used if
41 // there is a task which cannot be pre-empted and is likely to take longer
42 // than the largest expected idle task deadline. It should NOT be polled to
43 // check whether more work can be performed on the current idle task after
44 // its deadline has expired - post a new idle task for the continuation of the
45 // work in this case.
46 // Must be called from the thread this scheduler was created on.
47 virtual bool CanExceedIdleDeadlineIfRequired() const = 0;
49 // Adds or removes a task observer from the scheduler. The observer will be
50 // notified before and after every executed task. These functions can only be
51 // called on the thread this scheduler was created on.
52 virtual void AddTaskObserver(
53 base::MessageLoop::TaskObserver* task_observer) = 0;
54 virtual void RemoveTaskObserver(
55 base::MessageLoop::TaskObserver* task_observer) = 0;
57 // Shuts down the scheduler by dropping any remaining pending work in the work
58 // queues. After this call any work posted to the task runners will be
59 // silently dropped.
60 virtual void Shutdown() = 0;
62 protected:
63 ChildScheduler() {}
64 DISALLOW_COPY_AND_ASSIGN(ChildScheduler);
67 } // namespace scheduler
69 #endif // COMPONENTS_SCHEDULER_CHILD_CHILD_SCHEDULER_H_