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

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

Issue 1314903007: Implement WebFrameScheduler and WebPageScheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Responding to feedback Created 5 years, 3 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 2015 The Chromium Authors. All rights reserved. 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 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_SCHEDULER_HELPER_H_ 5 #ifndef COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_
6 #define COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ 6 #define COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_
7 7
8 #include "components/scheduler/child/task_queue_manager.h" 8 #include "components/scheduler/child/task_queue_manager.h"
9 #include "components/scheduler/child/task_queue_selector.h" 9 #include "components/scheduler/child/task_queue_selector.h"
10 #include "components/scheduler/scheduler_export.h" 10 #include "components/scheduler/scheduler_export.h"
11 11
12 namespace base { 12 namespace base {
13 class TickClock; 13 class TickClock;
14 } 14 }
15 15
16 namespace scheduler { 16 namespace scheduler {
17 17
18 class SchedulerTaskRunnerDelegate; 18 class SchedulerTaskRunnerDelegate;
19 19
20 // Common scheduler functionality for default tasks. 20 // Common scheduler functionality for default tasks.
21 class SCHEDULER_EXPORT SchedulerHelper { 21 class SCHEDULER_EXPORT SchedulerHelper : public TaskQueueManager::Observer {
22 public: 22 public:
23 // Category strings must have application lifetime (statics or 23 // Category strings must have application lifetime (statics or
24 // literals). They may not include " chars. 24 // literals). They may not include " chars.
25 SchedulerHelper(scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner, 25 SchedulerHelper(scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner,
26 const char* tracing_category, 26 const char* tracing_category,
27 const char* disabled_by_default_tracing_category, 27 const char* disabled_by_default_tracing_category,
28 const char* disabled_by_default_verbose_tracing_category); 28 const char* disabled_by_default_verbose_tracing_category);
29 ~SchedulerHelper(); 29 ~SchedulerHelper() override;
30
31 // TaskQueueManager::Observer implementation:
32 void OnUnregisterTaskQueue(
33 const scoped_refptr<internal::TaskQueueImpl>& queue) override;
30 34
31 // Returns the default task runner. 35 // Returns the default task runner.
32 scoped_refptr<TaskQueue> DefaultTaskRunner(); 36 scoped_refptr<TaskQueue> DefaultTaskRunner();
33 37
34 // Returns the control task runner. Tasks posted to this runner are executed 38 // Returns the control task runner. Tasks posted to this runner are executed
35 // with the highest priority. Care must be taken to avoid starvation of other 39 // with the highest priority. Care must be taken to avoid starvation of other
36 // task queues. 40 // task queues.
37 scoped_refptr<TaskQueue> ControlTaskRunner(); 41 scoped_refptr<TaskQueue> ControlTaskRunner();
38 42
39 // Returns the control task after wakeup runner. Tasks posted to this runner 43 // Returns the control task after wakeup runner. Tasks posted to this runner
(...skipping 15 matching lines...) Expand all
55 // Returns true if Shutdown() has been called. Otherwise returns false. 59 // Returns true if Shutdown() has been called. Otherwise returns false.
56 bool IsShutdown() const { return !task_queue_manager_.get(); } 60 bool IsShutdown() const { return !task_queue_manager_.get(); }
57 61
58 void CheckOnValidThread() const { 62 void CheckOnValidThread() const {
59 DCHECK(thread_checker_.CalledOnValidThread()); 63 DCHECK(thread_checker_.CalledOnValidThread());
60 } 64 }
61 65
62 // Creates a new TaskQueue with the given |spec|. 66 // Creates a new TaskQueue with the given |spec|.
63 scoped_refptr<TaskQueue> NewTaskQueue(const TaskQueue::Spec& spec); 67 scoped_refptr<TaskQueue> NewTaskQueue(const TaskQueue::Spec& spec);
64 68
69 class SCHEDULER_EXPORT Observer {
70 public:
71 virtual ~Observer() {}
72
73 // Called when |queue| is unregistered.
74 virtual void OnUnregisterTaskQueue(
75 const scoped_refptr<TaskQueue>& queue) = 0;
76 };
77
78 // Called once to set the Observer. This function is called on the main
79 // thread. If |observer| is null, then no callbacks will occur.
80 // Note |observer| is expected to outlive the SchedulerHelper.
81 void SetQueueObserver(Observer* observer);
82
65 // Accessor methods. 83 // Accessor methods.
66 base::TimeTicks Now() const; 84 base::TimeTicks Now() const;
67 base::TimeTicks NextPendingDelayedTaskRunTime() const; 85 base::TimeTicks NextPendingDelayedTaskRunTime() const;
68 bool GetAndClearSystemIsQuiescentBit(); 86 bool GetAndClearSystemIsQuiescentBit();
69 87
70 // Test helpers. 88 // Test helpers.
71 void SetTimeSourceForTesting(scoped_ptr<base::TickClock> time_source); 89 void SetTimeSourceForTesting(scoped_ptr<base::TickClock> time_source);
72 void SetWorkBatchSizeForTesting(size_t work_batch_size); 90 void SetWorkBatchSizeForTesting(size_t work_batch_size);
73 TaskQueueManager* GetTaskQueueManagerForTesting(); 91 TaskQueueManager* GetTaskQueueManagerForTesting();
74 92
75 private: 93 private:
76 friend class SchedulerHelperTest; 94 friend class SchedulerHelperTest;
77 95
78 base::ThreadChecker thread_checker_; 96 base::ThreadChecker thread_checker_;
79 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; 97 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_;
80 scoped_ptr<TaskQueueManager> task_queue_manager_; 98 scoped_ptr<TaskQueueManager> task_queue_manager_;
81 scoped_refptr<TaskQueue> control_task_runner_; 99 scoped_refptr<TaskQueue> control_task_runner_;
82 scoped_refptr<TaskQueue> control_after_wakeup_task_runner_; 100 scoped_refptr<TaskQueue> control_after_wakeup_task_runner_;
83 scoped_refptr<TaskQueue> default_task_runner_; 101 scoped_refptr<TaskQueue> default_task_runner_;
84 102
85 scoped_ptr<base::TickClock> time_source_; 103 scoped_ptr<base::TickClock> time_source_;
86 104
105 Observer* queue_observer_; // NOT OWNED
87 const char* tracing_category_; 106 const char* tracing_category_;
88 const char* disabled_by_default_tracing_category_; 107 const char* disabled_by_default_tracing_category_;
89 108
90 DISALLOW_COPY_AND_ASSIGN(SchedulerHelper); 109 DISALLOW_COPY_AND_ASSIGN(SchedulerHelper);
91 }; 110 };
92 111
93 } // namespace scheduler 112 } // namespace scheduler
94 113
95 #endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ 114 #endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698