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