OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_ | |
6 #define COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/time/time.h" | |
14 #include "components/scheduler/base/lazy_now.h" | |
15 #include "components/scheduler/base/task_queue_impl.h" | |
16 #include "components/scheduler/scheduler_export.h" | |
17 | |
18 namespace scheduler { | |
19 namespace internal { | |
20 class TaskQueueImpl; | |
21 } // internal | |
22 class TaskQueueManager; | |
23 | |
24 class SCHEDULER_EXPORT TimeDomain : public base::RefCounted<TimeDomain> { | |
25 public: | |
26 TimeDomain(); | |
27 | |
28 // Returns a LazyNow that evaluate this TimeDomain's Now. | |
29 virtual LazyNow GetLazyNow() = 0; | |
Sami
2015/11/19 13:01:03
nit: Create instead of Get?
Also, add a note that
alex clarke (OOO till 29th)
2015/11/19 13:54:48
Done.
| |
30 | |
31 // Some TimeDomains support virtual time, this method tells us to advance time | |
32 // if possible and return true if time was advanced. | |
33 virtual bool MaybeAdvanceTime() = 0; | |
34 | |
35 // Returns the name of this time domain for tracing. | |
36 virtual const char* GetName() const = 0; | |
37 | |
38 protected: | |
39 friend class internal::TaskQueueImpl; | |
40 friend class TaskQueueManager; | |
41 friend class base::RefCounted<TimeDomain>; | |
42 | |
43 virtual ~TimeDomain(); | |
44 | |
45 void AsValueInto(base::trace_event::TracedValue* state) const; | |
46 | |
47 // Migrates |queue| from this time domain to |destination_time_domain|. | |
48 void MigrateQueue(internal::TaskQueueImpl* queue, | |
49 TimeDomain* destination_time_domain); | |
50 | |
51 // If there is a scheduled delayed task, |out_time| is set to the scheduled | |
52 // runtime for the next one and it returns true. Returns false otherwise. | |
53 bool NextScheduledRunTime(base::TimeTicks* out_time) const; | |
54 | |
55 // If there is a scheduled delayed task, |out_task_queue| is set to the queue | |
56 // the next task was posted to and it returns true. Returns false otherwise. | |
57 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const; | |
58 | |
59 // Adds |queue| to the set of task queues that UpdateWorkQueues calls | |
60 // UpdateWorkQueue on. | |
61 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); | |
62 | |
63 // Schedules a call to TaskQueueImpl::MoveReadyDelayedTasksToIncomingQueue | |
64 // when this TimeDomain reaches |delayed_run_time|. | |
65 void ScheduleDelayedWork(internal::TaskQueueImpl* queue, | |
66 base::TimeTicks delayed_run_time, | |
67 LazyNow* lazy_now); | |
68 | |
69 // Removes |queue| from the set of task queues that UpdateWorkQueues calls | |
70 // UpdateWorkQueue on. | |
71 void UnregisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); | |
72 | |
73 // Removes |queue| from all internal data structures. | |
74 void UnregisterQueue(internal::TaskQueueImpl* queue); | |
75 | |
76 // Updates active queues associated with this TimeDomain. | |
77 void UpdateWorkQueues(bool should_trigger_wakeup, | |
78 const internal::TaskQueueImpl::Task* previous_task); | |
79 | |
80 // The implementaion will secedule task processing to run with |delay| with | |
81 // respect to the TimeDomain's time source. | |
82 virtual void RequestWakeup(base::TimeDelta delay) = 0; | |
83 | |
84 // For implementation specific tracing. | |
85 virtual void AsValueIntoInternal( | |
86 base::trace_event::TracedValue* state) const = 0; | |
87 | |
88 // Call TaskQueueImpl::MoveReadyDelayedTasksToIncomingQueue for each | |
89 // queue where the delay has elapsed. | |
90 void WakeupReadyDelayedQueues(LazyNow* lazy_now); | |
91 | |
92 private: | |
93 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet(); | |
94 | |
95 typedef std::multimap<base::TimeTicks, internal::TaskQueueImpl*> | |
96 DelayedWakeupMultimap; | |
97 | |
98 DelayedWakeupMultimap delayed_wakeup_multimap_; | |
99 | |
100 // This lock guards only |newly_updatable_|. It's not expected to be heavily | |
101 // contended. | |
102 base::Lock newly_updatable_lock_; | |
103 std::vector<internal::TaskQueueImpl*> newly_updatable_; | |
104 | |
105 // Set of task queues with avaliable work on the incoming queue. This should | |
106 // only be accessed from the main thread. | |
107 std::set<internal::TaskQueueImpl*> updatable_queue_set_; | |
108 | |
109 base::ThreadChecker main_thread_checker_; | |
110 base::WeakPtrFactory<TimeDomain> weak_factory_; | |
111 | |
112 DISALLOW_COPY_AND_ASSIGN(TimeDomain); | |
113 }; | |
114 | |
115 } // namespace scheduler | |
116 | |
117 #endif // COMPONENTS_SCHEDULER_BASE_TIME_DOMAIN_H_ | |
OLD | NEW |