| 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 "content/child/scheduler/task_queue_manager.h" | 5 #include "content/child/scheduler/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/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "base/trace_event/trace_event_argument.h" | 12 #include "base/trace_event/trace_event_argument.h" |
| 13 #include "cc/test/test_now_source.h" | |
| 14 #include "content/child/scheduler/nestable_single_thread_task_runner.h" | 13 #include "content/child/scheduler/nestable_single_thread_task_runner.h" |
| 15 #include "content/child/scheduler/task_queue_selector.h" | 14 #include "content/child/scheduler/task_queue_selector.h" |
| 15 #include "content/child/scheduler/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 content { | 21 namespace content { |
| 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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 TaskQueueManager::TaskQueueManager( | 454 TaskQueueManager::TaskQueueManager( |
| 455 size_t task_queue_count, | 455 size_t task_queue_count, |
| 456 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner, | 456 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner, |
| 457 TaskQueueSelector* selector, | 457 TaskQueueSelector* selector, |
| 458 const char* disabled_by_default_tracing_category) | 458 const char* disabled_by_default_tracing_category) |
| 459 : main_task_runner_(main_task_runner), | 459 : main_task_runner_(main_task_runner), |
| 460 selector_(selector), | 460 selector_(selector), |
| 461 task_was_run_bitmap_(0), | 461 task_was_run_bitmap_(0), |
| 462 pending_dowork_count_(0), | 462 pending_dowork_count_(0), |
| 463 work_batch_size_(1), | 463 work_batch_size_(1), |
| 464 time_source_(nullptr), | 464 time_source_(new TimeSource), |
| 465 disabled_by_default_tracing_category_( | 465 disabled_by_default_tracing_category_( |
| 466 disabled_by_default_tracing_category), | 466 disabled_by_default_tracing_category), |
| 467 deletion_sentinel_(new DeletionSentinel()), | 467 deletion_sentinel_(new DeletionSentinel()), |
| 468 weak_factory_(this) { | 468 weak_factory_(this) { |
| 469 DCHECK(main_task_runner->RunsTasksOnCurrentThread()); | 469 DCHECK(main_task_runner->RunsTasksOnCurrentThread()); |
| 470 DCHECK_LE(task_queue_count, sizeof(task_was_run_bitmap_) * CHAR_BIT) | 470 DCHECK_LE(task_queue_count, sizeof(task_was_run_bitmap_) * CHAR_BIT) |
| 471 << "You need a bigger int for task_was_run_bitmap_"; | 471 << "You need a bigger int for task_was_run_bitmap_"; |
| 472 TRACE_EVENT_OBJECT_CREATED_WITH_ID(disabled_by_default_tracing_category, | 472 TRACE_EVENT_OBJECT_CREATED_WITH_ID(disabled_by_default_tracing_category, |
| 473 "TaskQueueManager", this); | 473 "TaskQueueManager", this); |
| 474 | 474 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 } | 696 } |
| 697 | 697 |
| 698 void TaskQueueManager::RemoveTaskObserver( | 698 void TaskQueueManager::RemoveTaskObserver( |
| 699 base::MessageLoop::TaskObserver* task_observer) { | 699 base::MessageLoop::TaskObserver* task_observer) { |
| 700 DCHECK(main_thread_checker_.CalledOnValidThread()); | 700 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 701 base::MessageLoop::current()->RemoveTaskObserver(task_observer); | 701 base::MessageLoop::current()->RemoveTaskObserver(task_observer); |
| 702 task_observers_.RemoveObserver(task_observer); | 702 task_observers_.RemoveObserver(task_observer); |
| 703 } | 703 } |
| 704 | 704 |
| 705 void TaskQueueManager::SetTimeSourceForTesting( | 705 void TaskQueueManager::SetTimeSourceForTesting( |
| 706 scoped_refptr<cc::TestNowSource> time_source) { | 706 scoped_ptr<TimeSource> time_source) { |
| 707 DCHECK(main_thread_checker_.CalledOnValidThread()); | 707 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 708 time_source_ = time_source; | 708 time_source_ = time_source.Pass(); |
| 709 } | 709 } |
| 710 | 710 |
| 711 uint64 TaskQueueManager::GetAndClearTaskWasRunOnQueueBitmap() { | 711 uint64 TaskQueueManager::GetAndClearTaskWasRunOnQueueBitmap() { |
| 712 uint64 bitmap = task_was_run_bitmap_; | 712 uint64 bitmap = task_was_run_bitmap_; |
| 713 task_was_run_bitmap_ = 0; | 713 task_was_run_bitmap_ = 0; |
| 714 return bitmap; | 714 return bitmap; |
| 715 } | 715 } |
| 716 | 716 |
| 717 base::TimeTicks TaskQueueManager::Now() const { | 717 base::TimeTicks TaskQueueManager::Now() const { |
| 718 return UNLIKELY(time_source_) ? time_source_->Now() : base::TimeTicks::Now(); | 718 return time_source_->Now(); |
| 719 } | 719 } |
| 720 | 720 |
| 721 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 721 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 722 TaskQueueManager::AsValueWithSelectorResult(bool should_run, | 722 TaskQueueManager::AsValueWithSelectorResult(bool should_run, |
| 723 size_t selected_queue) const { | 723 size_t selected_queue) const { |
| 724 DCHECK(main_thread_checker_.CalledOnValidThread()); | 724 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 725 scoped_refptr<base::trace_event::TracedValue> state = | 725 scoped_refptr<base::trace_event::TracedValue> state = |
| 726 new base::trace_event::TracedValue(); | 726 new base::trace_event::TracedValue(); |
| 727 state->BeginArray("queues"); | 727 state->BeginArray("queues"); |
| 728 for (auto& queue : queues_) | 728 for (auto& queue : queues_) |
| 729 queue->AsValueInto(state.get()); | 729 queue->AsValueInto(state.get()); |
| 730 state->EndArray(); | 730 state->EndArray(); |
| 731 state->BeginDictionary("selector"); | 731 state->BeginDictionary("selector"); |
| 732 selector_->AsValueInto(state.get()); | 732 selector_->AsValueInto(state.get()); |
| 733 state->EndDictionary(); | 733 state->EndDictionary(); |
| 734 if (should_run) | 734 if (should_run) |
| 735 state->SetInteger("selected_queue", selected_queue); | 735 state->SetInteger("selected_queue", selected_queue); |
| 736 return state; | 736 return state; |
| 737 } | 737 } |
| 738 | 738 |
| 739 void TaskQueueManager::OnTaskQueueEnabled() { | 739 void TaskQueueManager::OnTaskQueueEnabled() { |
| 740 DCHECK(main_thread_checker_.CalledOnValidThread()); | 740 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 741 MaybePostDoWorkOnMainRunner(); | 741 MaybePostDoWorkOnMainRunner(); |
| 742 } | 742 } |
| 743 | 743 |
| 744 } // namespace content | 744 } // namespace content |
| OLD | NEW |