| 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 "components/scheduler/base/task_queue_impl.h" | 5 #include "components/scheduler/base/task_queue_impl.h" |
| 6 | 6 |
| 7 #include "base/debug/blame_context.h" |
| 7 #include "components/scheduler/base/task_queue_manager.h" | 8 #include "components/scheduler/base/task_queue_manager.h" |
| 8 #include "components/scheduler/base/task_queue_manager_delegate.h" | 9 #include "components/scheduler/base/task_queue_manager_delegate.h" |
| 9 #include "components/scheduler/base/time_domain.h" | 10 #include "components/scheduler/base/time_domain.h" |
| 10 #include "components/scheduler/base/work_queue.h" | 11 #include "components/scheduler/base/work_queue.h" |
| 11 | 12 |
| 12 namespace scheduler { | 13 namespace scheduler { |
| 13 namespace internal { | 14 namespace internal { |
| 14 | 15 |
| 15 TaskQueueImpl::TaskQueueImpl( | 16 TaskQueueImpl::TaskQueueImpl( |
| 16 TaskQueueManager* task_queue_manager, | 17 TaskQueueManager* task_queue_manager, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 TaskQueueManager* task_queue_manager, | 103 TaskQueueManager* task_queue_manager, |
| 103 PumpPolicy pump_policy, | 104 PumpPolicy pump_policy, |
| 104 TaskQueueImpl* task_queue, | 105 TaskQueueImpl* task_queue, |
| 105 TimeDomain* time_domain) | 106 TimeDomain* time_domain) |
| 106 : task_queue_manager(task_queue_manager), | 107 : task_queue_manager(task_queue_manager), |
| 107 pump_policy(pump_policy), | 108 pump_policy(pump_policy), |
| 108 time_domain(time_domain), | 109 time_domain(time_domain), |
| 109 delayed_work_queue(new WorkQueue(task_queue, "delayed")), | 110 delayed_work_queue(new WorkQueue(task_queue, "delayed")), |
| 110 immediate_work_queue(new WorkQueue(task_queue, "immediate")), | 111 immediate_work_queue(new WorkQueue(task_queue, "immediate")), |
| 111 set_index(0), | 112 set_index(0), |
| 112 is_enabled(true) {} | 113 is_enabled(true), |
| 114 blame_context(nullptr) {} |
| 113 | 115 |
| 114 TaskQueueImpl::MainThreadOnly::~MainThreadOnly() {} | 116 TaskQueueImpl::MainThreadOnly::~MainThreadOnly() {} |
| 115 | 117 |
| 116 void TaskQueueImpl::UnregisterTaskQueue() { | 118 void TaskQueueImpl::UnregisterTaskQueue() { |
| 117 base::AutoLock lock(any_thread_lock_); | 119 base::AutoLock lock(any_thread_lock_); |
| 118 if (main_thread_only().time_domain) | 120 if (main_thread_only().time_domain) |
| 119 main_thread_only().time_domain->UnregisterQueue(this); | 121 main_thread_only().time_domain->UnregisterQueue(this); |
| 120 if (!any_thread().task_queue_manager) | 122 if (!any_thread().task_queue_manager) |
| 121 return; | 123 return; |
| 122 any_thread().time_domain = nullptr; | 124 any_thread().time_domain = nullptr; |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 } | 599 } |
| 598 | 600 |
| 599 void TaskQueueImpl::RemoveTaskObserver( | 601 void TaskQueueImpl::RemoveTaskObserver( |
| 600 base::MessageLoop::TaskObserver* task_observer) { | 602 base::MessageLoop::TaskObserver* task_observer) { |
| 601 main_thread_only().task_observers.RemoveObserver(task_observer); | 603 main_thread_only().task_observers.RemoveObserver(task_observer); |
| 602 } | 604 } |
| 603 | 605 |
| 604 void TaskQueueImpl::NotifyWillProcessTask( | 606 void TaskQueueImpl::NotifyWillProcessTask( |
| 605 const base::PendingTask& pending_task) { | 607 const base::PendingTask& pending_task) { |
| 606 DCHECK(should_notify_observers_); | 608 DCHECK(should_notify_observers_); |
| 609 if (main_thread_only().blame_context) |
| 610 main_thread_only().blame_context->Enter(); |
| 607 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, | 611 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, |
| 608 main_thread_only().task_observers, | 612 main_thread_only().task_observers, |
| 609 WillProcessTask(pending_task)); | 613 WillProcessTask(pending_task)); |
| 610 } | 614 } |
| 611 | 615 |
| 612 void TaskQueueImpl::NotifyDidProcessTask( | 616 void TaskQueueImpl::NotifyDidProcessTask( |
| 613 const base::PendingTask& pending_task) { | 617 const base::PendingTask& pending_task) { |
| 614 DCHECK(should_notify_observers_); | 618 DCHECK(should_notify_observers_); |
| 615 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, | 619 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, |
| 616 main_thread_only().task_observers, | 620 main_thread_only().task_observers, |
| 617 DidProcessTask(pending_task)); | 621 DidProcessTask(pending_task)); |
| 622 if (main_thread_only().blame_context) |
| 623 main_thread_only().blame_context->Leave(); |
| 618 } | 624 } |
| 619 | 625 |
| 620 void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) { | 626 void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) { |
| 621 base::AutoLock lock(any_thread_lock_); | 627 base::AutoLock lock(any_thread_lock_); |
| 622 DCHECK(time_domain); | 628 DCHECK(time_domain); |
| 623 // NOTE this is similar to checking |any_thread().task_queue_manager| but the | 629 // NOTE this is similar to checking |any_thread().task_queue_manager| but the |
| 624 // TaskQueueSelectorTests constructs TaskQueueImpl directly with a null | 630 // TaskQueueSelectorTests constructs TaskQueueImpl directly with a null |
| 625 // task_queue_manager. Instead we check |any_thread().time_domain| which is | 631 // task_queue_manager. Instead we check |any_thread().time_domain| which is |
| 626 // another way of asserting that UnregisterTaskQueue has not been called. | 632 // another way of asserting that UnregisterTaskQueue has not been called. |
| 627 DCHECK(any_thread().time_domain); | 633 DCHECK(any_thread().time_domain); |
| 628 if (!any_thread().time_domain) | 634 if (!any_thread().time_domain) |
| 629 return; | 635 return; |
| 630 DCHECK(main_thread_checker_.CalledOnValidThread()); | 636 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 631 if (time_domain == main_thread_only().time_domain) | 637 if (time_domain == main_thread_only().time_domain) |
| 632 return; | 638 return; |
| 633 | 639 |
| 634 main_thread_only().time_domain->MigrateQueue(this, time_domain); | 640 main_thread_only().time_domain->MigrateQueue(this, time_domain); |
| 635 main_thread_only().time_domain = time_domain; | 641 main_thread_only().time_domain = time_domain; |
| 636 any_thread().time_domain = time_domain; | 642 any_thread().time_domain = time_domain; |
| 637 } | 643 } |
| 638 | 644 |
| 639 TimeDomain* TaskQueueImpl::GetTimeDomain() const { | 645 TimeDomain* TaskQueueImpl::GetTimeDomain() const { |
| 640 if (base::PlatformThread::CurrentId() == thread_id_) | 646 if (base::PlatformThread::CurrentId() == thread_id_) |
| 641 return main_thread_only().time_domain; | 647 return main_thread_only().time_domain; |
| 642 | 648 |
| 643 base::AutoLock lock(any_thread_lock_); | 649 base::AutoLock lock(any_thread_lock_); |
| 644 return any_thread().time_domain; | 650 return any_thread().time_domain; |
| 645 } | 651 } |
| 646 | 652 |
| 653 void TaskQueueImpl::SetBlameContext( |
| 654 base::debug::BlameContextBase* blame_context) { |
| 655 main_thread_only().blame_context = blame_context; |
| 656 } |
| 657 |
| 647 // static | 658 // static |
| 648 void TaskQueueImpl::QueueAsValueInto(const std::queue<Task>& queue, | 659 void TaskQueueImpl::QueueAsValueInto(const std::queue<Task>& queue, |
| 649 base::trace_event::TracedValue* state) { | 660 base::trace_event::TracedValue* state) { |
| 650 std::queue<Task> queue_copy(queue); | 661 std::queue<Task> queue_copy(queue); |
| 651 while (!queue_copy.empty()) { | 662 while (!queue_copy.empty()) { |
| 652 TaskAsValueInto(queue_copy.front(), state); | 663 TaskAsValueInto(queue_copy.front(), state); |
| 653 queue_copy.pop(); | 664 queue_copy.pop(); |
| 654 } | 665 } |
| 655 } | 666 } |
| 656 | 667 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 679 state->SetBoolean("nestable", task.nestable); | 690 state->SetBoolean("nestable", task.nestable); |
| 680 state->SetBoolean("is_high_res", task.is_high_res); | 691 state->SetBoolean("is_high_res", task.is_high_res); |
| 681 state->SetDouble( | 692 state->SetDouble( |
| 682 "delayed_run_time", | 693 "delayed_run_time", |
| 683 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); | 694 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); |
| 684 state->EndDictionary(); | 695 state->EndDictionary(); |
| 685 } | 696 } |
| 686 | 697 |
| 687 } // namespace internal | 698 } // namespace internal |
| 688 } // namespace scheduler | 699 } // namespace scheduler |
| OLD | NEW |