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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = NULL; | 90 MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = NULL; |
91 | 91 |
92 // Create a process-wide unique ID to represent this task in trace events. This | 92 // Create a process-wide unique ID to represent this task in trace events. This |
93 // will be mangled with a Process ID hash to reduce the likelyhood of colliding | 93 // will be mangled with a Process ID hash to reduce the likelyhood of colliding |
94 // with MessageLoop pointers on other processes. | 94 // with MessageLoop pointers on other processes. |
95 uint64 GetTaskTraceID(const PendingTask& task, MessageLoop* loop) { | 95 uint64 GetTaskTraceID(const PendingTask& task, MessageLoop* loop) { |
96 return (static_cast<uint64>(task.sequence_num) << 32) | | 96 return (static_cast<uint64>(task.sequence_num) << 32) | |
97 static_cast<uint64>(reinterpret_cast<intptr_t>(loop)); | 97 static_cast<uint64>(reinterpret_cast<intptr_t>(loop)); |
98 } | 98 } |
99 | 99 |
| 100 // Returns true if MessagePump::ScheduleWork() must be called one |
| 101 // time for every task that is added to the MessageLoop incoming queue. |
| 102 bool AlwaysNotifyPump(MessageLoop::Type type) { |
| 103 #if defined(OS_ANDROID) |
| 104 return type == MessageLoop::TYPE_UI; |
| 105 #else |
| 106 return false; |
| 107 #endif |
| 108 } |
| 109 |
100 } // namespace | 110 } // namespace |
101 | 111 |
102 //------------------------------------------------------------------------------ | 112 //------------------------------------------------------------------------------ |
103 | 113 |
104 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
105 | 115 |
106 // Upon a SEH exception in this thread, it restores the original unhandled | 116 // Upon a SEH exception in this thread, it restores the original unhandled |
107 // exception filter. | 117 // exception filter. |
108 static int SEHFilter(LPTOP_LEVEL_EXCEPTION_FILTER old_filter) { | 118 static int SEHFilter(LPTOP_LEVEL_EXCEPTION_FILTER old_filter) { |
109 ::SetUnhandledExceptionFilter(old_filter); | 119 ::SetUnhandledExceptionFilter(old_filter); |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 // tasks (to faciliate FIFO sorting when two tasks have the same | 627 // tasks (to faciliate FIFO sorting when two tasks have the same |
618 // delayed_run_time value) and for identifying the task in about:tracing. | 628 // delayed_run_time value) and for identifying the task in about:tracing. |
619 pending_task->sequence_num = next_sequence_num_++; | 629 pending_task->sequence_num = next_sequence_num_++; |
620 | 630 |
621 TRACE_EVENT_FLOW_BEGIN0("task", "MessageLoop::PostTask", | 631 TRACE_EVENT_FLOW_BEGIN0("task", "MessageLoop::PostTask", |
622 TRACE_ID_MANGLE(GetTaskTraceID(*pending_task, this))); | 632 TRACE_ID_MANGLE(GetTaskTraceID(*pending_task, this))); |
623 | 633 |
624 bool was_empty = incoming_queue_.empty(); | 634 bool was_empty = incoming_queue_.empty(); |
625 incoming_queue_.push(*pending_task); | 635 incoming_queue_.push(*pending_task); |
626 pending_task->task.Reset(); | 636 pending_task->task.Reset(); |
627 if (!was_empty) | 637 // The Android UI message loop needs to get notified each time |
| 638 // a task is added to the incoming queue. |
| 639 if (!was_empty && !AlwaysNotifyPump(type_)) |
628 return true; // Someone else should have started the sub-pump. | 640 return true; // Someone else should have started the sub-pump. |
629 | 641 |
630 pump = pump_; | 642 pump = pump_; |
631 } | 643 } |
632 // Since the incoming_queue_ may contain a task that destroys this message | 644 // Since the incoming_queue_ may contain a task that destroys this message |
633 // loop, we cannot exit incoming_queue_lock_ until we are done with |this|. | 645 // loop, we cannot exit incoming_queue_lock_ until we are done with |this|. |
634 // We use a stack-based reference to the message pump so that we can call | 646 // We use a stack-based reference to the message pump so that we can call |
635 // ScheduleWork outside of incoming_queue_lock_. | 647 // ScheduleWork outside of incoming_queue_lock_. |
636 | 648 |
637 pump->ScheduleWork(); | 649 pump->ScheduleWork(); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 fd, | 837 fd, |
826 persistent, | 838 persistent, |
827 mode, | 839 mode, |
828 controller, | 840 controller, |
829 delegate); | 841 delegate); |
830 } | 842 } |
831 | 843 |
832 #endif | 844 #endif |
833 | 845 |
834 } // namespace base | 846 } // namespace base |
OLD | NEW |