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 #include "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 incoming_task_queue_->ReloadWorkQueue(&work_queue_); | 518 incoming_task_queue_->ReloadWorkQueue(&work_queue_); |
519 } | 519 } |
520 | 520 |
521 void MessageLoop::ScheduleWork(bool was_empty) { | 521 void MessageLoop::ScheduleWork(bool was_empty) { |
522 // The Android UI message loop needs to get notified each time | 522 // The Android UI message loop needs to get notified each time |
523 // a task is added to the incoming queue. | 523 // a task is added to the incoming queue. |
524 if (was_empty || AlwaysNotifyPump(type_)) | 524 if (was_empty || AlwaysNotifyPump(type_)) |
525 pump_->ScheduleWork(); | 525 pump_->ScheduleWork(); |
526 } | 526 } |
527 | 527 |
| 528 void MessageLoop::ReloadAllWorkQueues() { |
| 529 ReloadWorkQueue(); |
| 530 } |
| 531 |
| 532 TaskQueue& MessageLoop::GetNextWorkQueue() { |
| 533 return work_queue_; |
| 534 } |
| 535 |
| 536 bool MessageLoop::HasWorkAvailable() const { |
| 537 return !work_queue_.empty(); |
| 538 } |
| 539 |
528 //------------------------------------------------------------------------------ | 540 //------------------------------------------------------------------------------ |
529 // Method and data for histogramming events and actions taken by each instance | 541 // Method and data for histogramming events and actions taken by each instance |
530 // on each thread. | 542 // on each thread. |
531 | 543 |
532 void MessageLoop::StartHistogrammer() { | 544 void MessageLoop::StartHistogrammer() { |
533 #if !defined(OS_NACL) // NaCl build has no metrics code. | 545 #if !defined(OS_NACL) // NaCl build has no metrics code. |
534 if (enable_histogrammer_ && !message_histogram_ | 546 if (enable_histogrammer_ && !message_histogram_ |
535 && StatisticsRecorder::IsActive()) { | 547 && StatisticsRecorder::IsActive()) { |
536 DCHECK(!thread_name_.empty()); | 548 DCHECK(!thread_name_.empty()); |
537 message_histogram_ = LinearHistogram::FactoryGetWithRangeDescription( | 549 message_histogram_ = LinearHistogram::FactoryGetWithRangeDescription( |
(...skipping 13 matching lines...) Expand all Loading... |
551 #endif | 563 #endif |
552 } | 564 } |
553 | 565 |
554 bool MessageLoop::DoWork() { | 566 bool MessageLoop::DoWork() { |
555 if (!nestable_tasks_allowed_) { | 567 if (!nestable_tasks_allowed_) { |
556 // Task can't be executed right now. | 568 // Task can't be executed right now. |
557 return false; | 569 return false; |
558 } | 570 } |
559 | 571 |
560 for (;;) { | 572 for (;;) { |
561 ReloadWorkQueue(); | 573 ReloadAllWorkQueues(); |
562 if (work_queue_.empty()) | 574 |
| 575 if (!HasWorkAvailable()) |
563 break; | 576 break; |
564 | 577 |
| 578 TaskQueue& current_work_queue = GetNextWorkQueue(); |
| 579 |
565 // Execute oldest task. | 580 // Execute oldest task. |
566 do { | 581 do { |
567 PendingTask pending_task = work_queue_.front(); | 582 PendingTask pending_task = current_work_queue.front(); |
568 work_queue_.pop(); | 583 current_work_queue.pop(); |
569 if (!pending_task.delayed_run_time.is_null()) { | 584 if (!pending_task.delayed_run_time.is_null()) { |
570 AddToDelayedWorkQueue(pending_task); | 585 AddToDelayedWorkQueue(pending_task); |
571 // If we changed the topmost task, then it is time to reschedule. | 586 // If we changed the topmost task, then it is time to reschedule. |
572 if (delayed_work_queue_.top().task.Equals(pending_task.task)) | 587 if (delayed_work_queue_.top().task.Equals(pending_task.task)) |
573 pump_->ScheduleDelayedWork(pending_task.delayed_run_time); | 588 pump_->ScheduleDelayedWork(pending_task.delayed_run_time); |
574 } else { | 589 } else { |
575 if (DeferOrRunPendingTask(pending_task)) | 590 if (DeferOrRunPendingTask(pending_task)) |
576 return true; | 591 return true; |
577 } | 592 } |
578 } while (!work_queue_.empty()); | 593 } while (!current_work_queue.empty()); |
579 } | 594 } |
580 | 595 |
581 // Nothing happened. | 596 // Nothing happened. |
582 return false; | 597 return false; |
583 } | 598 } |
584 | 599 |
585 bool MessageLoop::DoDelayedWork(TimeTicks* next_delayed_work_time) { | 600 bool MessageLoop::DoDelayedWork(TimeTicks* next_delayed_work_time) { |
586 if (!nestable_tasks_allowed_ || delayed_work_queue_.empty()) { | 601 if (!nestable_tasks_allowed_ || delayed_work_queue_.empty()) { |
587 recent_time_ = *next_delayed_work_time = TimeTicks(); | 602 recent_time_ = *next_delayed_work_time = TimeTicks(); |
588 return false; | 603 return false; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 fd, | 735 fd, |
721 persistent, | 736 persistent, |
722 mode, | 737 mode, |
723 controller, | 738 controller, |
724 delegate); | 739 delegate); |
725 } | 740 } |
726 | 741 |
727 #endif | 742 #endif |
728 | 743 |
729 } // namespace base | 744 } // namespace base |
OLD | NEW |