| 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/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "base/trace_event/trace_event_argument.h" | 11 #include "base/trace_event/trace_event_argument.h" |
| 12 #include "cc/test/test_now_source.h" | 12 #include "cc/test/test_now_source.h" |
| 13 #include "content/renderer/scheduler/nestable_single_thread_task_runner.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 { |
| 20 namespace internal { | 21 namespace internal { |
| 21 | 22 |
| 22 class TaskQueue : public base::SingleThreadTaskRunner { | 23 class TaskQueue : public base::SingleThreadTaskRunner { |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 state->SetDouble( | 335 state->SetDouble( |
| 335 "delayed_run_time", | 336 "delayed_run_time", |
| 336 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); | 337 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); |
| 337 state->EndDictionary(); | 338 state->EndDictionary(); |
| 338 } | 339 } |
| 339 | 340 |
| 340 } // namespace internal | 341 } // namespace internal |
| 341 | 342 |
| 342 TaskQueueManager::TaskQueueManager( | 343 TaskQueueManager::TaskQueueManager( |
| 343 size_t task_queue_count, | 344 size_t task_queue_count, |
| 344 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 345 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner, |
| 345 TaskQueueSelector* selector) | 346 TaskQueueSelector* selector) |
| 346 : main_task_runner_(main_task_runner), | 347 : main_task_runner_(main_task_runner), |
| 347 selector_(selector), | 348 selector_(selector), |
| 348 pending_dowork_count_(0), | 349 pending_dowork_count_(0), |
| 349 work_batch_size_(1), | 350 work_batch_size_(1), |
| 350 time_source_(nullptr), | 351 time_source_(nullptr), |
| 351 weak_factory_(this) { | 352 weak_factory_(this) { |
| 352 DCHECK(main_task_runner->RunsTasksOnCurrentThread()); | 353 DCHECK(main_task_runner->RunsTasksOnCurrentThread()); |
| 353 TRACE_EVENT_OBJECT_CREATED_WITH_ID( | 354 TRACE_EVENT_OBJECT_CREATED_WITH_ID( |
| 354 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "TaskQueueManager", | 355 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "TaskQueueManager", |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 task_annotator_.DidQueueTask("TaskQueueManager::PostTask", *pending_task); | 489 task_annotator_.DidQueueTask("TaskQueueManager::PostTask", *pending_task); |
| 489 } | 490 } |
| 490 | 491 |
| 491 void TaskQueueManager::ProcessTaskFromWorkQueue( | 492 void TaskQueueManager::ProcessTaskFromWorkQueue( |
| 492 size_t queue_index, | 493 size_t queue_index, |
| 493 bool has_previous_task, | 494 bool has_previous_task, |
| 494 base::PendingTask* previous_task) { | 495 base::PendingTask* previous_task) { |
| 495 DCHECK(main_thread_checker_.CalledOnValidThread()); | 496 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 496 internal::TaskQueue* queue = Queue(queue_index); | 497 internal::TaskQueue* queue = Queue(queue_index); |
| 497 base::PendingTask pending_task = queue->TakeTaskFromWorkQueue(); | 498 base::PendingTask pending_task = queue->TakeTaskFromWorkQueue(); |
| 498 if (!pending_task.nestable) { | 499 if (!pending_task.nestable && main_task_runner_->IsNested()) { |
| 499 // Defer non-nestable work to the main task runner. NOTE these tasks can be | 500 // Defer non-nestable work to the main task runner. NOTE these tasks can be |
| 500 // arbitrarily delayed so the additional delay should not be a problem. | 501 // arbitrarily delayed so the additional delay should not be a problem. |
| 501 main_task_runner_->PostNonNestableTask(pending_task.posted_from, | 502 main_task_runner_->PostNonNestableTask(pending_task.posted_from, |
| 502 pending_task.task); | 503 pending_task.task); |
| 503 } else { | 504 } else { |
| 504 // Suppress "will" task observer notifications for the first and "did" | 505 // Suppress "will" task observer notifications for the first and "did" |
| 505 // notifications for the last task in the batch to avoid duplicate | 506 // notifications for the last task in the batch to avoid duplicate |
| 506 // notifications. | 507 // notifications. |
| 507 if (has_previous_task) { | 508 if (has_previous_task) { |
| 508 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, | 509 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 state->EndArray(); | 578 state->EndArray(); |
| 578 state->BeginDictionary("selector"); | 579 state->BeginDictionary("selector"); |
| 579 selector_->AsValueInto(state.get()); | 580 selector_->AsValueInto(state.get()); |
| 580 state->EndDictionary(); | 581 state->EndDictionary(); |
| 581 if (should_run) | 582 if (should_run) |
| 582 state->SetInteger("selected_queue", selected_queue); | 583 state->SetInteger("selected_queue", selected_queue); |
| 583 return state; | 584 return state; |
| 584 } | 585 } |
| 585 | 586 |
| 586 } // namespace content | 587 } // namespace content |
| OLD | NEW |