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 <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 DCHECK_EQ(this, current()); | 270 DCHECK_EQ(this, current()); |
271 nesting_observers_.AddObserver(observer); | 271 nesting_observers_.AddObserver(observer); |
272 } | 272 } |
273 | 273 |
274 void MessageLoop::RemoveNestingObserver(NestingObserver* observer) { | 274 void MessageLoop::RemoveNestingObserver(NestingObserver* observer) { |
275 DCHECK_EQ(this, current()); | 275 DCHECK_EQ(this, current()); |
276 nesting_observers_.RemoveObserver(observer); | 276 nesting_observers_.RemoveObserver(observer); |
277 } | 277 } |
278 | 278 |
279 #if !(defined(OS_MACOSX) && !defined(OS_IOS)) | 279 #if !(defined(OS_MACOSX) && !defined(OS_IOS)) |
280 void MessageLoop::PostTask( | 280 void MessageLoop::PostTask(const tracked_objects::Location& from_here, |
281 const tracked_objects::Location& from_here, | 281 OnceClosure task) { |
282 const Closure& task) { | 282 task_runner_->PostTask(from_here, std::move(task)); |
283 task_runner_->PostTask(from_here, task); | |
284 } | 283 } |
285 | 284 |
286 void MessageLoop::PostDelayedTask( | 285 void MessageLoop::PostDelayedTask(const tracked_objects::Location& from_here, |
287 const tracked_objects::Location& from_here, | 286 OnceClosure task, |
288 const Closure& task, | 287 TimeDelta delay) { |
289 TimeDelta delay) { | 288 task_runner_->PostDelayedTask(from_here, std::move(task), delay); |
290 task_runner_->PostDelayedTask(from_here, task, delay); | |
291 } | 289 } |
292 #endif // !(defined(OS_MACOSX) && !defined(OS_IOS)) | 290 #endif // !(defined(OS_MACOSX) && !defined(OS_IOS)) |
293 | 291 |
294 void MessageLoop::Run() { | 292 void MessageLoop::Run() { |
295 DCHECK(pump_); | 293 DCHECK(pump_); |
296 RunLoop run_loop; | 294 RunLoop run_loop; |
297 run_loop.Run(); | 295 run_loop.Run(); |
298 } | 296 } |
299 | 297 |
300 void MessageLoop::RunUntilIdle() { | 298 void MessageLoop::RunUntilIdle() { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 pump_->Run(this); | 449 pump_->Run(this); |
452 } | 450 } |
453 | 451 |
454 bool MessageLoop::ProcessNextDelayedNonNestableTask() { | 452 bool MessageLoop::ProcessNextDelayedNonNestableTask() { |
455 if (run_loop_->run_depth_ != 1) | 453 if (run_loop_->run_depth_ != 1) |
456 return false; | 454 return false; |
457 | 455 |
458 if (deferred_non_nestable_work_queue_.empty()) | 456 if (deferred_non_nestable_work_queue_.empty()) |
459 return false; | 457 return false; |
460 | 458 |
461 PendingTask pending_task = | 459 PendingTask pending_task = std::move( |
462 std::move(deferred_non_nestable_work_queue_.front()); | 460 const_cast<PendingTask&>(deferred_non_nestable_work_queue_.front())); |
463 deferred_non_nestable_work_queue_.pop(); | 461 deferred_non_nestable_work_queue_.pop(); |
464 | 462 |
465 RunTask(pending_task); | 463 RunTask(std::move(pending_task)); |
466 return true; | 464 return true; |
467 } | 465 } |
468 | 466 |
469 void MessageLoop::RunTask(const PendingTask& pending_task) { | 467 void MessageLoop::RunTask(PendingTask pending_task) { |
470 DCHECK(nestable_tasks_allowed_); | 468 DCHECK(nestable_tasks_allowed_); |
471 | 469 |
472 #if defined(OS_WIN) | 470 #if defined(OS_WIN) |
473 if (pending_task.is_high_res) { | 471 if (pending_task.is_high_res) { |
474 pending_high_res_tasks_--; | 472 pending_high_res_tasks_--; |
475 CHECK_GE(pending_high_res_tasks_, 0); | 473 CHECK_GE(pending_high_res_tasks_, 0); |
476 } | 474 } |
477 #endif | 475 #endif |
478 | 476 |
479 // Execute the task and assume the worst: It is probably not reentrant. | 477 // Execute the task and assume the worst: It is probably not reentrant. |
480 nestable_tasks_allowed_ = false; | 478 nestable_tasks_allowed_ = false; |
481 | 479 |
482 HistogramEvent(kTaskRunEvent); | 480 HistogramEvent(kTaskRunEvent); |
483 | 481 |
484 TRACE_TASK_EXECUTION("MessageLoop::RunTask", pending_task); | 482 TRACE_TASK_EXECUTION("MessageLoop::RunTask", pending_task); |
485 | 483 |
486 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 484 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
487 WillProcessTask(pending_task)); | 485 WillProcessTask(pending_task)); |
488 task_annotator_.RunTask("MessageLoop::PostTask", pending_task); | 486 task_annotator_.RunTask("MessageLoop::PostTask", &pending_task); |
489 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 487 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
490 DidProcessTask(pending_task)); | 488 DidProcessTask(pending_task)); |
491 | 489 |
492 nestable_tasks_allowed_ = true; | 490 nestable_tasks_allowed_ = true; |
493 } | 491 } |
494 | 492 |
495 bool MessageLoop::DeferOrRunPendingTask(PendingTask pending_task) { | 493 bool MessageLoop::DeferOrRunPendingTask(PendingTask pending_task) { |
496 if (pending_task.nestable || run_loop_->run_depth_ == 1) { | 494 if (pending_task.nestable || run_loop_->run_depth_ == 1) { |
497 RunTask(pending_task); | 495 RunTask(std::move(pending_task)); |
498 // Show that we ran a task (Note: a new one might arrive as a | 496 // Show that we ran a task (Note: a new one might arrive as a |
499 // consequence!). | 497 // consequence!). |
500 return true; | 498 return true; |
501 } | 499 } |
502 | 500 |
503 // We couldn't run the task now because we're in a nested message loop | 501 // We couldn't run the task now because we're in a nested message loop |
504 // and the task isn't nestable. | 502 // and the task isn't nestable. |
505 deferred_non_nestable_work_queue_.push(std::move(pending_task)); | 503 deferred_non_nestable_work_queue_.push(std::move(pending_task)); |
506 return false; | 504 return false; |
507 } | 505 } |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 persistent, | 773 persistent, |
776 mode, | 774 mode, |
777 controller, | 775 controller, |
778 delegate); | 776 delegate); |
779 } | 777 } |
780 #endif | 778 #endif |
781 | 779 |
782 #endif // !defined(OS_NACL_SFI) | 780 #endif // !defined(OS_NACL_SFI) |
783 | 781 |
784 } // namespace base | 782 } // namespace base |
OLD | NEW |