Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: components/scheduler/child/single_thread_idle_task_runner.h

Issue 2118903002: scheduler: Move the Blink scheduler into Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef COMPONENTS_SCHEDULER_CHILD_SINGLE_THREAD_IDLE_TASK_RUNNER_H_
6 #define COMPONENTS_SCHEDULER_CHILD_SINGLE_THREAD_IDLE_TASK_RUNNER_H_
7
8 #include "base/bind.h"
9 #include "base/callback.h"
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/time/time.h"
14 #include "base/trace_event/trace_event.h"
15 #include "components/scheduler/scheduler_export.h"
16
17 namespace base {
18 namespace trace_event {
19 class BlameContext;
20 }
21 }
22
23 namespace scheduler {
24
25 // A SingleThreadIdleTaskRunner is a task runner for running idle tasks. Idle
26 // tasks have an unbound argument which is bound to a deadline
27 // (in base::TimeTicks) when they are run. The idle task is expected to
28 // complete by this deadline.
29 class SingleThreadIdleTaskRunner
30 : public base::RefCountedThreadSafe<SingleThreadIdleTaskRunner> {
31 public:
32 typedef base::Callback<void(base::TimeTicks)> IdleTask;
33
34 // Used to request idle task deadlines and signal posting of idle tasks.
35 class SCHEDULER_EXPORT Delegate {
36 public:
37 Delegate();
38 virtual ~Delegate();
39
40 // Signals that an idle task has been posted. This will be called on the
41 // posting thread, which may not be the same thread as the
42 // SingleThreadIdleTaskRunner runs on.
43 virtual void OnIdleTaskPosted() = 0;
44
45 // Signals that a new idle task is about to be run and returns the deadline
46 // for this idle task.
47 virtual base::TimeTicks WillProcessIdleTask() = 0;
48
49 // Signals that an idle task has finished being run.
50 virtual void DidProcessIdleTask() = 0;
51
52 private:
53 DISALLOW_COPY_AND_ASSIGN(Delegate);
54 };
55
56 // NOTE Category strings must have application lifetime (statics or
57 // literals). They may not include " chars.
58 SingleThreadIdleTaskRunner(
59 scoped_refptr<base::SingleThreadTaskRunner> idle_priority_task_runner,
60 scoped_refptr<base::SingleThreadTaskRunner> after_wakeup_task_runner,
61 Delegate* Delegate,
62 const char* tracing_category);
63
64 virtual void PostIdleTask(const tracked_objects::Location& from_here,
65 const IdleTask& idle_task);
66
67 virtual void PostNonNestableIdleTask(
68 const tracked_objects::Location& from_here,
69 const IdleTask& idle_task);
70
71 virtual void PostIdleTaskAfterWakeup(
72 const tracked_objects::Location& from_here,
73 const IdleTask& idle_task);
74
75 bool RunsTasksOnCurrentThread() const;
76
77 void SetBlameContext(base::trace_event::BlameContext* blame_context);
78
79 protected:
80 virtual ~SingleThreadIdleTaskRunner();
81
82 private:
83 friend class base::RefCountedThreadSafe<SingleThreadIdleTaskRunner>;
84
85 void RunTask(IdleTask idle_task);
86
87 scoped_refptr<base::SingleThreadTaskRunner> idle_priority_task_runner_;
88 scoped_refptr<base::SingleThreadTaskRunner> after_wakeup_task_runner_;
89 Delegate* delegate_; // NOT OWNED
90 const char* tracing_category_;
91 base::trace_event::BlameContext* blame_context_; // Not owned.
92 base::WeakPtr<SingleThreadIdleTaskRunner> weak_scheduler_ptr_;
93 base::WeakPtrFactory<SingleThreadIdleTaskRunner> weak_factory_;
94 DISALLOW_COPY_AND_ASSIGN(SingleThreadIdleTaskRunner);
95 };
96
97 } // namespace scheduler
98
99 #endif // COMPONENTS_SCHEDULER_CHILD_SINGLE_THREAD_IDLE_TASK_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698