OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 public: | 334 public: |
335 explicit AutoRunState(MessageLoop* loop); | 335 explicit AutoRunState(MessageLoop* loop); |
336 ~AutoRunState(); | 336 ~AutoRunState(); |
337 private: | 337 private: |
338 MessageLoop* loop_; | 338 MessageLoop* loop_; |
339 RunState* previous_state_; | 339 RunState* previous_state_; |
340 }; | 340 }; |
341 | 341 |
342 // This structure is copied around by value. | 342 // This structure is copied around by value. |
343 struct PendingTask { | 343 struct PendingTask { |
344 Task* task; // The task to run. | 344 Task* task; // The task to run. |
345 base::Time delayed_run_time; // The time when the task should be run. | 345 base::TimeTicks delayed_run_time; // The time when the task should be run. |
346 int sequence_num; // Used to facilitate sorting by run time. | 346 int sequence_num; // Secondary sort key for run time. |
347 bool nestable; // True if OK to dispatch from a nested loop. | 347 bool nestable; // OK to dispatch from a nested loop. |
348 | 348 |
349 PendingTask(Task* task, bool nestable) | 349 PendingTask(Task* task, bool nestable) |
350 : task(task), sequence_num(0), nestable(nestable) { | 350 : task(task), sequence_num(0), nestable(nestable) { |
351 } | 351 } |
352 | 352 |
353 // Used to support sorting. | 353 // Used to support sorting. |
354 bool operator<(const PendingTask& other) const; | 354 bool operator<(const PendingTask& other) const; |
355 }; | 355 }; |
356 | 356 |
357 class TaskQueue : public std::queue<PendingTask> { | 357 class TaskQueue : public std::queue<PendingTask> { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 // destructor to make sure all the task's destructors get called. Returns | 422 // destructor to make sure all the task's destructors get called. Returns |
423 // true if some work was done. | 423 // true if some work was done. |
424 bool DeletePendingTasks(); | 424 bool DeletePendingTasks(); |
425 | 425 |
426 // Post a task to our incomming queue. | 426 // Post a task to our incomming queue. |
427 void PostTask_Helper(const tracked_objects::Location& from_here, Task* task, | 427 void PostTask_Helper(const tracked_objects::Location& from_here, Task* task, |
428 int64 delay_ms, bool nestable); | 428 int64 delay_ms, bool nestable); |
429 | 429 |
430 // base::MessagePump::Delegate methods: | 430 // base::MessagePump::Delegate methods: |
431 virtual bool DoWork(); | 431 virtual bool DoWork(); |
432 virtual bool DoDelayedWork(base::Time* next_delayed_work_time); | 432 virtual bool DoDelayedWork(base::TimeTicks* next_delayed_work_time); |
433 virtual bool DoIdleWork(); | 433 virtual bool DoIdleWork(); |
434 | 434 |
435 // Start recording histogram info about events and action IF it was enabled | 435 // Start recording histogram info about events and action IF it was enabled |
436 // and IF the statistics recorder can accept a registration of our histogram. | 436 // and IF the statistics recorder can accept a registration of our histogram. |
437 void StartHistogrammer(); | 437 void StartHistogrammer(); |
438 | 438 |
439 // Add occurence of event to our histogram, so that we can see what is being | 439 // Add occurence of event to our histogram, so that we can see what is being |
440 // done in a specific MessageLoop instance (i.e., specific thread). | 440 // done in a specific MessageLoop instance (i.e., specific thread). |
441 // If message_histogram_ is NULL, this is a no-op. | 441 // If message_histogram_ is NULL, this is a no-op. |
442 void HistogramEvent(int event); | 442 void HistogramEvent(int event); |
443 | 443 |
444 Type type_; | 444 Type type_; |
445 | 445 |
446 // A list of tasks that need to be processed by this instance. Note that | 446 // A list of tasks that need to be processed by this instance. Note that |
447 // this queue is only accessed (push/pop) by our current thread. | 447 // this queue is only accessed (push/pop) by our current thread. |
448 TaskQueue work_queue_; | 448 TaskQueue work_queue_; |
449 | 449 |
450 // Contains delayed tasks, sorted by their 'delayed_run_time' property. | 450 // Contains delayed tasks, sorted by their 'delayed_run_time' property. |
451 DelayedTaskQueue delayed_work_queue_; | 451 DelayedTaskQueue delayed_work_queue_; |
452 | 452 |
453 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. | 453 // A recent snapshot of Time::Now(), used to check delayed_work_queue_. |
454 base::Time recent_time_; | 454 base::TimeTicks recent_time_; |
455 | 455 |
456 // A queue of non-nestable tasks that we had to defer because when it came | 456 // A queue of non-nestable tasks that we had to defer because when it came |
457 // time to execute them we were in a nested message loop. They will execute | 457 // time to execute them we were in a nested message loop. They will execute |
458 // once we're out of nested message loops. | 458 // once we're out of nested message loops. |
459 TaskQueue deferred_non_nestable_work_queue_; | 459 TaskQueue deferred_non_nestable_work_queue_; |
460 | 460 |
461 scoped_refptr<base::MessagePump> pump_; | 461 scoped_refptr<base::MessagePump> pump_; |
462 | 462 |
463 ObserverList<DestructionObserver> destruction_observers_; | 463 ObserverList<DestructionObserver> destruction_observers_; |
464 | 464 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 #endif // defined(OS_POSIX) | 609 #endif // defined(OS_POSIX) |
610 }; | 610 }; |
611 | 611 |
612 // Do not add any member variables to MessageLoopForIO! This is important b/c | 612 // Do not add any member variables to MessageLoopForIO! This is important b/c |
613 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 613 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
614 // data that you need should be stored on the MessageLoop's pump_ instance. | 614 // data that you need should be stored on the MessageLoop's pump_ instance. |
615 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 615 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
616 MessageLoopForIO_should_not_have_extra_member_variables); | 616 MessageLoopForIO_should_not_have_extra_member_variables); |
617 | 617 |
618 #endif // BASE_MESSAGE_LOOP_H_ | 618 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |