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

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

Issue 1151353003: [scheduler]: Avoid waking up the scheduler to end long idle periods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@end_idle_sync_2
Patch Set: Created 5 years, 7 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_SCHEDULER_CHILD_SINGLE_THREAD_IDLE_TASK_RUNNER_H_ 5 #ifndef COMPONENTS_SCHEDULER_CHILD_SINGLE_THREAD_IDLE_TASK_RUNNER_H_
6 #define COMPONENTS_SCHEDULER_CHILD_SINGLE_THREAD_IDLE_TASK_RUNNER_H_ 6 #define COMPONENTS_SCHEDULER_CHILD_SINGLE_THREAD_IDLE_TASK_RUNNER_H_
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "components/scheduler/scheduler_export.h"
13 14
14 namespace scheduler { 15 namespace scheduler {
15 16
16 // A SingleThreadIdleTaskRunner is a task runner for running idle tasks. Idle 17 // A SingleThreadIdleTaskRunner is a task runner for running idle tasks. Idle
17 // tasks have an unbound argument which is bound to a deadline 18 // tasks have an unbound argument which is bound to a deadline
18 // (in base::TimeTicks) when they are run. The idle task is expected to 19 // (in base::TimeTicks) when they are run. The idle task is expected to
19 // complete by this deadline. 20 // complete by this deadline.
20 class SingleThreadIdleTaskRunner 21 class SingleThreadIdleTaskRunner
21 : public base::RefCountedThreadSafe<SingleThreadIdleTaskRunner> { 22 : public base::RefCountedThreadSafe<SingleThreadIdleTaskRunner> {
22 public: 23 public:
23 typedef base::Callback<void(base::TimeTicks)> IdleTask; 24 typedef base::Callback<void(base::TimeTicks)> IdleTask;
24 25
26 // Used request idle task deadlines and signal posting of idle tasks.
Sami 2015/05/26 13:35:41 "Used to"?
rmcilroy 2015/05/27 11:58:37 Done.
27 class SCHEDULER_EXPORT Observer {
Sami 2015/05/26 13:35:41 "Delegate" or "Controller" perhaps since I think c
rmcilroy 2015/05/27 11:58:37 Yeah (I originally had Delegate, then moved to Obs
28 public:
29 Observer();
30 virtual ~Observer();
31
32 // Signals that an idle task has been posted.
33 virtual void OnIdleTaskPosted() = 0;
Sami 2015/05/26 13:35:41 Maybe mention that this will be called on the post
rmcilroy 2015/05/27 11:58:37 Done.
34
35 // Signals that a new idle task is about to be run and returns the deadline
36 // for this idle task.
37 virtual void OnWillRunIdleTask(base::TimeTicks* deadline_out) const = 0;
Sami 2015/05/26 13:35:41 Could we name these WillProcessIdleTask/DidProcess
rmcilroy 2015/05/27 11:58:37 Done.
38
39 // Signals that an idle task has finished being run.
40 virtual void OnDidRunIdleTask() = 0;
41
42 private:
43 DISALLOW_COPY_AND_ASSIGN(Observer);
44 };
45
46
25 // NOTE Category strings must have application lifetime (statics or 47 // NOTE Category strings must have application lifetime (statics or
26 // literals). They may not include " chars. 48 // literals). They may not include " chars.
27 SingleThreadIdleTaskRunner( 49 SingleThreadIdleTaskRunner(
28 scoped_refptr<base::SingleThreadTaskRunner> idle_priority_task_runner, 50 scoped_refptr<base::SingleThreadTaskRunner> idle_priority_task_runner,
29 scoped_refptr<base::SingleThreadTaskRunner> after_wakeup_task_runner, 51 scoped_refptr<base::SingleThreadTaskRunner> after_wakeup_task_runner,
30 base::Callback<void(base::TimeTicks*)> deadline_supplier, 52 Observer* observer,
31 const char* tracing_category); 53 const char* tracing_category);
32 54
33 virtual void PostIdleTask(const tracked_objects::Location& from_here, 55 virtual void PostIdleTask(const tracked_objects::Location& from_here,
34 const IdleTask& idle_task); 56 const IdleTask& idle_task);
35 57
36 virtual void PostNonNestableIdleTask( 58 virtual void PostNonNestableIdleTask(
37 const tracked_objects::Location& from_here, 59 const tracked_objects::Location& from_here,
38 const IdleTask& idle_task); 60 const IdleTask& idle_task);
39 61
40 virtual void PostIdleTaskAfterWakeup( 62 virtual void PostIdleTaskAfterWakeup(
41 const tracked_objects::Location& from_here, 63 const tracked_objects::Location& from_here,
42 const IdleTask& idle_task); 64 const IdleTask& idle_task);
43 65
44 bool RunsTasksOnCurrentThread() const; 66 bool RunsTasksOnCurrentThread() const;
45 67
46 protected: 68 protected:
47 virtual ~SingleThreadIdleTaskRunner(); 69 virtual ~SingleThreadIdleTaskRunner();
48 70
49 private: 71 private:
50 friend class base::RefCountedThreadSafe<SingleThreadIdleTaskRunner>; 72 friend class base::RefCountedThreadSafe<SingleThreadIdleTaskRunner>;
51 73
52 void RunTask(IdleTask idle_task); 74 void RunTask(IdleTask idle_task);
53 75
54 scoped_refptr<base::SingleThreadTaskRunner> idle_priority_task_runner_; 76 scoped_refptr<base::SingleThreadTaskRunner> idle_priority_task_runner_;
55 scoped_refptr<base::SingleThreadTaskRunner> after_wakeup_task_runner_; 77 scoped_refptr<base::SingleThreadTaskRunner> after_wakeup_task_runner_;
56 base::Callback<void(base::TimeTicks*)> deadline_supplier_; 78 Observer* observer_; // NOT OWNED
57 const char* tracing_category_; 79 const char* tracing_category_;
58 base::WeakPtr<SingleThreadIdleTaskRunner> weak_scheduler_ptr_; 80 base::WeakPtr<SingleThreadIdleTaskRunner> weak_scheduler_ptr_;
59 base::WeakPtrFactory<SingleThreadIdleTaskRunner> weak_factory_; 81 base::WeakPtrFactory<SingleThreadIdleTaskRunner> weak_factory_;
60 DISALLOW_COPY_AND_ASSIGN(SingleThreadIdleTaskRunner); 82 DISALLOW_COPY_AND_ASSIGN(SingleThreadIdleTaskRunner);
61 }; 83 };
62 84
63 } // namespace scheduler 85 } // namespace scheduler
64 86
65 #endif // COMPONENTS_SCHEDULER_CHILD_SINGLE_THREAD_IDLE_TASK_RUNNER_H_ 87 #endif // COMPONENTS_SCHEDULER_CHILD_SINGLE_THREAD_IDLE_TASK_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698