| 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 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 bool is_enabled = IsQueueEnabled(); | 806 bool is_enabled = IsQueueEnabled(); |
| 807 if (was_enabled != is_enabled) | 807 if (was_enabled != is_enabled) |
| 808 EnableOrDisableWithSelector(is_enabled); | 808 EnableOrDisableWithSelector(is_enabled); |
| 809 } | 809 } |
| 810 | 810 |
| 811 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { | 811 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { |
| 812 if (!main_thread_only().task_queue_manager) | 812 if (!main_thread_only().task_queue_manager) |
| 813 return; | 813 return; |
| 814 | 814 |
| 815 if (enable) { | 815 if (enable) { |
| 816 if (HasPendingImmediateWork()) | 816 if (HasPendingImmediateWorkWithoutDelayedIncomingQueue() && |
| 817 NotifyWakeUpChangedOnMainThread(base::TimeTicks()); | 817 main_thread_only().observer) { |
| 818 main_thread_only().observer->OnQueueNextWakeUpChanged(this, |
| 819 base::TimeTicks()); |
| 820 } |
| 818 | 821 |
| 819 ScheduleDelayedWorkInTimeDomain(main_thread_only().time_domain->Now()); | 822 ScheduleDelayedWorkInTimeDomain(main_thread_only().time_domain->Now()); |
| 820 | 823 |
| 821 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts | 824 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts |
| 822 // a DoWork if needed. | 825 // a DoWork if needed. |
| 823 main_thread_only().task_queue_manager->selector_.EnableQueue(this); | 826 main_thread_only().task_queue_manager->selector_.EnableQueue(this); |
| 824 } else { | 827 } else { |
| 825 if (!main_thread_only().delayed_incoming_queue.empty()) | 828 if (!main_thread_only().delayed_incoming_queue.empty()) |
| 826 main_thread_only().time_domain->CancelDelayedWork(this); | 829 main_thread_only().time_domain->CancelDelayedWork(this); |
| 827 main_thread_only().task_queue_manager->selector_.DisableQueue(this); | 830 main_thread_only().task_queue_manager->selector_.DisableQueue(this); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 | 887 |
| 885 void TaskQueueImpl::ScheduleDelayedWorkInTimeDomain(base::TimeTicks now) { | 888 void TaskQueueImpl::ScheduleDelayedWorkInTimeDomain(base::TimeTicks now) { |
| 886 if (!IsQueueEnabled()) | 889 if (!IsQueueEnabled()) |
| 887 return; | 890 return; |
| 888 if (main_thread_only().delayed_incoming_queue.empty()) | 891 if (main_thread_only().delayed_incoming_queue.empty()) |
| 889 return; | 892 return; |
| 890 | 893 |
| 891 main_thread_only().time_domain->ScheduleDelayedWork( | 894 main_thread_only().time_domain->ScheduleDelayedWork( |
| 892 this, main_thread_only().delayed_incoming_queue.top().delayed_wake_up(), | 895 this, main_thread_only().delayed_incoming_queue.top().delayed_wake_up(), |
| 893 now); | 896 now); |
| 894 | |
| 895 if (!HasPendingImmediateWork()) { | |
| 896 NotifyWakeUpChangedOnMainThread( | |
| 897 main_thread_only().delayed_incoming_queue.top().delayed_run_time); | |
| 898 } | |
| 899 } | 897 } |
| 900 | 898 |
| 901 void TaskQueueImpl::NotifyWakeUpChangedOnMainThread(base::TimeTicks wake_up) { | 899 void TaskQueueImpl::SetScheduledTimeDomainWakeUp( |
| 902 if (main_thread_only().observer) | 900 base::Optional<base::TimeTicks> scheduled_time_domain_wake_up) { |
| 903 main_thread_only().observer->OnQueueNextWakeUpChanged(this, wake_up); | 901 main_thread_only().scheduled_time_domain_wake_up = |
| 902 scheduled_time_domain_wake_up; |
| 903 |
| 904 if (!scheduled_time_domain_wake_up) |
| 905 return; |
| 906 if (!main_thread_only().observer) |
| 907 return; |
| 908 if (HasPendingImmediateWorkWithoutDelayedIncomingQueue()) |
| 909 return; |
| 910 |
| 911 main_thread_only().observer->OnQueueNextWakeUpChanged( |
| 912 this, scheduled_time_domain_wake_up.value()); |
| 913 } |
| 914 |
| 915 bool TaskQueueImpl::HasPendingImmediateWorkWithoutDelayedIncomingQueue() { |
| 916 // Any work queue tasks count as immediate work. |
| 917 if (!main_thread_only().delayed_work_queue->Empty() || |
| 918 !main_thread_only().immediate_work_queue->Empty()) { |
| 919 return true; |
| 920 } |
| 921 |
| 922 // Finally tasks on |immediate_incoming_queue| count as immediate work. |
| 923 base::AutoLock lock(immediate_incoming_queue_lock_); |
| 924 return !immediate_incoming_queue().empty(); |
| 904 } | 925 } |
| 905 | 926 |
| 906 } // namespace internal | 927 } // namespace internal |
| 907 } // namespace scheduler | 928 } // namespace scheduler |
| 908 } // namespace blink | 929 } // namespace blink |
| OLD | NEW |