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 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 364 |
365 protected: | 365 protected: |
366 virtual ~TaskObserver(); | 366 virtual ~TaskObserver(); |
367 }; | 367 }; |
368 | 368 |
369 // These functions can only be called on the same thread that |this| is | 369 // These functions can only be called on the same thread that |this| is |
370 // running on. | 370 // running on. |
371 void AddTaskObserver(TaskObserver* task_observer); | 371 void AddTaskObserver(TaskObserver* task_observer); |
372 void RemoveTaskObserver(TaskObserver* task_observer); | 372 void RemoveTaskObserver(TaskObserver* task_observer); |
373 | 373 |
374 // When we go into high resolution timer mode, we will stay in hi-res mode | |
375 // for at least 1s. | |
376 static const int kHighResolutionTimerModeLeaseTimeMs = 1000; | |
377 | |
378 #if defined(OS_WIN) | 374 #if defined(OS_WIN) |
379 void set_os_modal_loop(bool os_modal_loop) { | 375 void set_os_modal_loop(bool os_modal_loop) { |
380 os_modal_loop_ = os_modal_loop; | 376 os_modal_loop_ = os_modal_loop; |
381 } | 377 } |
382 | 378 |
383 bool os_modal_loop() const { | 379 bool os_modal_loop() const { |
384 return os_modal_loop_; | 380 return os_modal_loop_; |
385 } | 381 } |
386 #endif // OS_WIN | 382 #endif // OS_WIN |
387 | 383 |
388 // Can only be called from the thread that owns the MessageLoop. | 384 // Can only be called from the thread that owns the MessageLoop. |
389 bool is_running() const; | 385 bool is_running() const; |
390 | 386 |
391 // Returns true if the message loop has high resolution timers enabled. | 387 // Returns true if the message loop has high resolution timers enabled. |
392 // Provided for testing. | 388 // Provided for testing. |
393 bool IsHighResolutionTimerEnabledForTesting(); | 389 bool HasHighResolutionTasks(); |
394 | 390 |
395 // Returns true if the message loop is "idle". Provided for testing. | 391 // Returns true if the message loop is "idle". Provided for testing. |
396 bool IsIdleForTesting(); | 392 bool IsIdleForTesting(); |
397 | 393 |
398 //---------------------------------------------------------------------------- | 394 //---------------------------------------------------------------------------- |
399 protected: | 395 protected: |
400 scoped_ptr<MessagePump> pump_; | 396 scoped_ptr<MessagePump> pump_; |
401 | 397 |
402 private: | 398 private: |
403 friend class internal::IncomingTaskQueue; | 399 friend class internal::IncomingTaskQueue; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 virtual bool DoWork() OVERRIDE; | 449 virtual bool DoWork() OVERRIDE; |
454 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE; | 450 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE; |
455 virtual bool DoIdleWork() OVERRIDE; | 451 virtual bool DoIdleWork() OVERRIDE; |
456 | 452 |
457 const Type type_; | 453 const Type type_; |
458 | 454 |
459 // A list of tasks that need to be processed by this instance. Note that | 455 // A list of tasks that need to be processed by this instance. Note that |
460 // this queue is only accessed (push/pop) by our current thread. | 456 // this queue is only accessed (push/pop) by our current thread. |
461 TaskQueue work_queue_; | 457 TaskQueue work_queue_; |
462 | 458 |
| 459 // How many high resolution tasks are in the pending task queue. This value |
| 460 // increases by N every time we call ReloadWorkQueue() and decreases by 1 |
| 461 // every time we call RunTask() if the task needs a high resolution timer. |
| 462 int pending_high_res_tasks_; |
| 463 // Tracks if we have requested high resolution timers. Its only use is to |
| 464 // turn off the high resolution timer upon loop destruction. |
| 465 bool in_high_res_mode_; |
| 466 |
463 // Contains delayed tasks, sorted by their 'delayed_run_time' property. | 467 // Contains delayed tasks, sorted by their 'delayed_run_time' property. |
464 DelayedTaskQueue delayed_work_queue_; | 468 DelayedTaskQueue delayed_work_queue_; |
465 | 469 |
466 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. | 470 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. |
467 TimeTicks recent_time_; | 471 TimeTicks recent_time_; |
468 | 472 |
469 // A queue of non-nestable tasks that we had to defer because when it came | 473 // A queue of non-nestable tasks that we had to defer because when it came |
470 // time to execute them we were in a nested message loop. They will execute | 474 // time to execute them we were in a nested message loop. They will execute |
471 // once we're out of nested message loops. | 475 // once we're out of nested message loops. |
472 TaskQueue deferred_non_nestable_work_queue_; | 476 TaskQueue deferred_non_nestable_work_queue_; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 | 657 |
654 // Do not add any member variables to MessageLoopForIO! This is important b/c | 658 // Do not add any member variables to MessageLoopForIO! This is important b/c |
655 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 659 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
656 // data that you need should be stored on the MessageLoop's pump_ instance. | 660 // data that you need should be stored on the MessageLoop's pump_ instance. |
657 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 661 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
658 MessageLoopForIO_should_not_have_extra_member_variables); | 662 MessageLoopForIO_should_not_have_extra_member_variables); |
659 | 663 |
660 } // namespace base | 664 } // namespace base |
661 | 665 |
662 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 666 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
OLD | NEW |