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

Unified Diff: third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc

Issue 2808843003: [scheduler] Change TaskQueue observer call mechanism. (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc
diff --git a/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc b/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc
index 5f11a7462b94ca16ca6c0da8a839e1e189d0a56a..517cdc59499a6c8b02ff92f52d1596680f64467e 100644
--- a/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc
+++ b/third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc
@@ -813,8 +813,11 @@ void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) {
return;
if (enable) {
- if (HasPendingImmediateWork())
- NotifyWakeUpChangedOnMainThread(base::TimeTicks());
+ if (HasPendingImmediateWorkWithoutDelayedIncomingQueue() &&
+ main_thread_only().observer) {
+ main_thread_only().observer->OnQueueNextWakeUpChanged(this,
+ base::TimeTicks());
+ }
ScheduleDelayedWorkInTimeDomain(main_thread_only().time_domain->Now());
@@ -891,16 +894,34 @@ void TaskQueueImpl::ScheduleDelayedWorkInTimeDomain(base::TimeTicks now) {
main_thread_only().time_domain->ScheduleDelayedWork(
this, main_thread_only().delayed_incoming_queue.top().delayed_wake_up(),
now);
+}
- if (!HasPendingImmediateWork()) {
- NotifyWakeUpChangedOnMainThread(
- main_thread_only().delayed_incoming_queue.top().delayed_run_time);
- }
+void TaskQueueImpl::SetScheduledTimeDomainWakeUp(
+ base::Optional<base::TimeTicks> scheduled_time_domain_wake_up) {
+ main_thread_only().scheduled_time_domain_wake_up =
+ scheduled_time_domain_wake_up;
+
+ if (!scheduled_time_domain_wake_up)
+ return;
+ if (!main_thread_only().observer)
+ return;
+ if (HasPendingImmediateWorkWithoutDelayedIncomingQueue())
+ return;
+
+ main_thread_only().observer->OnQueueNextWakeUpChanged(
+ this, scheduled_time_domain_wake_up.value());
}
-void TaskQueueImpl::NotifyWakeUpChangedOnMainThread(base::TimeTicks wake_up) {
- if (main_thread_only().observer)
- main_thread_only().observer->OnQueueNextWakeUpChanged(this, wake_up);
+bool TaskQueueImpl::HasPendingImmediateWorkWithoutDelayedIncomingQueue() {
+ // Any work queue tasks count as immediate work.
+ if (!main_thread_only().delayed_work_queue->Empty() ||
+ !main_thread_only().immediate_work_queue->Empty()) {
+ return true;
+ }
+
+ // Finally tasks on |immediate_incoming_queue| count as immediate work.
+ base::AutoLock lock(immediate_incoming_queue_lock_);
+ return !immediate_incoming_queue().empty();
}
} // namespace internal

Powered by Google App Engine
This is Rietveld 408576698