OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 bool os_modal_loop() const { | 371 bool os_modal_loop() const { |
372 return os_modal_loop_; | 372 return os_modal_loop_; |
373 } | 373 } |
374 #endif // OS_WIN | 374 #endif // OS_WIN |
375 | 375 |
376 // Can only be called from the thread that owns the MessageLoop. | 376 // Can only be called from the thread that owns the MessageLoop. |
377 bool is_running() const; | 377 bool is_running() const; |
378 | 378 |
379 //---------------------------------------------------------------------------- | 379 //---------------------------------------------------------------------------- |
380 protected: | 380 protected: |
381 // PendingTasks are sorted by their |delayed_run_time| property. | |
382 typedef std::priority_queue<base::PendingTask> DelayedTaskQueue; | |
383 | |
384 struct RunState { | 381 struct RunState { |
385 // Used to count how many Run() invocations are on the stack. | 382 // Used to count how many Run() invocations are on the stack. |
386 int run_depth; | 383 int run_depth; |
387 | 384 |
388 // Used to record that Quit() was called, or that we should quit the pump | 385 // Used to record that Quit() was called, or that we should quit the pump |
389 // once it becomes idle. | 386 // once it becomes idle. |
390 bool quit_received; | 387 bool quit_received; |
391 | 388 |
392 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 389 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
393 Dispatcher* dispatcher; | 390 Dispatcher* dispatcher; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 virtual bool DoDelayedWork(base::TimeTicks* next_delayed_work_time) OVERRIDE; | 481 virtual bool DoDelayedWork(base::TimeTicks* next_delayed_work_time) OVERRIDE; |
485 virtual bool DoIdleWork() OVERRIDE; | 482 virtual bool DoIdleWork() OVERRIDE; |
486 | 483 |
487 Type type_; | 484 Type type_; |
488 | 485 |
489 // A list of tasks that need to be processed by this instance. Note that | 486 // A list of tasks that need to be processed by this instance. Note that |
490 // this queue is only accessed (push/pop) by our current thread. | 487 // this queue is only accessed (push/pop) by our current thread. |
491 base::TaskQueue work_queue_; | 488 base::TaskQueue work_queue_; |
492 | 489 |
493 // Contains delayed tasks, sorted by their 'delayed_run_time' property. | 490 // Contains delayed tasks, sorted by their 'delayed_run_time' property. |
494 DelayedTaskQueue delayed_work_queue_; | 491 base::DelayedTaskQueue delayed_work_queue_; |
495 | 492 |
496 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. | 493 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. |
497 base::TimeTicks recent_time_; | 494 base::TimeTicks recent_time_; |
498 | 495 |
499 // A queue of non-nestable tasks that we had to defer because when it came | 496 // A queue of non-nestable tasks that we had to defer because when it came |
500 // time to execute them we were in a nested message loop. They will execute | 497 // time to execute them we were in a nested message loop. They will execute |
501 // once we're out of nested message loops. | 498 // once we're out of nested message loops. |
502 base::TaskQueue deferred_non_nestable_work_queue_; | 499 base::TaskQueue deferred_non_nestable_work_queue_; |
503 | 500 |
504 scoped_refptr<base::MessagePump> pump_; | 501 scoped_refptr<base::MessagePump> pump_; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 #endif // defined(OS_POSIX) | 666 #endif // defined(OS_POSIX) |
670 }; | 667 }; |
671 | 668 |
672 // Do not add any member variables to MessageLoopForIO! This is important b/c | 669 // Do not add any member variables to MessageLoopForIO! This is important b/c |
673 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 670 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
674 // data that you need should be stored on the MessageLoop's pump_ instance. | 671 // data that you need should be stored on the MessageLoop's pump_ instance. |
675 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 672 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
676 MessageLoopForIO_should_not_have_extra_member_variables); | 673 MessageLoopForIO_should_not_have_extra_member_variables); |
677 | 674 |
678 #endif // BASE_MESSAGE_LOOP_H_ | 675 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |