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 |
374 #if defined(OS_WIN) | 378 #if defined(OS_WIN) |
375 void set_os_modal_loop(bool os_modal_loop) { | 379 void set_os_modal_loop(bool os_modal_loop) { |
376 os_modal_loop_ = os_modal_loop; | 380 os_modal_loop_ = os_modal_loop; |
377 } | 381 } |
378 | 382 |
379 bool os_modal_loop() const { | 383 bool os_modal_loop() const { |
380 return os_modal_loop_; | 384 return os_modal_loop_; |
381 } | 385 } |
382 #endif // OS_WIN | 386 #endif // OS_WIN |
383 | 387 |
384 // Can only be called from the thread that owns the MessageLoop. | 388 // Can only be called from the thread that owns the MessageLoop. |
385 bool is_running() const; | 389 bool is_running() const; |
386 | 390 |
387 // Returns true if the message loop has high resolution timers enabled. | 391 // Returns true if the message loop has high resolution timers enabled. |
388 // Provided for testing. | 392 // Provided for testing. |
389 bool HasHighResolutionTasks(); | 393 bool IsHighResolutionTimerEnabledForTesting(); |
390 | 394 |
391 // Returns true if the message loop is "idle". Provided for testing. | 395 // Returns true if the message loop is "idle". Provided for testing. |
392 bool IsIdleForTesting(); | 396 bool IsIdleForTesting(); |
393 | 397 |
394 //---------------------------------------------------------------------------- | 398 //---------------------------------------------------------------------------- |
395 protected: | 399 protected: |
396 scoped_ptr<MessagePump> pump_; | 400 scoped_ptr<MessagePump> pump_; |
397 | 401 |
398 private: | 402 private: |
399 friend class internal::IncomingTaskQueue; | 403 friend class internal::IncomingTaskQueue; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 virtual bool DoWork() OVERRIDE; | 453 virtual bool DoWork() OVERRIDE; |
450 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE; | 454 virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE; |
451 virtual bool DoIdleWork() OVERRIDE; | 455 virtual bool DoIdleWork() OVERRIDE; |
452 | 456 |
453 const Type type_; | 457 const Type type_; |
454 | 458 |
455 // A list of tasks that need to be processed by this instance. Note that | 459 // A list of tasks that need to be processed by this instance. Note that |
456 // this queue is only accessed (push/pop) by our current thread. | 460 // this queue is only accessed (push/pop) by our current thread. |
457 TaskQueue work_queue_; | 461 TaskQueue work_queue_; |
458 | 462 |
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 | |
467 // Contains delayed tasks, sorted by their 'delayed_run_time' property. | 463 // Contains delayed tasks, sorted by their 'delayed_run_time' property. |
468 DelayedTaskQueue delayed_work_queue_; | 464 DelayedTaskQueue delayed_work_queue_; |
469 | 465 |
470 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. | 466 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. |
471 TimeTicks recent_time_; | 467 TimeTicks recent_time_; |
472 | 468 |
473 // A queue of non-nestable tasks that we had to defer because when it came | 469 // A queue of non-nestable tasks that we had to defer because when it came |
474 // time to execute them we were in a nested message loop. They will execute | 470 // time to execute them we were in a nested message loop. They will execute |
475 // once we're out of nested message loops. | 471 // once we're out of nested message loops. |
476 TaskQueue deferred_non_nestable_work_queue_; | 472 TaskQueue deferred_non_nestable_work_queue_; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 | 653 |
658 // Do not add any member variables to MessageLoopForIO! This is important b/c | 654 // Do not add any member variables to MessageLoopForIO! This is important b/c |
659 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 655 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
660 // data that you need should be stored on the MessageLoop's pump_ instance. | 656 // data that you need should be stored on the MessageLoop's pump_ instance. |
661 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 657 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
662 MessageLoopForIO_should_not_have_extra_member_variables); | 658 MessageLoopForIO_should_not_have_extra_member_variables); |
663 | 659 |
664 } // namespace base | 660 } // namespace base |
665 | 661 |
666 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 662 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
OLD | NEW |