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/trace_event/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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 606 } |
605 | 607 |
606 void TaskQueueImpl::RemoveTaskObserver( | 608 void TaskQueueImpl::RemoveTaskObserver( |
607 base::MessageLoop::TaskObserver* task_observer) { | 609 base::MessageLoop::TaskObserver* task_observer) { |
608 main_thread_only().task_observers.RemoveObserver(task_observer); | 610 main_thread_only().task_observers.RemoveObserver(task_observer); |
609 } | 611 } |
610 | 612 |
611 void TaskQueueImpl::NotifyWillProcessTask( | 613 void TaskQueueImpl::NotifyWillProcessTask( |
612 const base::PendingTask& pending_task) { | 614 const base::PendingTask& pending_task) { |
613 DCHECK(should_notify_observers_); | 615 DCHECK(should_notify_observers_); |
| 616 if (main_thread_only().blame_context) |
| 617 main_thread_only().blame_context->Enter(); |
614 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, | 618 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, |
615 main_thread_only().task_observers, | 619 main_thread_only().task_observers, |
616 WillProcessTask(pending_task)); | 620 WillProcessTask(pending_task)); |
617 } | 621 } |
618 | 622 |
619 void TaskQueueImpl::NotifyDidProcessTask( | 623 void TaskQueueImpl::NotifyDidProcessTask( |
620 const base::PendingTask& pending_task) { | 624 const base::PendingTask& pending_task) { |
621 DCHECK(should_notify_observers_); | 625 DCHECK(should_notify_observers_); |
622 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, | 626 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, |
623 main_thread_only().task_observers, | 627 main_thread_only().task_observers, |
624 DidProcessTask(pending_task)); | 628 DidProcessTask(pending_task)); |
| 629 if (main_thread_only().blame_context) |
| 630 main_thread_only().blame_context->Leave(); |
625 } | 631 } |
626 | 632 |
627 void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) { | 633 void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) { |
628 base::AutoLock lock(any_thread_lock_); | 634 base::AutoLock lock(any_thread_lock_); |
629 DCHECK(time_domain); | 635 DCHECK(time_domain); |
630 // NOTE this is similar to checking |any_thread().task_queue_manager| but the | 636 // NOTE this is similar to checking |any_thread().task_queue_manager| but the |
631 // TaskQueueSelectorTests constructs TaskQueueImpl directly with a null | 637 // TaskQueueSelectorTests constructs TaskQueueImpl directly with a null |
632 // task_queue_manager. Instead we check |any_thread().time_domain| which is | 638 // task_queue_manager. Instead we check |any_thread().time_domain| which is |
633 // another way of asserting that UnregisterTaskQueue has not been called. | 639 // another way of asserting that UnregisterTaskQueue has not been called. |
634 DCHECK(any_thread().time_domain); | 640 DCHECK(any_thread().time_domain); |
635 if (!any_thread().time_domain) | 641 if (!any_thread().time_domain) |
636 return; | 642 return; |
637 DCHECK(main_thread_checker_.CalledOnValidThread()); | 643 DCHECK(main_thread_checker_.CalledOnValidThread()); |
638 if (time_domain == main_thread_only().time_domain) | 644 if (time_domain == main_thread_only().time_domain) |
639 return; | 645 return; |
640 | 646 |
641 main_thread_only().time_domain->MigrateQueue(this, time_domain); | 647 main_thread_only().time_domain->MigrateQueue(this, time_domain); |
642 main_thread_only().time_domain = time_domain; | 648 main_thread_only().time_domain = time_domain; |
643 any_thread().time_domain = time_domain; | 649 any_thread().time_domain = time_domain; |
644 } | 650 } |
645 | 651 |
646 TimeDomain* TaskQueueImpl::GetTimeDomain() const { | 652 TimeDomain* TaskQueueImpl::GetTimeDomain() const { |
647 if (base::PlatformThread::CurrentId() == thread_id_) | 653 if (base::PlatformThread::CurrentId() == thread_id_) |
648 return main_thread_only().time_domain; | 654 return main_thread_only().time_domain; |
649 | 655 |
650 base::AutoLock lock(any_thread_lock_); | 656 base::AutoLock lock(any_thread_lock_); |
651 return any_thread().time_domain; | 657 return any_thread().time_domain; |
652 } | 658 } |
653 | 659 |
| 660 void TaskQueueImpl::SetBlameContext( |
| 661 base::trace_event::BlameContext* blame_context) { |
| 662 main_thread_only().blame_context = blame_context; |
| 663 } |
| 664 |
654 // static | 665 // static |
655 void TaskQueueImpl::QueueAsValueInto(const std::queue<Task>& queue, | 666 void TaskQueueImpl::QueueAsValueInto(const std::queue<Task>& queue, |
656 base::trace_event::TracedValue* state) { | 667 base::trace_event::TracedValue* state) { |
657 std::queue<Task> queue_copy(queue); | 668 std::queue<Task> queue_copy(queue); |
658 while (!queue_copy.empty()) { | 669 while (!queue_copy.empty()) { |
659 TaskAsValueInto(queue_copy.front(), state); | 670 TaskAsValueInto(queue_copy.front(), state); |
660 queue_copy.pop(); | 671 queue_copy.pop(); |
661 } | 672 } |
662 } | 673 } |
663 | 674 |
(...skipping 22 matching lines...) Expand all Loading... |
686 state->SetBoolean("nestable", task.nestable); | 697 state->SetBoolean("nestable", task.nestable); |
687 state->SetBoolean("is_high_res", task.is_high_res); | 698 state->SetBoolean("is_high_res", task.is_high_res); |
688 state->SetDouble( | 699 state->SetDouble( |
689 "delayed_run_time", | 700 "delayed_run_time", |
690 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); | 701 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); |
691 state->EndDictionary(); | 702 state->EndDictionary(); |
692 } | 703 } |
693 | 704 |
694 } // namespace internal | 705 } // namespace internal |
695 } // namespace scheduler | 706 } // namespace scheduler |
OLD | NEW |