| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // TYPE_CUSTOM | 99 // TYPE_CUSTOM |
| 100 // MessagePump was supplied to constructor. | 100 // MessagePump was supplied to constructor. |
| 101 // | 101 // |
| 102 enum Type { | 102 enum Type { |
| 103 TYPE_DEFAULT, | 103 TYPE_DEFAULT, |
| 104 TYPE_UI, | 104 TYPE_UI, |
| 105 TYPE_CUSTOM, | 105 TYPE_CUSTOM, |
| 106 TYPE_IO, | 106 TYPE_IO, |
| 107 #if defined(OS_ANDROID) | 107 #if defined(OS_ANDROID) |
| 108 TYPE_JAVA, | 108 TYPE_JAVA, |
| 109 #endif // defined(OS_ANDROID) | 109 #endif // defined(OS_ANDROID) |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 // Normally, it is not necessary to instantiate a MessageLoop. Instead, it | 112 // Normally, it is not necessary to instantiate a MessageLoop. Instead, it |
| 113 // is typical to make use of the current thread's MessageLoop instance. | 113 // is typical to make use of the current thread's MessageLoop instance. |
| 114 explicit MessageLoop(Type type = TYPE_DEFAULT); | 114 explicit MessageLoop(Type type = TYPE_DEFAULT); |
| 115 // Creates a TYPE_CUSTOM MessageLoop with the supplied MessagePump, which must | 115 // Creates a TYPE_CUSTOM MessageLoop with the supplied MessagePump, which must |
| 116 // be non-NULL. | 116 // be non-NULL. |
| 117 explicit MessageLoop(scoped_ptr<base::MessagePump> pump); | 117 explicit MessageLoop(scoped_ptr<base::MessagePump> pump); |
| 118 ~MessageLoop() override; | 118 ~MessageLoop() override; |
| 119 | 119 |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 bool DoWork() override; | 445 bool DoWork() override; |
| 446 bool DoDelayedWork(TimeTicks* next_delayed_work_time) override; | 446 bool DoDelayedWork(TimeTicks* next_delayed_work_time) override; |
| 447 bool DoIdleWork() override; | 447 bool DoIdleWork() override; |
| 448 | 448 |
| 449 const Type type_; | 449 const Type type_; |
| 450 | 450 |
| 451 // A list of tasks that need to be processed by this instance. Note that | 451 // A list of tasks that need to be processed by this instance. Note that |
| 452 // this queue is only accessed (push/pop) by our current thread. | 452 // this queue is only accessed (push/pop) by our current thread. |
| 453 TaskQueue work_queue_; | 453 TaskQueue work_queue_; |
| 454 | 454 |
| 455 #if defined(OS_WIN) |
| 455 // How many high resolution tasks are in the pending task queue. This value | 456 // How many high resolution tasks are in the pending task queue. This value |
| 456 // increases by N every time we call ReloadWorkQueue() and decreases by 1 | 457 // increases by N every time we call ReloadWorkQueue() and decreases by 1 |
| 457 // every time we call RunTask() if the task needs a high resolution timer. | 458 // every time we call RunTask() if the task needs a high resolution timer. |
| 458 int pending_high_res_tasks_; | 459 int pending_high_res_tasks_; |
| 459 // Tracks if we have requested high resolution timers. Its only use is to | 460 // Tracks if we have requested high resolution timers. Its only use is to |
| 460 // turn off the high resolution timer upon loop destruction. | 461 // turn off the high resolution timer upon loop destruction. |
| 461 bool in_high_res_mode_; | 462 bool in_high_res_mode_; |
| 463 #endif |
| 462 | 464 |
| 463 // Contains delayed tasks, sorted by their 'delayed_run_time' property. | 465 // Contains delayed tasks, sorted by their 'delayed_run_time' property. |
| 464 DelayedTaskQueue delayed_work_queue_; | 466 DelayedTaskQueue delayed_work_queue_; |
| 465 | 467 |
| 466 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. | 468 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. |
| 467 TimeTicks recent_time_; | 469 TimeTicks recent_time_; |
| 468 | 470 |
| 469 // A queue of non-nestable tasks that we had to defer because when it came | 471 // 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 | 472 // time to execute them we were in a nested message loop. They will execute |
| 471 // once we're out of nested message loops. | 473 // once we're out of nested message loops. |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 #if defined(OS_WIN) | 634 #if defined(OS_WIN) |
| 633 // Please see MessagePumpWin for definitions of these methods. | 635 // Please see MessagePumpWin for definitions of these methods. |
| 634 void RegisterIOHandler(HANDLE file, IOHandler* handler); | 636 void RegisterIOHandler(HANDLE file, IOHandler* handler); |
| 635 bool RegisterJobObject(HANDLE job, IOHandler* handler); | 637 bool RegisterJobObject(HANDLE job, IOHandler* handler); |
| 636 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter); | 638 bool WaitForIOCompletion(DWORD timeout, IOHandler* filter); |
| 637 #elif defined(OS_POSIX) | 639 #elif defined(OS_POSIX) |
| 638 // Please see MessagePumpIOSForIO/MessagePumpLibevent for definition. | 640 // Please see MessagePumpIOSForIO/MessagePumpLibevent for definition. |
| 639 bool WatchFileDescriptor(int fd, | 641 bool WatchFileDescriptor(int fd, |
| 640 bool persistent, | 642 bool persistent, |
| 641 Mode mode, | 643 Mode mode, |
| 642 FileDescriptorWatcher *controller, | 644 FileDescriptorWatcher* controller, |
| 643 Watcher *delegate); | 645 Watcher* delegate); |
| 644 #endif // defined(OS_IOS) || defined(OS_POSIX) | 646 #endif // defined(OS_IOS) || defined(OS_POSIX) |
| 645 #endif // !defined(OS_NACL_SFI) | 647 #endif // !defined(OS_NACL_SFI) |
| 646 }; | 648 }; |
| 647 | 649 |
| 648 // Do not add any member variables to MessageLoopForIO! This is important b/c | 650 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 649 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 651 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 650 // data that you need should be stored on the MessageLoop's pump_ instance. | 652 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 651 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 653 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 652 MessageLoopForIO_should_not_have_extra_member_variables); | 654 MessageLoopForIO_should_not_have_extra_member_variables); |
| 653 | 655 |
| 654 } // namespace base | 656 } // namespace base |
| 655 | 657 |
| 656 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 658 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| OLD | NEW |