blob: fffeb098e4095b11607028eed9685c710176736b [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
[email protected]ea15e982008-08-15 07:31:205#include "base/message_loop.h"
6
[email protected]fc7fb6e2008-08-16 03:09:057#include <algorithm>
8
[email protected]752578562008-09-07 08:08:299#if defined(OS_WIN)
10#include <mmsystem.h>
11#endif
12
[email protected]f1ea2fa2008-08-21 22:26:0613#include "base/compiler_specific.h"
initial.commitd7cae122008-07-26 21:49:3814#include "base/logging.h"
[email protected]b16ef312008-08-19 18:36:2315#include "base/message_pump_default.h"
initial.commitd7cae122008-07-26 21:49:3816#include "base/string_util.h"
17#include "base/thread_local_storage.h"
initial.commitd7cae122008-07-26 21:49:3818
19// a TLS index to the message loop for the current thread
20// Note that if we start doing complex stuff in other static initializers
21// this could cause problems.
[email protected]6a6e6572008-08-20 22:54:5222// TODO(evanm): this shouldn't rely on static initialization.
23// static
24TLSSlot MessageLoop::tls_index_;
initial.commitd7cae122008-07-26 21:49:3825
26//------------------------------------------------------------------------------
27
initial.commitd7cae122008-07-26 21:49:3828// Logical events for Histogram profiling. Run with -message-loop-histogrammer
29// to get an accounting of messages and actions taken on each thread.
[email protected]fc7fb6e2008-08-16 03:09:0530static const int kTaskRunEvent = 0x1;
31static const int kTimerEvent = 0x2;
initial.commitd7cae122008-07-26 21:49:3832
33// Provide range of message IDs for use in histogramming and debug display.
34static const int kLeastNonZeroMessageId = 1;
35static const int kMaxMessageId = 1099;
36static const int kNumberOfDistinctMessagesDisplayed = 1100;
37
38//------------------------------------------------------------------------------
39
[email protected]fc7fb6e2008-08-16 03:09:0540#if defined(OS_WIN)
initial.commitd7cae122008-07-26 21:49:3841
initial.commitd7cae122008-07-26 21:49:3842// Upon a SEH exception in this thread, it restores the original unhandled
43// exception filter.
44static int SEHFilter(LPTOP_LEVEL_EXCEPTION_FILTER old_filter) {
45 ::SetUnhandledExceptionFilter(old_filter);
46 return EXCEPTION_CONTINUE_SEARCH;
47}
48
49// Retrieves a pointer to the current unhandled exception filter. There
50// is no standalone getter method.
51static LPTOP_LEVEL_EXCEPTION_FILTER GetTopSEHFilter() {
52 LPTOP_LEVEL_EXCEPTION_FILTER top_filter = NULL;
53 top_filter = ::SetUnhandledExceptionFilter(0);
54 ::SetUnhandledExceptionFilter(top_filter);
55 return top_filter;
56}
57
[email protected]fc7fb6e2008-08-16 03:09:0558#endif // defined(OS_WIN)
59
initial.commitd7cae122008-07-26 21:49:3860//------------------------------------------------------------------------------
61
[email protected]4d9bdfaf2008-08-26 05:53:5762MessageLoop::MessageLoop(Type type)
63 : type_(type),
[email protected]a5b94a92008-08-12 23:25:4364 nestable_tasks_allowed_(true),
[email protected]b16ef312008-08-19 18:36:2365 exception_restoration_(false),
[email protected]752578562008-09-07 08:08:2966 state_(NULL),
67 next_sequence_num_(0) {
[email protected]4d9bdfaf2008-08-26 05:53:5768 DCHECK(!tls_index_.Get()) << "should only have one message loop per thread";
[email protected]6a6e6572008-08-20 22:54:5269 tls_index_.Set(this);
[email protected]4d9bdfaf2008-08-26 05:53:5770
[email protected]752578562008-09-07 08:08:2971 // TODO(darin): This does not seem like the best place for this code to live!
72#if defined(OS_WIN)
73 // We've experimented with all sorts of timers, and initially tried
74 // to avoid using timeBeginPeriod because it does affect the system
75 // globally. However, after much investigation, it turns out that all
76 // of the major plugins (flash, windows media 9-11, and quicktime)
77 // already use timeBeginPeriod to increase the speed of the clock.
78 // Since the browser must work with these plugins, the browser already
79 // needs to support a fast clock. We may as well use this ourselves,
80 // as it really is the best timer mechanism for our needs.
81 timeBeginPeriod(1);
82#endif
83
[email protected]ef8963172008-08-26 06:52:4184 // TODO(darin): Choose the pump based on the requested type.
[email protected]fc7fb6e2008-08-16 03:09:0585#if defined(OS_WIN)
[email protected]9bcbf472008-08-30 00:22:4886 if (type_ == TYPE_DEFAULT) {
87 pump_ = new base::MessagePumpDefault();
88 } else {
89 pump_ = new base::MessagePumpWin();
90 }
[email protected]b16ef312008-08-19 18:36:2391#else
[email protected]ef8963172008-08-26 06:52:4192 pump_ = new base::MessagePumpDefault();
[email protected]fc7fb6e2008-08-16 03:09:0593#endif
initial.commitd7cae122008-07-26 21:49:3894}
95
96MessageLoop::~MessageLoop() {
97 DCHECK(this == current());
[email protected]2a127252008-08-05 23:16:4198
99 // Let interested parties have one last shot at accessing this.
100 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_,
101 WillDestroyCurrentMessageLoop());
102
[email protected]166020b2008-09-09 05:15:56103 // OK, now make it so that no one can find us.
104 tls_index_.Set(NULL);
[email protected]06c6a6c2008-09-07 08:52:31105
[email protected]08de3cde2008-09-09 05:55:35106 DCHECK(!state_);
107
108 // Most tasks that have not been Run() are deleted in the |timer_manager_|
109 // destructor after we remove our tls index. We delete the tasks in our
110 // queues here so their destuction is similar to the tasks in the
111 // |timer_manager_|.
112 DeletePendingTasks();
113 ReloadWorkQueue();
114 DeletePendingTasks();
115
116 // Delete tasks in the delayed work queue.
117 while (!delayed_work_queue_.empty()) {
118 Task* task = delayed_work_queue_.top().task;
119 delayed_work_queue_.pop();
120 delete task;
121 }
122
[email protected]752578562008-09-07 08:08:29123#if defined(OS_WIN)
124 // Match timeBeginPeriod() from construction.
125 timeEndPeriod(1);
126#endif
initial.commitd7cae122008-07-26 21:49:38127}
128
[email protected]2a127252008-08-05 23:16:41129void MessageLoop::AddDestructionObserver(DestructionObserver *obs) {
130 DCHECK(this == current());
131 destruction_observers_.AddObserver(obs);
132}
133
134void MessageLoop::RemoveDestructionObserver(DestructionObserver *obs) {
135 DCHECK(this == current());
136 destruction_observers_.RemoveObserver(obs);
137}
138
[email protected]ea15e982008-08-15 07:31:20139void MessageLoop::Run() {
[email protected]fc7fb6e2008-08-16 03:09:05140 AutoRunState save_state(this);
141 RunHandler();
[email protected]ea15e982008-08-15 07:31:20142}
143
[email protected]7e0e8762008-07-31 13:10:20144void MessageLoop::RunAllPending() {
[email protected]fc7fb6e2008-08-16 03:09:05145 AutoRunState save_state(this);
146 state_->quit_received = true; // Means run until we would otherwise block.
147 RunHandler();
initial.commitd7cae122008-07-26 21:49:38148}
149
150// Runs the loop in two different SEH modes:
151// enable_SEH_restoration_ = false : any unhandled exception goes to the last
152// one that calls SetUnhandledExceptionFilter().
153// enable_SEH_restoration_ = true : any unhandled exception goes to the filter
154// that was existed before the loop was run.
[email protected]fc7fb6e2008-08-16 03:09:05155void MessageLoop::RunHandler() {
156#if defined(OS_WIN)
initial.commitd7cae122008-07-26 21:49:38157 if (exception_restoration_) {
158 LPTOP_LEVEL_EXCEPTION_FILTER current_filter = GetTopSEHFilter();
159 __try {
[email protected]fc7fb6e2008-08-16 03:09:05160 RunInternal();
initial.commitd7cae122008-07-26 21:49:38161 } __except(SEHFilter(current_filter)) {
162 }
[email protected]fc7fb6e2008-08-16 03:09:05163 return;
initial.commitd7cae122008-07-26 21:49:38164 }
[email protected]fc7fb6e2008-08-16 03:09:05165#endif
166
167 RunInternal();
initial.commitd7cae122008-07-26 21:49:38168}
169
170//------------------------------------------------------------------------------
initial.commitd7cae122008-07-26 21:49:38171
[email protected]fc7fb6e2008-08-16 03:09:05172void MessageLoop::RunInternal() {
173 DCHECK(this == current());
174
initial.commitd7cae122008-07-26 21:49:38175 StartHistogrammer();
176
[email protected]fc7fb6e2008-08-16 03:09:05177#if defined(OS_WIN)
178 if (state_->dispatcher) {
179 pump_win()->RunWithDispatcher(this, state_->dispatcher);
180 return;
[email protected]7e0e8762008-07-31 13:10:20181 }
[email protected]fc7fb6e2008-08-16 03:09:05182#endif
183
184 pump_->Run(this);
[email protected]b8f2fe5d2008-07-30 07:50:53185}
[email protected]7622bd02008-07-30 06:58:56186
[email protected]3882c4332008-07-30 19:03:59187//------------------------------------------------------------------------------
188// Wrapper functions for use in above message loop framework.
189
initial.commitd7cae122008-07-26 21:49:38190bool MessageLoop::ProcessNextDelayedNonNestableTask() {
[email protected]fc7fb6e2008-08-16 03:09:05191 if (state_->run_depth != 1)
initial.commitd7cae122008-07-26 21:49:38192 return false;
193
[email protected]752578562008-09-07 08:08:29194 if (deferred_non_nestable_work_queue_.empty())
initial.commitd7cae122008-07-26 21:49:38195 return false;
[email protected]752578562008-09-07 08:08:29196
197 Task* task = deferred_non_nestable_work_queue_.front().task;
198 deferred_non_nestable_work_queue_.pop();
199
200 RunTask(task);
initial.commitd7cae122008-07-26 21:49:38201 return true;
202}
203
initial.commitd7cae122008-07-26 21:49:38204//------------------------------------------------------------------------------
205
206void MessageLoop::Quit() {
[email protected]fc7fb6e2008-08-16 03:09:05207 DCHECK(current() == this);
208 if (state_) {
209 state_->quit_received = true;
210 } else {
211 NOTREACHED() << "Must be inside Run to call Quit";
initial.commitd7cae122008-07-26 21:49:38212 }
initial.commitd7cae122008-07-26 21:49:38213}
214
[email protected]752578562008-09-07 08:08:29215void MessageLoop::PostTask(
216 const tracked_objects::Location& from_here, Task* task) {
217 PostTask_Helper(from_here, task, 0, true);
218}
219
220void MessageLoop::PostDelayedTask(
221 const tracked_objects::Location& from_here, Task* task, int delay_ms) {
222 PostTask_Helper(from_here, task, delay_ms, true);
223}
224
225void MessageLoop::PostNonNestableTask(
226 const tracked_objects::Location& from_here, Task* task) {
227 PostTask_Helper(from_here, task, 0, false);
228}
229
230void MessageLoop::PostNonNestableDelayedTask(
231 const tracked_objects::Location& from_here, Task* task, int delay_ms) {
232 PostTask_Helper(from_here, task, delay_ms, false);
233}
234
initial.commitd7cae122008-07-26 21:49:38235// Possibly called on a background thread!
[email protected]752578562008-09-07 08:08:29236void MessageLoop::PostTask_Helper(
237 const tracked_objects::Location& from_here, Task* task, int delay_ms,
238 bool nestable) {
initial.commitd7cae122008-07-26 21:49:38239 task->SetBirthPlace(from_here);
[email protected]9bcbf472008-08-30 00:22:48240
[email protected]752578562008-09-07 08:08:29241 PendingTask pending_task(task, nestable);
[email protected]9bcbf472008-08-30 00:22:48242
243 if (delay_ms > 0) {
[email protected]752578562008-09-07 08:08:29244 pending_task.delayed_run_time =
[email protected]9bcbf472008-08-30 00:22:48245 Time::Now() + TimeDelta::FromMilliseconds(delay_ms);
246 } else {
247 DCHECK(delay_ms == 0) << "delay should not be negative";
248 }
249
initial.commitd7cae122008-07-26 21:49:38250 // Warning: Don't try to short-circuit, and handle this thread's tasks more
251 // directly, as it could starve handling of foreign threads. Put every task
252 // into this queue.
253
[email protected]fc7fb6e2008-08-16 03:09:05254 scoped_refptr<base::MessagePump> pump;
initial.commitd7cae122008-07-26 21:49:38255 {
[email protected]fc7fb6e2008-08-16 03:09:05256 AutoLock locked(incoming_queue_lock_);
257
[email protected]752578562008-09-07 08:08:29258 bool was_empty = incoming_queue_.empty();
259 incoming_queue_.push(pending_task);
initial.commitd7cae122008-07-26 21:49:38260 if (!was_empty)
261 return; // Someone else should have started the sub-pump.
262
[email protected]fc7fb6e2008-08-16 03:09:05263 pump = pump_;
[email protected]ea15e982008-08-15 07:31:20264 }
[email protected]fc7fb6e2008-08-16 03:09:05265 // Since the incoming_queue_ may contain a task that destroys this message
266 // loop, we cannot exit incoming_queue_lock_ until we are done with |this|.
267 // We use a stack-based reference to the message pump so that we can call
268 // ScheduleWork outside of incoming_queue_lock_.
[email protected]ea15e982008-08-15 07:31:20269
[email protected]fc7fb6e2008-08-16 03:09:05270 pump->ScheduleWork();
initial.commitd7cae122008-07-26 21:49:38271}
272
273void MessageLoop::SetNestableTasksAllowed(bool allowed) {
[email protected]124a2bdf2008-08-09 00:14:09274 if (nestable_tasks_allowed_ != allowed) {
275 nestable_tasks_allowed_ = allowed;
276 if (!nestable_tasks_allowed_)
277 return;
278 // Start the native pump if we are not already pumping.
[email protected]fc7fb6e2008-08-16 03:09:05279 pump_->ScheduleWork();
[email protected]124a2bdf2008-08-09 00:14:09280 }
initial.commitd7cae122008-07-26 21:49:38281}
282
283bool MessageLoop::NestableTasksAllowed() const {
284 return nestable_tasks_allowed_;
285}
286
initial.commitd7cae122008-07-26 21:49:38287//------------------------------------------------------------------------------
initial.commitd7cae122008-07-26 21:49:38288
initial.commitd7cae122008-07-26 21:49:38289void MessageLoop::RunTask(Task* task) {
initial.commitd7cae122008-07-26 21:49:38290 DCHECK(nestable_tasks_allowed_);
291 // Execute the task and assume the worst: It is probably not reentrant.
292 nestable_tasks_allowed_ = false;
[email protected]752578562008-09-07 08:08:29293
294 HistogramEvent(kTaskRunEvent);
295 task->Run();
296 delete task;
297
298 nestable_tasks_allowed_ = true;
initial.commitd7cae122008-07-26 21:49:38299}
300
[email protected]752578562008-09-07 08:08:29301bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) {
302 if (pending_task.nestable || state_->run_depth == 1) {
303 RunTask(pending_task.task);
304 // Show that we ran a task (Note: a new one might arrive as a
305 // consequence!).
306 return true;
307 }
308
309 // We couldn't run the task now because we're in a nested message loop
310 // and the task isn't nestable.
311 deferred_non_nestable_work_queue_.push(pending_task);
312 return false;
initial.commitd7cae122008-07-26 21:49:38313}
314
initial.commitd7cae122008-07-26 21:49:38315void MessageLoop::ReloadWorkQueue() {
316 // We can improve performance of our loading tasks from incoming_queue_ to
[email protected]fc7fb6e2008-08-16 03:09:05317 // work_queue_ by waiting until the last minute (work_queue_ is empty) to
318 // load. That reduces the number of locks-per-task significantly when our
[email protected]752578562008-09-07 08:08:29319 // queues get large.
320 if (!work_queue_.empty())
initial.commitd7cae122008-07-26 21:49:38321 return; // Wait till we *really* need to lock and load.
322
323 // Acquire all we can from the inter-thread queue with one lock acquisition.
initial.commitd7cae122008-07-26 21:49:38324 {
325 AutoLock lock(incoming_queue_lock_);
[email protected]752578562008-09-07 08:08:29326 if (incoming_queue_.empty())
initial.commitd7cae122008-07-26 21:49:38327 return;
[email protected]752578562008-09-07 08:08:29328 std::swap(incoming_queue_, work_queue_);
329 DCHECK(incoming_queue_.empty());
initial.commitd7cae122008-07-26 21:49:38330 }
331}
332
[email protected]08de3cde2008-09-09 05:55:35333void MessageLoop::DeletePendingTasks() {
334 /* Comment this out as it's causing crashes.
335 while (!work_queue_.Empty()) {
336 Task* task = work_queue_.Pop();
337 if (task->is_owned_by_message_loop())
338 delete task;
initial.commitd7cae122008-07-26 21:49:38339 }
[email protected]08de3cde2008-09-09 05:55:35340
341 while (!delayed_non_nestable_queue_.Empty()) {
342 Task* task = delayed_non_nestable_queue_.Pop();
343 if (task->is_owned_by_message_loop())
344 delete task;
initial.commitd7cae122008-07-26 21:49:38345 }
[email protected]08de3cde2008-09-09 05:55:35346 */
initial.commitd7cae122008-07-26 21:49:38347}
348
[email protected]fc7fb6e2008-08-16 03:09:05349bool MessageLoop::DoWork() {
[email protected]752578562008-09-07 08:08:29350 if (!nestable_tasks_allowed_) {
351 // Task can't be executed right now.
352 return false;
353 }
354
355 for (;;) {
356 ReloadWorkQueue();
357 if (work_queue_.empty())
358 break;
359
360 // Execute oldest task.
361 do {
362 PendingTask pending_task = work_queue_.front();
363 work_queue_.pop();
364 if (!pending_task.delayed_run_time.is_null()) {
365 bool was_empty = delayed_work_queue_.empty();
366
367 // Move to the delayed work queue. Initialize the sequence number
368 // before inserting into the delayed_work_queue_. The sequence number
369 // is used to faciliate FIFO sorting when two tasks have the same
370 // delayed_run_time value.
371 pending_task.sequence_num = next_sequence_num_++;
372 delayed_work_queue_.push(pending_task);
373
374 if (was_empty) // We only schedule the next delayed work item.
375 pump_->ScheduleDelayedWork(pending_task.delayed_run_time);
376 } else {
377 if (DeferOrRunPendingTask(pending_task))
378 return true;
379 }
380 } while (!work_queue_.empty());
381 }
382
383 // Nothing happened.
384 return false;
[email protected]fc7fb6e2008-08-16 03:09:05385}
386
[email protected]b24250fc2008-08-20 06:30:58387bool MessageLoop::DoDelayedWork(Time* next_delayed_work_time) {
[email protected]752578562008-09-07 08:08:29388 if (!nestable_tasks_allowed_ || delayed_work_queue_.empty()) {
389 *next_delayed_work_time = Time();
390 return false;
391 }
392
393 if (delayed_work_queue_.top().delayed_run_time > Time::Now()) {
394 *next_delayed_work_time = delayed_work_queue_.top().delayed_run_time;
395 return false;
396 }
[email protected]fc7fb6e2008-08-16 03:09:05397
[email protected]752578562008-09-07 08:08:29398 PendingTask pending_task = delayed_work_queue_.top();
399 delayed_work_queue_.pop();
400
401 if (!delayed_work_queue_.empty())
402 *next_delayed_work_time = delayed_work_queue_.top().delayed_run_time;
[email protected]fc7fb6e2008-08-16 03:09:05403
[email protected]752578562008-09-07 08:08:29404 return DeferOrRunPendingTask(pending_task);
[email protected]fc7fb6e2008-08-16 03:09:05405}
406
407bool MessageLoop::DoIdleWork() {
408 if (ProcessNextDelayedNonNestableTask())
409 return true;
410
411 if (state_->quit_received)
412 pump_->Quit();
413
414 return false;
415}
416
417//------------------------------------------------------------------------------
418// MessageLoop::AutoRunState
419
420MessageLoop::AutoRunState::AutoRunState(MessageLoop* loop) : loop_(loop) {
421 // Make the loop reference us.
422 previous_state_ = loop_->state_;
423 if (previous_state_) {
424 run_depth = previous_state_->run_depth + 1;
[email protected]ea15e982008-08-15 07:31:20425 } else {
[email protected]fc7fb6e2008-08-16 03:09:05426 run_depth = 1;
[email protected]ea15e982008-08-15 07:31:20427 }
[email protected]fc7fb6e2008-08-16 03:09:05428 loop_->state_ = this;
429
430 // Initialize the other fields:
431 quit_received = false;
432#if defined(OS_WIN)
433 dispatcher = NULL;
434#endif
435}
436
437MessageLoop::AutoRunState::~AutoRunState() {
438 loop_->state_ = previous_state_;
[email protected]a5b94a92008-08-12 23:25:43439}
440
initial.commitd7cae122008-07-26 21:49:38441//------------------------------------------------------------------------------
[email protected]752578562008-09-07 08:08:29442// MessageLoop::PendingTask
initial.commitd7cae122008-07-26 21:49:38443
[email protected]752578562008-09-07 08:08:29444bool MessageLoop::PendingTask::operator<(const PendingTask& other) const {
445 // Since the top of a priority queue is defined as the "greatest" element, we
446 // need to invert the comparison here. We want the smaller time to be at the
447 // top of the heap.
initial.commitd7cae122008-07-26 21:49:38448
[email protected]752578562008-09-07 08:08:29449 if (delayed_run_time < other.delayed_run_time)
450 return false;
initial.commitd7cae122008-07-26 21:49:38451
[email protected]752578562008-09-07 08:08:29452 if (delayed_run_time > other.delayed_run_time)
453 return true;
initial.commitd7cae122008-07-26 21:49:38454
[email protected]752578562008-09-07 08:08:29455 // If the times happen to match, then we use the sequence number to decide.
456 // Compare the difference to support integer roll-over.
457 return (sequence_num - other.sequence_num) > 0;
initial.commitd7cae122008-07-26 21:49:38458}
459
460//------------------------------------------------------------------------------
461// Method and data for histogramming events and actions taken by each instance
462// on each thread.
463
464// static
465bool MessageLoop::enable_histogrammer_ = false;
466
467// static
468void MessageLoop::EnableHistogrammer(bool enable) {
469 enable_histogrammer_ = enable;
470}
471
472void MessageLoop::StartHistogrammer() {
473 if (enable_histogrammer_ && !message_histogram_.get()
474 && StatisticsRecorder::WasStarted()) {
[email protected]fc7fb6e2008-08-16 03:09:05475 DCHECK(!thread_name_.empty());
initial.commitd7cae122008-07-26 21:49:38476 message_histogram_.reset(new LinearHistogram(
477 ASCIIToWide("MsgLoop:" + thread_name_).c_str(),
478 kLeastNonZeroMessageId,
479 kMaxMessageId,
480 kNumberOfDistinctMessagesDisplayed));
481 message_histogram_->SetFlags(message_histogram_->kHexRangePrintingFlag);
482 message_histogram_->SetRangeDescriptions(event_descriptions_);
483 }
484}
485
486void MessageLoop::HistogramEvent(int event) {
487 if (message_histogram_.get())
488 message_histogram_->Add(event);
489}
490
initial.commitd7cae122008-07-26 21:49:38491// Provide a macro that takes an expression (such as a constant, or macro
492// constant) and creates a pair to initalize an array of pairs. In this case,
493// our pair consists of the expressions value, and the "stringized" version
494// of the expression (i.e., the exrpression put in quotes). For example, if
495// we have:
496// #define FOO 2
497// #define BAR 5
498// then the following:
499// VALUE_TO_NUMBER_AND_NAME(FOO + BAR)
500// will expand to:
501// {7, "FOO + BAR"}
502// We use the resulting array as an argument to our histogram, which reads the
503// number as a bucket identifier, and proceeds to use the corresponding name
504// in the pair (i.e., the quoted string) when printing out a histogram.
505#define VALUE_TO_NUMBER_AND_NAME(name) {name, #name},
506
initial.commitd7cae122008-07-26 21:49:38507// static
508const LinearHistogram::DescriptionPair MessageLoop::event_descriptions_[] = {
initial.commitd7cae122008-07-26 21:49:38509 // Provide some pretty print capability in our histogram for our internal
510 // messages.
511
initial.commitd7cae122008-07-26 21:49:38512 // A few events we handle (kindred to messages), and used to profile actions.
513 VALUE_TO_NUMBER_AND_NAME(kTaskRunEvent)
initial.commitd7cae122008-07-26 21:49:38514 VALUE_TO_NUMBER_AND_NAME(kTimerEvent)
515
516 {-1, NULL} // The list must be null terminated, per API to histogram.
517};
license.botbf09a502008-08-24 00:55:55518
[email protected]4d9bdfaf2008-08-26 05:53:57519//------------------------------------------------------------------------------
520// MessageLoopForUI
521
522#if defined(OS_WIN)
523
524void MessageLoopForUI::Run(Dispatcher* dispatcher) {
525 AutoRunState save_state(this);
526 state_->dispatcher = dispatcher;
527 RunHandler();
528}
529
530void MessageLoopForUI::AddObserver(Observer* observer) {
531 pump_win()->AddObserver(observer);
532}
533
534void MessageLoopForUI::RemoveObserver(Observer* observer) {
535 pump_win()->RemoveObserver(observer);
536}
537
538void MessageLoopForUI::WillProcessMessage(const MSG& message) {
539 pump_win()->WillProcessMessage(message);
540}
541void MessageLoopForUI::DidProcessMessage(const MSG& message) {
542 pump_win()->DidProcessMessage(message);
543}
544void MessageLoopForUI::PumpOutPendingPaintMessages() {
545 pump_win()->PumpOutPendingPaintMessages();
546}
547
548#endif // defined(OS_WIN)
549
550//------------------------------------------------------------------------------
551// MessageLoopForIO
552
553#if defined(OS_WIN)
554
555void MessageLoopForIO::WatchObject(HANDLE object, Watcher* watcher) {
556 pump_win()->WatchObject(object, watcher);
557}
558
559#endif // defined(OS_WIN)