| OLD | NEW |
| 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 THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ |
| 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "platform/scheduler/base/lazy_now.h" | 16 #include "platform/scheduler/base/lazy_now.h" |
| 17 #include "platform/scheduler/base/task_queue_impl.h" | 17 #include "platform/scheduler/base/task_queue_impl.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 namespace scheduler { | 20 namespace scheduler { |
| 21 namespace internal { | 21 namespace internal { |
| 22 class TaskQueueImpl; | 22 class TaskQueueImpl; |
| 23 } // internal | 23 } // internal |
| 24 class TaskQueueManager; | 24 class TaskQueueManager; |
| 25 class TaskQueueManagerDelegate; | 25 class TaskQueueManagerDelegate; |
| 26 | 26 |
| 27 // The TimeDomain's job is to keep track of moments when delayed tasks have been |
| 28 // scheduled to fire and to notify their TaskQueues via UpdateDelayedWorkQueue. |
| 29 // |
| 30 // The time domain keeps track of the next wakeup required to pump delayed tasks |
| 31 // and issues |RequestWakeup| calls to the subclass as needed. Where possible |
| 32 // it tried to de-dupe these wakeups. Ideally it would be possible to cancel |
| 33 // them, but that's not currently supported by the base message loop. |
| 34 // |
| 35 // The clock itself is provided by subclasses of the TimeDomain and it may be |
| 36 // the real wall clock or a synthetic (virtual) time base. |
| 27 class BLINK_PLATFORM_EXPORT TimeDomain { | 37 class BLINK_PLATFORM_EXPORT TimeDomain { |
| 28 public: | 38 public: |
| 29 class BLINK_PLATFORM_EXPORT Observer { | 39 class BLINK_PLATFORM_EXPORT Observer { |
| 30 public: | 40 public: |
| 31 virtual ~Observer() {} | 41 virtual ~Observer() {} |
| 32 | 42 |
| 33 // Called when an empty TaskQueue registered with this TimeDomain has a task | 43 // Called when an empty TaskQueue registered with this TimeDomain has a task |
| 34 // enqueued. | 44 // enqueued. |
| 35 virtual void OnTimeDomainHasImmediateWork() = 0; | 45 virtual void OnTimeDomainHasImmediateWork() = 0; |
| 36 | 46 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // Adds |queue| to the set of task queues that UpdateWorkQueues calls | 88 // Adds |queue| to the set of task queues that UpdateWorkQueues calls |
| 79 // UpdateWorkQueue on. | 89 // UpdateWorkQueue on. |
| 80 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); | 90 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); |
| 81 | 91 |
| 82 // Schedules a call to TaskQueueImpl::MoveReadyDelayedTasksToDelayedWorkQueue | 92 // Schedules a call to TaskQueueImpl::MoveReadyDelayedTasksToDelayedWorkQueue |
| 83 // when this TimeDomain reaches |delayed_run_time|. | 93 // when this TimeDomain reaches |delayed_run_time|. |
| 84 void ScheduleDelayedWork(internal::TaskQueueImpl* queue, | 94 void ScheduleDelayedWork(internal::TaskQueueImpl* queue, |
| 85 base::TimeTicks delayed_run_time, | 95 base::TimeTicks delayed_run_time, |
| 86 base::TimeTicks now); | 96 base::TimeTicks now); |
| 87 | 97 |
| 98 // Cancels a call to TaskQueueImpl::MoveReadyDelayedTasksToDelayedWorkQueue |
| 99 // previously requested with ScheduleDelayedWork. Note this only works if |
| 100 // delayed_run_time is _not_ the next scheduled run time. |
| 101 void CancelDelayedWork(internal::TaskQueueImpl* queue, |
| 102 base::TimeTicks delayed_run_time); |
| 103 |
| 88 // Registers the |queue|. | 104 // Registers the |queue|. |
| 89 void RegisterQueue(internal::TaskQueueImpl* queue); | 105 void RegisterQueue(internal::TaskQueueImpl* queue); |
| 90 | 106 |
| 91 // Removes |queue| from the set of task queues that UpdateWorkQueues calls | 107 // Removes |queue| from the set of task queues that UpdateWorkQueues calls |
| 92 // UpdateWorkQueue on. Returns true if |queue| was updatable. | 108 // UpdateWorkQueue on. Returns true if |queue| was updatable. |
| 93 bool UnregisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); | 109 bool UnregisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); |
| 94 | 110 |
| 95 // Removes |queue| from all internal data structures. | 111 // Removes |queue| from all internal data structures. |
| 96 void UnregisterQueue(internal::TaskQueueImpl* queue); | 112 void UnregisterQueue(internal::TaskQueueImpl* queue); |
| 97 | 113 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 165 |
| 150 base::ThreadChecker main_thread_checker_; | 166 base::ThreadChecker main_thread_checker_; |
| 151 | 167 |
| 152 DISALLOW_COPY_AND_ASSIGN(TimeDomain); | 168 DISALLOW_COPY_AND_ASSIGN(TimeDomain); |
| 153 }; | 169 }; |
| 154 | 170 |
| 155 } // namespace scheduler | 171 } // namespace scheduler |
| 156 } // namespace blink | 172 } // namespace blink |
| 157 | 173 |
| 158 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ | 174 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ |
| OLD | NEW |