OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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.h" | 5 #include "base/message_loop.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 void MessageLoop::AddDestructionObserver(DestructionObserver *obs) { | 142 void MessageLoop::AddDestructionObserver(DestructionObserver *obs) { |
143 DCHECK(this == current()); | 143 DCHECK(this == current()); |
144 destruction_observers_.AddObserver(obs); | 144 destruction_observers_.AddObserver(obs); |
145 } | 145 } |
146 | 146 |
147 void MessageLoop::RemoveDestructionObserver(DestructionObserver *obs) { | 147 void MessageLoop::RemoveDestructionObserver(DestructionObserver *obs) { |
148 DCHECK(this == current()); | 148 DCHECK(this == current()); |
149 destruction_observers_.RemoveObserver(obs); | 149 destruction_observers_.RemoveObserver(obs); |
150 } | 150 } |
151 | 151 |
| 152 void MessageLoop::AddTaskObserver(TaskObserver *obs) { |
| 153 DCHECK_EQ(this, current()); |
| 154 task_observers_.AddObserver(obs); |
| 155 } |
| 156 |
| 157 void MessageLoop::RemoveTaskObserver(TaskObserver *obs) { |
| 158 DCHECK_EQ(this, current()); |
| 159 task_observers_.RemoveObserver(obs); |
| 160 } |
| 161 |
152 void MessageLoop::Run() { | 162 void MessageLoop::Run() { |
153 AutoRunState save_state(this); | 163 AutoRunState save_state(this); |
154 RunHandler(); | 164 RunHandler(); |
155 } | 165 } |
156 | 166 |
157 void MessageLoop::RunAllPending() { | 167 void MessageLoop::RunAllPending() { |
158 AutoRunState save_state(this); | 168 AutoRunState save_state(this); |
159 state_->quit_received = true; // Means run until we would otherwise block. | 169 state_->quit_received = true; // Means run until we would otherwise block. |
160 RunHandler(); | 170 RunHandler(); |
161 } | 171 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 } | 328 } |
319 | 329 |
320 //------------------------------------------------------------------------------ | 330 //------------------------------------------------------------------------------ |
321 | 331 |
322 void MessageLoop::RunTask(Task* task) { | 332 void MessageLoop::RunTask(Task* task) { |
323 DCHECK(nestable_tasks_allowed_); | 333 DCHECK(nestable_tasks_allowed_); |
324 // Execute the task and assume the worst: It is probably not reentrant. | 334 // Execute the task and assume the worst: It is probably not reentrant. |
325 nestable_tasks_allowed_ = false; | 335 nestable_tasks_allowed_ = false; |
326 | 336 |
327 HistogramEvent(kTaskRunEvent); | 337 HistogramEvent(kTaskRunEvent); |
| 338 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
| 339 WillProcessTask(task->tracked_birth_time())); |
328 task->Run(); | 340 task->Run(); |
| 341 FOR_EACH_OBSERVER(TaskObserver, task_observers_, DidProcessTask()); |
329 delete task; | 342 delete task; |
330 | 343 |
331 nestable_tasks_allowed_ = true; | 344 nestable_tasks_allowed_ = true; |
332 } | 345 } |
333 | 346 |
334 bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { | 347 bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { |
335 if (pending_task.nestable || state_->run_depth == 1) { | 348 if (pending_task.nestable || state_->run_depth == 1) { |
336 RunTask(pending_task.task); | 349 RunTask(pending_task.task); |
337 // Show that we ran a task (Note: a new one might arrive as a | 350 // Show that we ran a task (Note: a new one might arrive as a |
338 // consequence!). | 351 // consequence!). |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 VALUE_TO_NUMBER_AND_NAME(kTaskRunEvent) | 590 VALUE_TO_NUMBER_AND_NAME(kTaskRunEvent) |
578 VALUE_TO_NUMBER_AND_NAME(kTimerEvent) | 591 VALUE_TO_NUMBER_AND_NAME(kTimerEvent) |
579 | 592 |
580 {-1, NULL} // The list must be null terminated, per API to histogram. | 593 {-1, NULL} // The list must be null terminated, per API to histogram. |
581 }; | 594 }; |
582 | 595 |
583 //------------------------------------------------------------------------------ | 596 //------------------------------------------------------------------------------ |
584 // MessageLoopForUI | 597 // MessageLoopForUI |
585 | 598 |
586 #if defined(OS_WIN) | 599 #if defined(OS_WIN) |
587 void MessageLoopForUI::WillProcessMessage(const MSG& message) { | |
588 pump_win()->WillProcessMessage(message); | |
589 } | |
590 void MessageLoopForUI::DidProcessMessage(const MSG& message) { | 600 void MessageLoopForUI::DidProcessMessage(const MSG& message) { |
591 pump_win()->DidProcessMessage(message); | 601 pump_win()->DidProcessMessage(message); |
592 } | 602 } |
593 void MessageLoopForUI::PumpOutPendingPaintMessages() { | |
594 pump_ui()->PumpOutPendingPaintMessages(); | |
595 } | |
596 | |
597 #endif // defined(OS_WIN) | 603 #endif // defined(OS_WIN) |
598 | 604 |
599 #if !defined(OS_MACOSX) | 605 #if !defined(OS_MACOSX) |
600 void MessageLoopForUI::AddObserver(Observer* observer) { | 606 void MessageLoopForUI::AddObserver(Observer* observer) { |
601 pump_ui()->AddObserver(observer); | 607 pump_ui()->AddObserver(observer); |
602 } | 608 } |
603 | 609 |
604 void MessageLoopForUI::RemoveObserver(Observer* observer) { | 610 void MessageLoopForUI::RemoveObserver(Observer* observer) { |
605 pump_ui()->RemoveObserver(observer); | 611 pump_ui()->RemoveObserver(observer); |
606 } | 612 } |
(...skipping 27 matching lines...) Expand all Loading... |
634 Watcher *delegate) { | 640 Watcher *delegate) { |
635 return pump_libevent()->WatchFileDescriptor( | 641 return pump_libevent()->WatchFileDescriptor( |
636 fd, | 642 fd, |
637 persistent, | 643 persistent, |
638 static_cast<base::MessagePumpLibevent::Mode>(mode), | 644 static_cast<base::MessagePumpLibevent::Mode>(mode), |
639 controller, | 645 controller, |
640 delegate); | 646 delegate); |
641 } | 647 } |
642 | 648 |
643 #endif | 649 #endif |
OLD | NEW |