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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 VALUE_TO_NUMBER_AND_NAME(kTimerEvent) | 79 VALUE_TO_NUMBER_AND_NAME(kTimerEvent) |
80 | 80 |
81 {-1, NULL} // The list must be null terminated, per API to histogram. | 81 {-1, NULL} // The list must be null terminated, per API to histogram. |
82 }; | 82 }; |
83 #endif // !defined(OS_NACL) | 83 #endif // !defined(OS_NACL) |
84 | 84 |
85 bool enable_histogrammer_ = false; | 85 bool enable_histogrammer_ = false; |
86 | 86 |
87 MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = NULL; | 87 MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = NULL; |
88 | 88 |
89 // Returns true if MessagePump::ScheduleWork() must be called one | |
90 // time for every task that is added to the MessageLoop incoming queue. | |
91 bool AlwaysNotifyPump(MessageLoop::Type type) { | |
92 #if defined(OS_ANDROID) | |
93 // The Android UI message loop needs to get notified each time a task is added | |
94 // to the incoming queue. | |
95 return type == MessageLoop::TYPE_UI || type == MessageLoop::TYPE_JAVA; | |
96 #else | |
97 return false; | |
98 #endif | |
99 } | |
100 | |
101 #if defined(OS_IOS) | 89 #if defined(OS_IOS) |
102 typedef MessagePumpIOSForIO MessagePumpForIO; | 90 typedef MessagePumpIOSForIO MessagePumpForIO; |
103 #elif defined(OS_NACL) | 91 #elif defined(OS_NACL) |
104 typedef MessagePumpDefault MessagePumpForIO; | 92 typedef MessagePumpDefault MessagePumpForIO; |
105 #elif defined(OS_POSIX) | 93 #elif defined(OS_POSIX) |
106 typedef MessagePumpLibevent MessagePumpForIO; | 94 typedef MessagePumpLibevent MessagePumpForIO; |
107 #endif | 95 #endif |
108 | 96 |
109 MessagePumpForIO* ToPumpIO(MessagePump* pump) { | 97 MessagePumpForIO* ToPumpIO(MessagePump* pump) { |
110 return static_cast<MessagePumpForIO*>(pump); | 98 return static_cast<MessagePumpForIO*>(pump); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 // We can improve performance of our loading tasks from the incoming queue to | 491 // We can improve performance of our loading tasks from the incoming queue to |
504 // |*work_queue| by waiting until the last minute (|*work_queue| is empty) to | 492 // |*work_queue| by waiting until the last minute (|*work_queue| is empty) to |
505 // load. That reduces the number of locks-per-task significantly when our | 493 // load. That reduces the number of locks-per-task significantly when our |
506 // queues get large. | 494 // queues get large. |
507 if (work_queue_.empty()) { | 495 if (work_queue_.empty()) { |
508 pending_high_res_tasks_ += | 496 pending_high_res_tasks_ += |
509 incoming_task_queue_->ReloadWorkQueue(&work_queue_); | 497 incoming_task_queue_->ReloadWorkQueue(&work_queue_); |
510 } | 498 } |
511 } | 499 } |
512 | 500 |
513 void MessageLoop::ScheduleWork(bool was_empty) { | 501 void MessageLoop::ScheduleWork() { |
514 if (was_empty || AlwaysNotifyPump(type_)) | 502 pump_->ScheduleWork(); |
515 pump_->ScheduleWork(); | |
516 } | 503 } |
517 | 504 |
518 //------------------------------------------------------------------------------ | 505 //------------------------------------------------------------------------------ |
519 // Method and data for histogramming events and actions taken by each instance | 506 // Method and data for histogramming events and actions taken by each instance |
520 // on each thread. | 507 // on each thread. |
521 | 508 |
522 void MessageLoop::StartHistogrammer() { | 509 void MessageLoop::StartHistogrammer() { |
523 #if !defined(OS_NACL) // NaCl build has no metrics code. | 510 #if !defined(OS_NACL) // NaCl build has no metrics code. |
524 if (enable_histogrammer_ && !message_histogram_ | 511 if (enable_histogrammer_ && !message_histogram_ |
525 && StatisticsRecorder::IsActive()) { | 512 && StatisticsRecorder::IsActive()) { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 persistent, | 697 persistent, |
711 mode, | 698 mode, |
712 controller, | 699 controller, |
713 delegate); | 700 delegate); |
714 } | 701 } |
715 #endif | 702 #endif |
716 | 703 |
717 #endif // !defined(OS_NACL) | 704 #endif // !defined(OS_NACL) |
718 | 705 |
719 } // namespace base | 706 } // namespace base |
OLD | NEW |