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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 // Can only be called from the thread that owns the MessageLoop. | 384 // Can only be called from the thread that owns the MessageLoop. |
385 bool is_running() const; | 385 bool is_running() const; |
386 | 386 |
387 // Returns true if the message loop has high resolution timers enabled. | 387 // Returns true if the message loop has high resolution timers enabled. |
388 // Provided for testing. | 388 // Provided for testing. |
389 bool HasHighResolutionTasks(); | 389 bool HasHighResolutionTasks(); |
390 | 390 |
391 // Returns true if the message loop is "idle". Provided for testing. | 391 // Returns true if the message loop is "idle". Provided for testing. |
392 bool IsIdleForTesting(); | 392 bool IsIdleForTesting(); |
393 | 393 |
| 394 // Wakes up the message pump. Can be called on any thread. The caller is |
| 395 // responsible for synchronizing ScheduleWork() calls. |
| 396 void ScheduleWork(bool was_empty); |
| 397 |
| 398 // Returns the TaskAnnotator which is used to add debug information to posted |
| 399 // tasks. |
| 400 debug::TaskAnnotator* task_annotator() { return &task_annotator_; } |
| 401 |
| 402 // Runs the specified PendingTask. |
| 403 void RunTask(const PendingTask& pending_task); |
| 404 |
394 //---------------------------------------------------------------------------- | 405 //---------------------------------------------------------------------------- |
395 protected: | 406 protected: |
396 scoped_ptr<MessagePump> pump_; | 407 scoped_ptr<MessagePump> pump_; |
397 | 408 |
398 private: | 409 private: |
399 friend class internal::IncomingTaskQueue; | |
400 friend class RunLoop; | 410 friend class RunLoop; |
401 | 411 |
402 // Configures various members for the two constructors. | 412 // Configures various members for the two constructors. |
403 void Init(); | 413 void Init(); |
404 | 414 |
405 // Invokes the actual run loop using the message pump. | 415 // Invokes the actual run loop using the message pump. |
406 void RunHandler(); | 416 void RunHandler(); |
407 | 417 |
408 // Called to process any delayed non-nestable tasks. | 418 // Called to process any delayed non-nestable tasks. |
409 bool ProcessNextDelayedNonNestableTask(); | 419 bool ProcessNextDelayedNonNestableTask(); |
410 | 420 |
411 // Runs the specified PendingTask. | |
412 void RunTask(const PendingTask& pending_task); | |
413 | |
414 // Calls RunTask or queues the pending_task on the deferred task list if it | 421 // Calls RunTask or queues the pending_task on the deferred task list if it |
415 // cannot be run right now. Returns true if the task was run. | 422 // cannot be run right now. Returns true if the task was run. |
416 bool DeferOrRunPendingTask(const PendingTask& pending_task); | 423 bool DeferOrRunPendingTask(const PendingTask& pending_task); |
417 | 424 |
418 // Adds the pending task to delayed_work_queue_. | 425 // Adds the pending task to delayed_work_queue_. |
419 void AddToDelayedWorkQueue(const PendingTask& pending_task); | 426 void AddToDelayedWorkQueue(const PendingTask& pending_task); |
420 | 427 |
421 // Delete tasks that haven't run yet without running them. Used in the | 428 // Delete tasks that haven't run yet without running them. Used in the |
422 // destructor to make sure all the task's destructors get called. Returns | 429 // destructor to make sure all the task's destructors get called. Returns |
423 // true if some work was done. | 430 // true if some work was done. |
424 bool DeletePendingTasks(); | 431 bool DeletePendingTasks(); |
425 | 432 |
426 // Returns the TaskAnnotator which is used to add debug information to posted | |
427 // tasks. | |
428 debug::TaskAnnotator* task_annotator() { return &task_annotator_; } | |
429 | |
430 // Loads tasks from the incoming queue to |work_queue_| if the latter is | 433 // Loads tasks from the incoming queue to |work_queue_| if the latter is |
431 // empty. | 434 // empty. |
432 void ReloadWorkQueue(); | 435 void ReloadWorkQueue(); |
433 | 436 |
434 // Wakes up the message pump. Can be called on any thread. The caller is | |
435 // responsible for synchronizing ScheduleWork() calls. | |
436 void ScheduleWork(bool was_empty); | |
437 | |
438 // Start recording histogram info about events and action IF it was enabled | 437 // Start recording histogram info about events and action IF it was enabled |
439 // and IF the statistics recorder can accept a registration of our histogram. | 438 // and IF the statistics recorder can accept a registration of our histogram. |
440 void StartHistogrammer(); | 439 void StartHistogrammer(); |
441 | 440 |
442 // Add occurrence of event to our histogram, so that we can see what is being | 441 // Add occurrence of event to our histogram, so that we can see what is being |
443 // done in a specific MessageLoop instance (i.e., specific thread). | 442 // done in a specific MessageLoop instance (i.e., specific thread). |
444 // If message_histogram_ is NULL, this is a no-op. | 443 // If message_histogram_ is NULL, this is a no-op. |
445 void HistogramEvent(int event); | 444 void HistogramEvent(int event); |
446 | 445 |
447 // MessagePump::Delegate methods: | 446 // MessagePump::Delegate methods: |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 | 649 |
651 // 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 |
652 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 651 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
653 // 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. |
654 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 653 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
655 MessageLoopForIO_should_not_have_extra_member_variables); | 654 MessageLoopForIO_should_not_have_extra_member_variables); |
656 | 655 |
657 } // namespace base | 656 } // namespace base |
658 | 657 |
659 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 658 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
OLD | NEW |