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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 : type_(type), | 119 : type_(type), |
120 #if defined(OS_WIN) | 120 #if defined(OS_WIN) |
121 pending_high_res_tasks_(0), | 121 pending_high_res_tasks_(0), |
122 in_high_res_mode_(false), | 122 in_high_res_mode_(false), |
123 #endif | 123 #endif |
124 nestable_tasks_allowed_(true), | 124 nestable_tasks_allowed_(true), |
125 #if defined(OS_WIN) | 125 #if defined(OS_WIN) |
126 os_modal_loop_(false), | 126 os_modal_loop_(false), |
127 #endif // OS_WIN | 127 #endif // OS_WIN |
128 message_histogram_(NULL), | 128 message_histogram_(NULL), |
129 run_loop_(NULL) { | 129 run_loop_(NULL), |
| 130 current_pending_task_(NULL) { |
130 Init(); | 131 Init(); |
131 | 132 |
132 pump_ = CreateMessagePumpForType(type).Pass(); | 133 pump_ = CreateMessagePumpForType(type).Pass(); |
133 } | 134 } |
134 | 135 |
135 MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump) | 136 MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump) |
136 : pump_(pump.Pass()), | 137 : pump_(pump.Pass()), |
137 type_(TYPE_CUSTOM), | 138 type_(TYPE_CUSTOM), |
138 #if defined(OS_WIN) | 139 #if defined(OS_WIN) |
139 pending_high_res_tasks_(0), | 140 pending_high_res_tasks_(0), |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 420 |
420 PendingTask pending_task = deferred_non_nestable_work_queue_.front(); | 421 PendingTask pending_task = deferred_non_nestable_work_queue_.front(); |
421 deferred_non_nestable_work_queue_.pop(); | 422 deferred_non_nestable_work_queue_.pop(); |
422 | 423 |
423 RunTask(pending_task); | 424 RunTask(pending_task); |
424 return true; | 425 return true; |
425 } | 426 } |
426 | 427 |
427 void MessageLoop::RunTask(const PendingTask& pending_task) { | 428 void MessageLoop::RunTask(const PendingTask& pending_task) { |
428 DCHECK(nestable_tasks_allowed_); | 429 DCHECK(nestable_tasks_allowed_); |
| 430 current_pending_task_ = &pending_task; |
429 | 431 |
430 #if defined(OS_WIN) | 432 #if defined(OS_WIN) |
431 if (pending_task.is_high_res) { | 433 if (pending_task.is_high_res) { |
432 pending_high_res_tasks_--; | 434 pending_high_res_tasks_--; |
433 CHECK_GE(pending_high_res_tasks_, 0); | 435 CHECK_GE(pending_high_res_tasks_, 0); |
434 } | 436 } |
435 #endif | 437 #endif |
436 | 438 |
437 // Execute the task and assume the worst: It is probably not reentrant. | 439 // Execute the task and assume the worst: It is probably not reentrant. |
438 nestable_tasks_allowed_ = false; | 440 nestable_tasks_allowed_ = false; |
439 | 441 |
440 HistogramEvent(kTaskRunEvent); | 442 HistogramEvent(kTaskRunEvent); |
441 | 443 |
442 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 444 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
443 WillProcessTask(pending_task)); | 445 WillProcessTask(pending_task)); |
444 task_annotator_.RunTask( | 446 task_annotator_.RunTask( |
445 "MessageLoop::PostTask", "MessageLoop::RunTask", pending_task); | 447 "MessageLoop::PostTask", "MessageLoop::RunTask", pending_task); |
446 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 448 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
447 DidProcessTask(pending_task)); | 449 DidProcessTask(pending_task)); |
448 | 450 |
449 nestable_tasks_allowed_ = true; | 451 nestable_tasks_allowed_ = true; |
| 452 |
| 453 current_pending_task_ = NULL; |
450 } | 454 } |
451 | 455 |
452 bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { | 456 bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { |
453 if (pending_task.nestable || run_loop_->run_depth_ == 1) { | 457 if (pending_task.nestable || run_loop_->run_depth_ == 1) { |
454 RunTask(pending_task); | 458 RunTask(pending_task); |
455 // Show that we ran a task (Note: a new one might arrive as a | 459 // Show that we ran a task (Note: a new one might arrive as a |
456 // consequence!). | 460 // consequence!). |
457 return true; | 461 return true; |
458 } | 462 } |
459 | 463 |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 persistent, | 715 persistent, |
712 mode, | 716 mode, |
713 controller, | 717 controller, |
714 delegate); | 718 delegate); |
715 } | 719 } |
716 #endif | 720 #endif |
717 | 721 |
718 #endif // !defined(OS_NACL_SFI) | 722 #endif // !defined(OS_NACL_SFI) |
719 | 723 |
720 } // namespace base | 724 } // namespace base |
OLD | NEW |