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" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 internal::TaskQueueImpl::Task pending_task = queue->TakeTaskFromWorkQueue(); | 276 internal::TaskQueueImpl::Task pending_task = queue->TakeTaskFromWorkQueue(); |
277 | 277 |
278 if (queue->GetQuiescenceMonitored()) | 278 if (queue->GetQuiescenceMonitored()) |
279 task_was_run_on_quiescence_monitored_queue_ = true; | 279 task_was_run_on_quiescence_monitored_queue_ = true; |
280 | 280 |
281 if (!pending_task.nestable && main_task_runner_->IsNested()) { | 281 if (!pending_task.nestable && main_task_runner_->IsNested()) { |
282 // Defer non-nestable work to the main task runner. NOTE these tasks can be | 282 // Defer non-nestable work to the main task runner. NOTE these tasks can be |
283 // arbitrarily delayed so the additional delay should not be a problem. | 283 // arbitrarily delayed so the additional delay should not be a problem. |
284 main_task_runner_->PostNonNestableTask(pending_task.posted_from, | 284 main_task_runner_->PostNonNestableTask(pending_task.posted_from, |
285 pending_task.task); | 285 pending_task.task); |
| 286 // Even although we haven't actually run this task yet, we do set it as |
| 287 // the out_previous_task below because it might be our only chance to |
| 288 // wake up an after-wakeup queue. |
286 } else { | 289 } else { |
287 TRACE_TASK_EXECUTION("TaskQueueManager::ProcessTaskFromWorkQueue", | 290 TRACE_TASK_EXECUTION("TaskQueueManager::ProcessTaskFromWorkQueue", |
288 pending_task); | 291 pending_task); |
289 if (queue->GetShouldNotifyObservers()) { | 292 if (queue->GetShouldNotifyObservers()) { |
290 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, | 293 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, |
291 WillProcessTask(pending_task)); | 294 WillProcessTask(pending_task)); |
292 } | 295 } |
293 task_annotator_.RunTask("TaskQueueManager::PostTask", pending_task); | 296 task_annotator_.RunTask("TaskQueueManager::PostTask", pending_task); |
294 | 297 |
295 // Detect if the TaskQueueManager just got deleted. If this happens we must | 298 // Detect if the TaskQueueManager just got deleted. If this happens we must |
296 // not access any member variables after this point. | 299 // not access any member variables after this point. |
297 if (protect->HasOneRef()) | 300 if (protect->HasOneRef()) |
298 return true; | 301 return true; |
299 | 302 |
300 if (queue->GetShouldNotifyObservers()) { | 303 if (queue->GetShouldNotifyObservers()) { |
301 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, | 304 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, |
302 DidProcessTask(pending_task)); | 305 DidProcessTask(pending_task)); |
303 } | 306 } |
| 307 } |
304 | 308 |
305 pending_task.task.Reset(); | 309 pending_task.task.Reset(); |
306 *out_previous_task = pending_task; | 310 *out_previous_task = pending_task; |
307 } | |
308 return false; | 311 return false; |
309 } | 312 } |
310 | 313 |
311 bool TaskQueueManager::RunsTasksOnCurrentThread() const { | 314 bool TaskQueueManager::RunsTasksOnCurrentThread() const { |
312 return main_task_runner_->RunsTasksOnCurrentThread(); | 315 return main_task_runner_->RunsTasksOnCurrentThread(); |
313 } | 316 } |
314 | 317 |
315 bool TaskQueueManager::PostDelayedTask( | 318 bool TaskQueueManager::PostDelayedTask( |
316 const tracked_objects::Location& from_here, | 319 const tracked_objects::Location& from_here, |
317 const base::Closure& task, | 320 const base::Closure& task, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 } | 386 } |
384 | 387 |
385 void TaskQueueManager::OnTaskQueueEnabled(internal::TaskQueueImpl* queue) { | 388 void TaskQueueManager::OnTaskQueueEnabled(internal::TaskQueueImpl* queue) { |
386 DCHECK(main_thread_checker_.CalledOnValidThread()); | 389 DCHECK(main_thread_checker_.CalledOnValidThread()); |
387 // Only schedule DoWork if there's something to do. | 390 // Only schedule DoWork if there's something to do. |
388 if (!queue->work_queue().empty()) | 391 if (!queue->work_queue().empty()) |
389 MaybePostDoWorkOnMainRunner(); | 392 MaybePostDoWorkOnMainRunner(); |
390 } | 393 } |
391 | 394 |
392 } // namespace scheduler | 395 } // namespace scheduler |
OLD | NEW |