| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 DeletePendingTasks(); | 117 DeletePendingTasks(); |
| 118 ReloadWorkQueue(); | 118 ReloadWorkQueue(); |
| 119 // If we end up with empty queues, then break out of the loop. | 119 // If we end up with empty queues, then break out of the loop. |
| 120 did_work = DeletePendingTasks(); | 120 did_work = DeletePendingTasks(); |
| 121 if (!did_work) | 121 if (!did_work) |
| 122 break; | 122 break; |
| 123 } | 123 } |
| 124 DCHECK(!did_work); | 124 DCHECK(!did_work); |
| 125 | 125 |
| 126 // Let interested parties have one last shot at accessing this. | 126 // Let interested parties have one last shot at accessing this. |
| 127 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, | 127 for (auto& observer : destruction_observers_) |
| 128 WillDestroyCurrentMessageLoop()); | 128 observer.WillDestroyCurrentMessageLoop(); |
| 129 | 129 |
| 130 thread_task_runner_handle_.reset(); | 130 thread_task_runner_handle_.reset(); |
| 131 | 131 |
| 132 // Tell the incoming queue that we are dying. | 132 // Tell the incoming queue that we are dying. |
| 133 incoming_task_queue_->WillDestroyCurrentMessageLoop(); | 133 incoming_task_queue_->WillDestroyCurrentMessageLoop(); |
| 134 incoming_task_queue_ = NULL; | 134 incoming_task_queue_ = NULL; |
| 135 unbound_task_runner_ = NULL; | 135 unbound_task_runner_ = NULL; |
| 136 task_runner_ = NULL; | 136 task_runner_ = NULL; |
| 137 | 137 |
| 138 // OK, now make it so that no one can find us. | 138 // OK, now make it so that no one can find us. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 pending_high_res_tasks_--; | 401 pending_high_res_tasks_--; |
| 402 CHECK_GE(pending_high_res_tasks_, 0); | 402 CHECK_GE(pending_high_res_tasks_, 0); |
| 403 } | 403 } |
| 404 #endif | 404 #endif |
| 405 | 405 |
| 406 // Execute the task and assume the worst: It is probably not reentrant. | 406 // Execute the task and assume the worst: It is probably not reentrant. |
| 407 nestable_tasks_allowed_ = false; | 407 nestable_tasks_allowed_ = false; |
| 408 | 408 |
| 409 TRACE_TASK_EXECUTION("MessageLoop::RunTask", *pending_task); | 409 TRACE_TASK_EXECUTION("MessageLoop::RunTask", *pending_task); |
| 410 | 410 |
| 411 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 411 for (auto& observer : task_observers_) |
| 412 WillProcessTask(*pending_task)); | 412 observer.WillProcessTask(*pending_task); |
| 413 task_annotator_.RunTask("MessageLoop::PostTask", pending_task); | 413 task_annotator_.RunTask("MessageLoop::PostTask", pending_task); |
| 414 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 414 for (auto& observer : task_observers_) |
| 415 DidProcessTask(*pending_task)); | 415 observer.DidProcessTask(*pending_task); |
| 416 | 416 |
| 417 nestable_tasks_allowed_ = true; | 417 nestable_tasks_allowed_ = true; |
| 418 } | 418 } |
| 419 | 419 |
| 420 bool MessageLoop::DeferOrRunPendingTask(PendingTask pending_task) { | 420 bool MessageLoop::DeferOrRunPendingTask(PendingTask pending_task) { |
| 421 if (pending_task.nestable || run_loop_->run_depth_ == 1) { | 421 if (pending_task.nestable || run_loop_->run_depth_ == 1) { |
| 422 RunTask(&pending_task); | 422 RunTask(&pending_task); |
| 423 // Show that we ran a task (Note: a new one might arrive as a | 423 // Show that we ran a task (Note: a new one might arrive as a |
| 424 // consequence!). | 424 // consequence!). |
| 425 return true; | 425 return true; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 incoming_task_queue_->ReloadWorkQueue(&work_queue_); | 478 incoming_task_queue_->ReloadWorkQueue(&work_queue_); |
| 479 #endif | 479 #endif |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | 482 |
| 483 void MessageLoop::ScheduleWork() { | 483 void MessageLoop::ScheduleWork() { |
| 484 pump_->ScheduleWork(); | 484 pump_->ScheduleWork(); |
| 485 } | 485 } |
| 486 | 486 |
| 487 void MessageLoop::NotifyBeginNestedLoop() { | 487 void MessageLoop::NotifyBeginNestedLoop() { |
| 488 FOR_EACH_OBSERVER(NestingObserver, nesting_observers_, | 488 for (auto& observer : nesting_observers_) |
| 489 OnBeginNestedMessageLoop()); | 489 observer.OnBeginNestedMessageLoop(); |
| 490 } | 490 } |
| 491 | 491 |
| 492 bool MessageLoop::DoWork() { | 492 bool MessageLoop::DoWork() { |
| 493 if (!nestable_tasks_allowed_) { | 493 if (!nestable_tasks_allowed_) { |
| 494 // Task can't be executed right now. | 494 // Task can't be executed right now. |
| 495 return false; | 495 return false; |
| 496 } | 496 } |
| 497 | 497 |
| 498 for (;;) { | 498 for (;;) { |
| 499 ReloadWorkQueue(); | 499 ReloadWorkQueue(); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 persistent, | 654 persistent, |
| 655 mode, | 655 mode, |
| 656 controller, | 656 controller, |
| 657 delegate); | 657 delegate); |
| 658 } | 658 } |
| 659 #endif | 659 #endif |
| 660 | 660 |
| 661 #endif // !defined(OS_NACL_SFI) | 661 #endif // !defined(OS_NACL_SFI) |
| 662 | 662 |
| 663 } // namespace base | 663 } // namespace base |
| OLD | NEW |