Chromium Code Reviews| 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/renderer/scheduler/task_queue_manager.h" | 5 #include "content/renderer/scheduler/task_queue_manager.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/observer_list.h" | |
| 10 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 11 #include "base/trace_event/trace_event_argument.h" | 12 #include "base/trace_event/trace_event_argument.h" |
| 12 #include "cc/test/test_now_source.h" | 13 #include "cc/test/test_now_source.h" |
| 13 #include "content/renderer/scheduler/task_queue_selector.h" | 14 #include "content/renderer/scheduler/task_queue_selector.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 const int64_t kMaxTimeTicks = std::numeric_limits<int64>::max(); | 17 const int64_t kMaxTimeTicks = std::numeric_limits<int64>::max(); |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 void TaskQueueManager::ProcessTaskFromWorkQueue(size_t queue_index) { | 407 void TaskQueueManager::ProcessTaskFromWorkQueue(size_t queue_index) { |
| 407 DCHECK(main_thread_checker_.CalledOnValidThread()); | 408 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 408 internal::TaskQueue* queue = Queue(queue_index); | 409 internal::TaskQueue* queue = Queue(queue_index); |
| 409 base::PendingTask pending_task = queue->TakeTaskFromWorkQueue(); | 410 base::PendingTask pending_task = queue->TakeTaskFromWorkQueue(); |
| 410 if (!pending_task.nestable) { | 411 if (!pending_task.nestable) { |
| 411 // Defer non-nestable work to the main task runner. NOTE these tasks can be | 412 // Defer non-nestable work to the main task runner. NOTE these tasks can be |
| 412 // arbitrarily delayed so the additional delay should not be a problem. | 413 // arbitrarily delayed so the additional delay should not be a problem. |
| 413 main_task_runner_->PostNonNestableTask(pending_task.posted_from, | 414 main_task_runner_->PostNonNestableTask(pending_task.posted_from, |
| 414 pending_task.task); | 415 pending_task.task); |
| 415 } else { | 416 } else { |
| 417 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, | |
|
alex clarke (OOO till 29th)
2015/02/13 11:02:07
Aren't we risking a scenario like this:
base::Mes
Sami
2015/02/13 12:09:09
We talked about this offline. It should be fine be
| |
| 418 WillProcessTask(pending_task)); | |
| 416 task_annotator_.RunTask("TaskQueueManager::PostTask", | 419 task_annotator_.RunTask("TaskQueueManager::PostTask", |
| 417 "TaskQueueManager::RunTask", pending_task); | 420 "TaskQueueManager::RunTask", pending_task); |
| 421 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, | |
| 422 DidProcessTask(pending_task)); | |
| 418 } | 423 } |
| 419 } | 424 } |
| 420 | 425 |
| 421 bool TaskQueueManager::RunsTasksOnCurrentThread() const { | 426 bool TaskQueueManager::RunsTasksOnCurrentThread() const { |
| 422 return main_task_runner_->RunsTasksOnCurrentThread(); | 427 return main_task_runner_->RunsTasksOnCurrentThread(); |
| 423 } | 428 } |
| 424 | 429 |
| 425 bool TaskQueueManager::PostDelayedTask( | 430 bool TaskQueueManager::PostDelayedTask( |
| 426 const tracked_objects::Location& from_here, | 431 const tracked_objects::Location& from_here, |
| 427 const base::Closure& task, | 432 const base::Closure& task, |
| 428 base::TimeDelta delay) { | 433 base::TimeDelta delay) { |
| 429 DCHECK(delay > base::TimeDelta()); | 434 DCHECK(delay > base::TimeDelta()); |
| 430 return main_task_runner_->PostDelayedTask(from_here, task, delay); | 435 return main_task_runner_->PostDelayedTask(from_here, task, delay); |
| 431 } | 436 } |
| 432 | 437 |
| 433 void TaskQueueManager::SetQueueName(size_t queue_index, const char* name) { | 438 void TaskQueueManager::SetQueueName(size_t queue_index, const char* name) { |
| 434 DCHECK(main_thread_checker_.CalledOnValidThread()); | 439 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 435 internal::TaskQueue* queue = Queue(queue_index); | 440 internal::TaskQueue* queue = Queue(queue_index); |
| 436 queue->set_name(name); | 441 queue->set_name(name); |
| 437 } | 442 } |
| 438 | 443 |
| 439 void TaskQueueManager::SetWorkBatchSize(int work_batch_size) { | 444 void TaskQueueManager::SetWorkBatchSize(int work_batch_size) { |
| 440 DCHECK(main_thread_checker_.CalledOnValidThread()); | 445 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 441 DCHECK_GE(work_batch_size, 1); | 446 DCHECK_GE(work_batch_size, 1); |
| 442 work_batch_size_ = work_batch_size; | 447 work_batch_size_ = work_batch_size; |
| 443 } | 448 } |
| 444 | 449 |
| 450 void TaskQueueManager::AddTaskObserver( | |
| 451 base::MessageLoop::TaskObserver* task_observer) { | |
| 452 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
| 453 task_observers_.AddObserver(task_observer); | |
| 454 } | |
| 455 | |
| 456 void TaskQueueManager::RemoveTaskObserver( | |
| 457 base::MessageLoop::TaskObserver* task_observer) { | |
| 458 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
| 459 task_observers_.RemoveObserver(task_observer); | |
| 460 } | |
| 461 | |
| 445 void TaskQueueManager::SetTimeSourceForTesting( | 462 void TaskQueueManager::SetTimeSourceForTesting( |
| 446 scoped_refptr<cc::TestNowSource> time_source) { | 463 scoped_refptr<cc::TestNowSource> time_source) { |
| 447 DCHECK(main_thread_checker_.CalledOnValidThread()); | 464 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 448 time_source_ = time_source; | 465 time_source_ = time_source; |
| 449 } | 466 } |
| 450 | 467 |
| 451 base::TimeTicks TaskQueueManager::Now() const { | 468 base::TimeTicks TaskQueueManager::Now() const { |
| 452 return UNLIKELY(time_source_) ? time_source_->Now() : base::TimeTicks::Now(); | 469 return UNLIKELY(time_source_) ? time_source_->Now() : base::TimeTicks::Now(); |
| 453 } | 470 } |
| 454 | 471 |
| 455 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 472 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 456 TaskQueueManager::AsValueWithSelectorResult(bool should_run, | 473 TaskQueueManager::AsValueWithSelectorResult(bool should_run, |
| 457 size_t selected_queue) const { | 474 size_t selected_queue) const { |
| 458 DCHECK(main_thread_checker_.CalledOnValidThread()); | 475 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 459 scoped_refptr<base::trace_event::TracedValue> state = | 476 scoped_refptr<base::trace_event::TracedValue> state = |
| 460 new base::trace_event::TracedValue(); | 477 new base::trace_event::TracedValue(); |
| 461 state->BeginArray("queues"); | 478 state->BeginArray("queues"); |
| 462 for (auto& queue : queues_) | 479 for (auto& queue : queues_) |
| 463 queue->AsValueInto(state.get()); | 480 queue->AsValueInto(state.get()); |
| 464 state->EndArray(); | 481 state->EndArray(); |
| 465 state->BeginDictionary("selector"); | 482 state->BeginDictionary("selector"); |
| 466 selector_->AsValueInto(state.get()); | 483 selector_->AsValueInto(state.get()); |
| 467 state->EndDictionary(); | 484 state->EndDictionary(); |
| 468 if (should_run) | 485 if (should_run) |
| 469 state->SetInteger("selected_queue", selected_queue); | 486 state->SetInteger("selected_queue", selected_queue); |
| 470 return state; | 487 return state; |
| 471 } | 488 } |
| 472 | 489 |
| 473 } // namespace content | 490 } // namespace content |
| OLD | NEW |