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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 virtual bool DoWork() OVERRIDE; | 448 virtual bool DoWork() OVERRIDE; |
453 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE; | 449 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE; |
454 virtual bool DoIdleWork() OVERRIDE; | 450 virtual bool DoIdleWork() OVERRIDE; |
455 | 451 |
456 const Type type_; | 452 const Type type_; |
457 | 453 |
458 // A list of tasks that need to be processed by this instance. Note that | 454 // A list of tasks that need to be processed by this instance. Note that |
459 // this queue is only accessed (push/pop) by our current thread. | 455 // this queue is only accessed (push/pop) by our current thread. |
460 TaskQueue work_queue_; | 456 TaskQueue work_queue_; |
461 | 457 |
| 458 // How many high resolution tasks are in the pending task queue. This value |
| 459 // increases by N every time we call ReloadWorkQueue() and decreases by 1 |
| 460 // every time we call RunTask() if the task needs a high resolution timer. |
| 461 int pending_high_res_tasks_; |
| 462 // Tracks if we have requested high resolution timers. Its only use is to |
| 463 // turn off the high resolution timer upon loop destruction. |
| 464 bool in_high_res_mode_; |
| 465 |
462 // Contains delayed tasks, sorted by their 'delayed_run_time' property. | 466 // Contains delayed tasks, sorted by their 'delayed_run_time' property. |
463 DelayedTaskQueue delayed_work_queue_; | 467 DelayedTaskQueue delayed_work_queue_; |
464 | 468 |
465 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. | 469 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. |
466 TimeTicks recent_time_; | 470 TimeTicks recent_time_; |
467 | 471 |
468 // A queue of non-nestable tasks that we had to defer because when it came | 472 // A queue of non-nestable tasks that we had to defer because when it came |
469 // time to execute them we were in a nested message loop. They will execute | 473 // time to execute them we were in a nested message loop. They will execute |
470 // once we're out of nested message loops. | 474 // once we're out of nested message loops. |
471 TaskQueue deferred_non_nestable_work_queue_; | 475 TaskQueue deferred_non_nestable_work_queue_; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 | 650 |
647 // Do not add any member variables to MessageLoopForIO! This is important b/c | 651 // Do not add any member variables to MessageLoopForIO! This is important b/c |
648 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 652 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
649 // data that you need should be stored on the MessageLoop's pump_ instance. | 653 // data that you need should be stored on the MessageLoop's pump_ instance. |
650 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 654 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
651 MessageLoopForIO_should_not_have_extra_member_variables); | 655 MessageLoopForIO_should_not_have_extra_member_variables); |
652 | 656 |
653 } // namespace base | 657 } // namespace base |
654 | 658 |
655 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 659 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
OLD | NEW |