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