Chromium Code Reviews| 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 #include "platform/scheduler/base/task_queue_impl.h" | 5 #include "platform/scheduler/base/task_queue_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 size_t task_count = 0; | 395 size_t task_count = 0; |
| 396 task_count += main_thread_only().delayed_work_queue->Size(); | 396 task_count += main_thread_only().delayed_work_queue->Size(); |
| 397 task_count += main_thread_only().delayed_incoming_queue.size(); | 397 task_count += main_thread_only().delayed_incoming_queue.size(); |
| 398 task_count += main_thread_only().immediate_work_queue->Size(); | 398 task_count += main_thread_only().immediate_work_queue->Size(); |
| 399 | 399 |
| 400 base::AutoLock lock(immediate_incoming_queue_lock_); | 400 base::AutoLock lock(immediate_incoming_queue_lock_); |
| 401 task_count += immediate_incoming_queue().size(); | 401 task_count += immediate_incoming_queue().size(); |
| 402 return task_count; | 402 return task_count; |
| 403 } | 403 } |
| 404 | 404 |
| 405 bool TaskQueueImpl::HasPendingImmediateWork() const { | 405 bool TaskQueueImpl::HasTaskToRunImmediately() const { |
| 406 // Any work queue tasks count as immediate work. | 406 // Any work queue tasks count as immediate work. |
| 407 if (!main_thread_only().delayed_work_queue->Empty() || | 407 if (!main_thread_only().delayed_work_queue->Empty() || |
| 408 !main_thread_only().immediate_work_queue->Empty()) { | 408 !main_thread_only().immediate_work_queue->Empty()) { |
| 409 return true; | 409 return true; |
| 410 } | 410 } |
| 411 | 411 |
| 412 // Tasks on |delayed_incoming_queue| that could run now, count as | 412 // Tasks on |delayed_incoming_queue| that could run now, count as |
| 413 // immediate work. | 413 // immediate work. |
| 414 if (!main_thread_only().delayed_incoming_queue.empty() && | 414 if (!main_thread_only().delayed_incoming_queue.empty() && |
| 415 main_thread_only().delayed_incoming_queue.top().delayed_run_time <= | 415 main_thread_only().delayed_incoming_queue.top().delayed_run_time <= |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 814 bool is_enabled = IsQueueEnabled(); | 814 bool is_enabled = IsQueueEnabled(); |
| 815 if (was_enabled != is_enabled) | 815 if (was_enabled != is_enabled) |
| 816 EnableOrDisableWithSelector(is_enabled); | 816 EnableOrDisableWithSelector(is_enabled); |
| 817 } | 817 } |
| 818 | 818 |
| 819 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { | 819 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { |
| 820 if (!main_thread_only().task_queue_manager) | 820 if (!main_thread_only().task_queue_manager) |
| 821 return; | 821 return; |
| 822 | 822 |
| 823 if (enable) { | 823 if (enable) { |
| 824 if (HasPendingImmediateWork()) | 824 if (HasPendingImmediateWork() && main_thread_only().observer) { |
|
Sami
2017/05/08 17:33:37
This could also use a comment saying why we need t
altimin
2017/05/09 11:41:42
Done.
| |
| 825 NotifyWakeUpChangedOnMainThread(base::TimeTicks()); | 825 main_thread_only().observer->OnQueueNextWakeUpChanged(this, |
|
Sami
2017/05/08 17:33:37
Could you add a TODO where OnQueueNextWakeUpChange
altimin
2017/05/09 11:41:42
Done.
| |
| 826 base::TimeTicks()); | |
| 827 } | |
| 826 | 828 |
| 827 ScheduleDelayedWorkInTimeDomain(main_thread_only().time_domain->Now()); | 829 ScheduleDelayedWorkInTimeDomain(main_thread_only().time_domain->Now()); |
| 828 | 830 |
| 829 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts | 831 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts |
| 830 // a DoWork if needed. | 832 // a DoWork if needed. |
| 831 main_thread_only().task_queue_manager->selector_.EnableQueue(this); | 833 main_thread_only().task_queue_manager->selector_.EnableQueue(this); |
| 832 } else { | 834 } else { |
| 833 if (!main_thread_only().delayed_incoming_queue.empty()) | 835 if (!main_thread_only().delayed_incoming_queue.empty()) |
| 834 main_thread_only().time_domain->CancelDelayedWork(this); | 836 main_thread_only().time_domain->CancelDelayedWork(this); |
| 835 main_thread_only().task_queue_manager->selector_.DisableQueue(this); | 837 main_thread_only().task_queue_manager->selector_.DisableQueue(this); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 | 894 |
| 893 void TaskQueueImpl::ScheduleDelayedWorkInTimeDomain(base::TimeTicks now) { | 895 void TaskQueueImpl::ScheduleDelayedWorkInTimeDomain(base::TimeTicks now) { |
| 894 if (!IsQueueEnabled()) | 896 if (!IsQueueEnabled()) |
| 895 return; | 897 return; |
| 896 if (main_thread_only().delayed_incoming_queue.empty()) | 898 if (main_thread_only().delayed_incoming_queue.empty()) |
| 897 return; | 899 return; |
| 898 | 900 |
| 899 main_thread_only().time_domain->ScheduleDelayedWork( | 901 main_thread_only().time_domain->ScheduleDelayedWork( |
| 900 this, main_thread_only().delayed_incoming_queue.top().delayed_wake_up(), | 902 this, main_thread_only().delayed_incoming_queue.top().delayed_wake_up(), |
| 901 now); | 903 now); |
| 902 | |
| 903 NotifyWakeUpChangedOnMainThread( | |
| 904 main_thread_only().delayed_incoming_queue.top().delayed_run_time); | |
| 905 } | 904 } |
| 906 | 905 |
| 907 void TaskQueueImpl::NotifyWakeUpChangedOnMainThread(base::TimeTicks wake_up) { | 906 void TaskQueueImpl::SetScheduledTimeDomainWakeUp( |
| 908 if (main_thread_only().observer) | 907 base::Optional<base::TimeTicks> scheduled_time_domain_wake_up) { |
| 909 main_thread_only().observer->OnQueueNextWakeUpChanged(this, wake_up); | 908 main_thread_only().scheduled_time_domain_wake_up = |
| 909 scheduled_time_domain_wake_up; | |
| 910 | |
| 911 if (!scheduled_time_domain_wake_up) | |
| 912 return; | |
| 913 if (!main_thread_only().observer) | |
| 914 return; | |
| 915 if (HasPendingImmediateWork()) | |
|
Sami
2017/05/08 17:33:37
I'm not sure why we need to ignore ready incoming
altimin
2017/05/09 11:41:42
Done.
| |
| 916 return; | |
| 917 | |
| 918 main_thread_only().observer->OnQueueNextWakeUpChanged( | |
| 919 this, scheduled_time_domain_wake_up.value()); | |
| 920 } | |
| 921 | |
| 922 bool TaskQueueImpl::HasPendingImmediateWork() { | |
| 923 // Any work queue tasks count as immediate work. | |
| 924 if (!main_thread_only().delayed_work_queue->Empty() || | |
| 925 !main_thread_only().immediate_work_queue->Empty()) { | |
| 926 return true; | |
| 927 } | |
| 928 | |
| 929 // Finally tasks on |immediate_incoming_queue| count as immediate work. | |
| 930 base::AutoLock lock(immediate_incoming_queue_lock_); | |
| 931 return !immediate_incoming_queue().empty(); | |
| 910 } | 932 } |
| 911 | 933 |
| 912 } // namespace internal | 934 } // namespace internal |
| 913 } // namespace scheduler | 935 } // namespace scheduler |
| 914 } // namespace blink | 936 } // namespace blink |
| OLD | NEW |