| 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 if (run_loop_->run_depth_ != 1) | 380 if (run_loop_->run_depth_ != 1) |
| 381 return false; | 381 return false; |
| 382 | 382 |
| 383 if (deferred_non_nestable_work_queue_.empty()) | 383 if (deferred_non_nestable_work_queue_.empty()) |
| 384 return false; | 384 return false; |
| 385 | 385 |
| 386 PendingTask pending_task = | 386 PendingTask pending_task = |
| 387 std::move(deferred_non_nestable_work_queue_.front()); | 387 std::move(deferred_non_nestable_work_queue_.front()); |
| 388 deferred_non_nestable_work_queue_.pop(); | 388 deferred_non_nestable_work_queue_.pop(); |
| 389 | 389 |
| 390 RunTask(pending_task); | 390 RunTask(&pending_task); |
| 391 return true; | 391 return true; |
| 392 } | 392 } |
| 393 | 393 |
| 394 void MessageLoop::RunTask(const PendingTask& pending_task) { | 394 void MessageLoop::RunTask(PendingTask* pending_task) { |
| 395 DCHECK(nestable_tasks_allowed_); | 395 DCHECK(nestable_tasks_allowed_); |
| 396 | 396 |
| 397 #if defined(OS_WIN) | 397 #if defined(OS_WIN) |
| 398 if (pending_task.is_high_res) { | 398 if (pending_task->is_high_res) { |
| 399 pending_high_res_tasks_--; | 399 pending_high_res_tasks_--; |
| 400 CHECK_GE(pending_high_res_tasks_, 0); | 400 CHECK_GE(pending_high_res_tasks_, 0); |
| 401 } | 401 } |
| 402 #endif | 402 #endif |
| 403 | 403 |
| 404 // Execute the task and assume the worst: It is probably not reentrant. | 404 // Execute the task and assume the worst: It is probably not reentrant. |
| 405 nestable_tasks_allowed_ = false; | 405 nestable_tasks_allowed_ = false; |
| 406 | 406 |
| 407 TRACE_TASK_EXECUTION("MessageLoop::RunTask", pending_task); | 407 TRACE_TASK_EXECUTION("MessageLoop::RunTask", *pending_task); |
| 408 | 408 |
| 409 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 409 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
| 410 WillProcessTask(pending_task)); | 410 WillProcessTask(*pending_task)); |
| 411 task_annotator_.RunTask("MessageLoop::PostTask", pending_task); | 411 task_annotator_.RunTask("MessageLoop::PostTask", pending_task); |
| 412 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 412 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
| 413 DidProcessTask(pending_task)); | 413 DidProcessTask(*pending_task)); |
| 414 | 414 |
| 415 nestable_tasks_allowed_ = true; | 415 nestable_tasks_allowed_ = true; |
| 416 } | 416 } |
| 417 | 417 |
| 418 bool MessageLoop::DeferOrRunPendingTask(PendingTask pending_task) { | 418 bool MessageLoop::DeferOrRunPendingTask(PendingTask pending_task) { |
| 419 if (pending_task.nestable || run_loop_->run_depth_ == 1) { | 419 if (pending_task.nestable || run_loop_->run_depth_ == 1) { |
| 420 RunTask(pending_task); | 420 RunTask(&pending_task); |
| 421 // Show that we ran a task (Note: a new one might arrive as a | 421 // Show that we ran a task (Note: a new one might arrive as a |
| 422 // consequence!). | 422 // consequence!). |
| 423 return true; | 423 return true; |
| 424 } | 424 } |
| 425 | 425 |
| 426 // We couldn't run the task now because we're in a nested message loop | 426 // We couldn't run the task now because we're in a nested message loop |
| 427 // and the task isn't nestable. | 427 // and the task isn't nestable. |
| 428 deferred_non_nestable_work_queue_.push(std::move(pending_task)); | 428 deferred_non_nestable_work_queue_.push(std::move(pending_task)); |
| 429 return false; | 429 return false; |
| 430 } | 430 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 persistent, | 652 persistent, |
| 653 mode, | 653 mode, |
| 654 controller, | 654 controller, |
| 655 delegate); | 655 delegate); |
| 656 } | 656 } |
| 657 #endif | 657 #endif |
| 658 | 658 |
| 659 #endif // !defined(OS_NACL_SFI) | 659 #endif // !defined(OS_NACL_SFI) |
| 660 | 660 |
| 661 } // namespace base | 661 } // namespace base |
| OLD | NEW |