| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/child/task_queue_manager.h" | 5 #include "components/scheduler/child/task_queue_manager.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/time/default_tick_clock.h" |
| 11 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 12 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
| 13 #include "components/scheduler/child/nestable_single_thread_task_runner.h" | 14 #include "components/scheduler/child/nestable_single_thread_task_runner.h" |
| 14 #include "components/scheduler/child/task_queue_selector.h" | 15 #include "components/scheduler/child/task_queue_selector.h" |
| 15 #include "components/scheduler/child/time_source.h" | |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 const int64_t kMaxTimeTicks = std::numeric_limits<int64>::max(); | 18 const int64_t kMaxTimeTicks = std::numeric_limits<int64>::max(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace scheduler { | 21 namespace scheduler { |
| 22 namespace internal { | 22 namespace internal { |
| 23 | 23 |
| 24 // Now() is somewhat expensive so it makes sense not to call Now() unless we | 24 // Now() is somewhat expensive so it makes sense not to call Now() unless we |
| 25 // really need to. | 25 // really need to. |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 TaskQueueManager::TaskQueueManager( | 460 TaskQueueManager::TaskQueueManager( |
| 461 size_t task_queue_count, | 461 size_t task_queue_count, |
| 462 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner, | 462 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner, |
| 463 TaskQueueSelector* selector, | 463 TaskQueueSelector* selector, |
| 464 const char* disabled_by_default_tracing_category) | 464 const char* disabled_by_default_tracing_category) |
| 465 : main_task_runner_(main_task_runner), | 465 : main_task_runner_(main_task_runner), |
| 466 selector_(selector), | 466 selector_(selector), |
| 467 task_was_run_bitmap_(0), | 467 task_was_run_bitmap_(0), |
| 468 pending_dowork_count_(0), | 468 pending_dowork_count_(0), |
| 469 work_batch_size_(1), | 469 work_batch_size_(1), |
| 470 time_source_(new TimeSource), | 470 time_source_(new base::DefaultTickClock), |
| 471 disabled_by_default_tracing_category_( | 471 disabled_by_default_tracing_category_( |
| 472 disabled_by_default_tracing_category), | 472 disabled_by_default_tracing_category), |
| 473 deletion_sentinel_(new DeletionSentinel()), | 473 deletion_sentinel_(new DeletionSentinel()), |
| 474 weak_factory_(this) { | 474 weak_factory_(this) { |
| 475 DCHECK(main_task_runner->RunsTasksOnCurrentThread()); | 475 DCHECK(main_task_runner->RunsTasksOnCurrentThread()); |
| 476 DCHECK_LE(task_queue_count, sizeof(task_was_run_bitmap_) * CHAR_BIT) | 476 DCHECK_LE(task_queue_count, sizeof(task_was_run_bitmap_) * CHAR_BIT) |
| 477 << "You need a bigger int for task_was_run_bitmap_"; | 477 << "You need a bigger int for task_was_run_bitmap_"; |
| 478 TRACE_EVENT_OBJECT_CREATED_WITH_ID(disabled_by_default_tracing_category, | 478 TRACE_EVENT_OBJECT_CREATED_WITH_ID(disabled_by_default_tracing_category, |
| 479 "TaskQueueManager", this); | 479 "TaskQueueManager", this); |
| 480 | 480 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 } | 717 } |
| 718 | 718 |
| 719 void TaskQueueManager::RemoveTaskObserver( | 719 void TaskQueueManager::RemoveTaskObserver( |
| 720 base::MessageLoop::TaskObserver* task_observer) { | 720 base::MessageLoop::TaskObserver* task_observer) { |
| 721 DCHECK(main_thread_checker_.CalledOnValidThread()); | 721 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 722 main_task_runner_->RemoveTaskObserver(task_observer); | 722 main_task_runner_->RemoveTaskObserver(task_observer); |
| 723 task_observers_.RemoveObserver(task_observer); | 723 task_observers_.RemoveObserver(task_observer); |
| 724 } | 724 } |
| 725 | 725 |
| 726 void TaskQueueManager::SetTimeSourceForTesting( | 726 void TaskQueueManager::SetTimeSourceForTesting( |
| 727 scoped_ptr<TimeSource> time_source) { | 727 scoped_ptr<base::DefaultTickClock> time_source) { |
| 728 DCHECK(main_thread_checker_.CalledOnValidThread()); | 728 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 729 time_source_ = time_source.Pass(); | 729 time_source_ = time_source.Pass(); |
| 730 } | 730 } |
| 731 | 731 |
| 732 uint64 TaskQueueManager::GetAndClearTaskWasRunOnQueueBitmap() { | 732 uint64 TaskQueueManager::GetAndClearTaskWasRunOnQueueBitmap() { |
| 733 uint64 bitmap = task_was_run_bitmap_; | 733 uint64 bitmap = task_was_run_bitmap_; |
| 734 task_was_run_bitmap_ = 0; | 734 task_was_run_bitmap_ = 0; |
| 735 return bitmap; | 735 return bitmap; |
| 736 } | 736 } |
| 737 | 737 |
| 738 base::TimeTicks TaskQueueManager::Now() const { | 738 base::TimeTicks TaskQueueManager::Now() const { |
| 739 return time_source_->Now(); | 739 return time_source_->NowTicks(); |
| 740 } | 740 } |
| 741 | 741 |
| 742 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 742 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 743 TaskQueueManager::AsValueWithSelectorResult(bool should_run, | 743 TaskQueueManager::AsValueWithSelectorResult(bool should_run, |
| 744 size_t selected_queue) const { | 744 size_t selected_queue) const { |
| 745 DCHECK(main_thread_checker_.CalledOnValidThread()); | 745 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 746 scoped_refptr<base::trace_event::TracedValue> state = | 746 scoped_refptr<base::trace_event::TracedValue> state = |
| 747 new base::trace_event::TracedValue(); | 747 new base::trace_event::TracedValue(); |
| 748 state->BeginArray("queues"); | 748 state->BeginArray("queues"); |
| 749 for (auto& queue : queues_) | 749 for (auto& queue : queues_) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 return nullptr; | 786 return nullptr; |
| 787 } | 787 } |
| 788 } | 788 } |
| 789 | 789 |
| 790 void TaskQueueManager::OnTaskQueueEnabled() { | 790 void TaskQueueManager::OnTaskQueueEnabled() { |
| 791 DCHECK(main_thread_checker_.CalledOnValidThread()); | 791 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 792 MaybePostDoWorkOnMainRunner(); | 792 MaybePostDoWorkOnMainRunner(); |
| 793 } | 793 } |
| 794 | 794 |
| 795 } // namespace scheduler | 795 } // namespace scheduler |
| OLD | NEW |