OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // 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 | 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 #ifndef BASE_MESSAGE_LOOP_H_ | 5 #ifndef BASE_MESSAGE_LOOP_H_ |
6 #define BASE_MESSAGE_LOOP_H_ | 6 #define BASE_MESSAGE_LOOP_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 void RemoveTaskObserver(TaskObserver* task_observer); | 280 void RemoveTaskObserver(TaskObserver* task_observer); |
281 | 281 |
282 #if defined(OS_WIN) | 282 #if defined(OS_WIN) |
283 typedef base::MessagePumpWin::Dispatcher Dispatcher; | 283 typedef base::MessagePumpWin::Dispatcher Dispatcher; |
284 typedef base::MessagePumpForUI::Observer Observer; | 284 typedef base::MessagePumpForUI::Observer Observer; |
285 #elif !defined(OS_MACOSX) | 285 #elif !defined(OS_MACOSX) |
286 typedef base::MessagePumpForUI::Dispatcher Dispatcher; | 286 typedef base::MessagePumpForUI::Dispatcher Dispatcher; |
287 typedef base::MessagePumpForUI::Observer Observer; | 287 typedef base::MessagePumpForUI::Observer Observer; |
288 #endif | 288 #endif |
289 | 289 |
| 290 // Returns true if the message loop has high resolution timers enabled. |
| 291 // Provided for testing. |
| 292 bool high_resolution_timers_enabled() { |
| 293 #if defined(OS_WIN) |
| 294 return !high_resolution_timer_expiration_.is_null(); |
| 295 #else |
| 296 return true; |
| 297 #endif |
| 298 } |
| 299 |
| 300 // When we go into high resolution timer mode, we will stay in hi-res mode |
| 301 // for at least 1s. |
| 302 static const int kHighResolutionTimerModeLeaseTimeMs = 1000; |
| 303 |
290 //---------------------------------------------------------------------------- | 304 //---------------------------------------------------------------------------- |
291 protected: | 305 protected: |
292 struct RunState { | 306 struct RunState { |
293 // Used to count how many Run() invocations are on the stack. | 307 // Used to count how many Run() invocations are on the stack. |
294 int run_depth; | 308 int run_depth; |
295 | 309 |
296 // Used to record that Quit() was called, or that we should quit the pump | 310 // Used to record that Quit() was called, or that we should quit the pump |
297 // once it becomes idle. | 311 // once it becomes idle. |
298 bool quit_received; | 312 bool quit_received; |
299 | 313 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 // A null terminated list which creates an incoming_queue of tasks that are | 461 // A null terminated list which creates an incoming_queue of tasks that are |
448 // aquired under a mutex for processing on this instance's thread. These tasks | 462 // aquired under a mutex for processing on this instance's thread. These tasks |
449 // have not yet been sorted out into items for our work_queue_ vs items that | 463 // have not yet been sorted out into items for our work_queue_ vs items that |
450 // will be handled by the TimerManager. | 464 // will be handled by the TimerManager. |
451 TaskQueue incoming_queue_; | 465 TaskQueue incoming_queue_; |
452 // Protect access to incoming_queue_. | 466 // Protect access to incoming_queue_. |
453 Lock incoming_queue_lock_; | 467 Lock incoming_queue_lock_; |
454 | 468 |
455 RunState* state_; | 469 RunState* state_; |
456 | 470 |
| 471 #if defined(OS_WIN) |
| 472 base::TimeTicks high_resolution_timer_expiration_; |
| 473 #endif |
| 474 |
457 // The next sequence number to use for delayed tasks. | 475 // The next sequence number to use for delayed tasks. |
458 int next_sequence_num_; | 476 int next_sequence_num_; |
459 | 477 |
460 ObserverList<TaskObserver> task_observers_; | 478 ObserverList<TaskObserver> task_observers_; |
461 | 479 |
462 DISALLOW_COPY_AND_ASSIGN(MessageLoop); | 480 DISALLOW_COPY_AND_ASSIGN(MessageLoop); |
463 }; | 481 }; |
464 | 482 |
465 //----------------------------------------------------------------------------- | 483 //----------------------------------------------------------------------------- |
466 // MessageLoopForUI extends MessageLoop with methods that are particular to a | 484 // MessageLoopForUI extends MessageLoop with methods that are particular to a |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 #endif // defined(OS_POSIX) | 595 #endif // defined(OS_POSIX) |
578 }; | 596 }; |
579 | 597 |
580 // Do not add any member variables to MessageLoopForIO! This is important b/c | 598 // Do not add any member variables to MessageLoopForIO! This is important b/c |
581 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 599 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
582 // data that you need should be stored on the MessageLoop's pump_ instance. | 600 // data that you need should be stored on the MessageLoop's pump_ instance. |
583 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 601 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
584 MessageLoopForIO_should_not_have_extra_member_variables); | 602 MessageLoopForIO_should_not_have_extra_member_variables); |
585 | 603 |
586 #endif // BASE_MESSAGE_LOOP_H_ | 604 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |