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 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 114 |
115 MessageLoop::TaskObserver::TaskObserver() { | 115 MessageLoop::TaskObserver::TaskObserver() { |
116 } | 116 } |
117 | 117 |
118 MessageLoop::TaskObserver::~TaskObserver() { | 118 MessageLoop::TaskObserver::~TaskObserver() { |
119 } | 119 } |
120 | 120 |
121 MessageLoop::DestructionObserver::~DestructionObserver() { | 121 MessageLoop::DestructionObserver::~DestructionObserver() { |
122 } | 122 } |
123 | 123 |
| 124 MessageLoop::NestingObserver::~NestingObserver() {} |
| 125 |
124 //------------------------------------------------------------------------------ | 126 //------------------------------------------------------------------------------ |
125 | 127 |
126 MessageLoop::MessageLoop(Type type) | 128 MessageLoop::MessageLoop(Type type) |
127 : MessageLoop(type, MessagePumpFactoryCallback()) { | 129 : MessageLoop(type, MessagePumpFactoryCallback()) { |
128 BindToCurrentThread(); | 130 BindToCurrentThread(); |
129 } | 131 } |
130 | 132 |
131 MessageLoop::MessageLoop(std::unique_ptr<MessagePump> pump) | 133 MessageLoop::MessageLoop(std::unique_ptr<MessagePump> pump) |
132 : MessageLoop(TYPE_CUSTOM, Bind(&ReturnPump, Passed(&pump))) { | 134 : MessageLoop(TYPE_CUSTOM, Bind(&ReturnPump, Passed(&pump))) { |
133 BindToCurrentThread(); | 135 BindToCurrentThread(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 DCHECK_EQ(this, current()); | 258 DCHECK_EQ(this, current()); |
257 destruction_observers_.AddObserver(destruction_observer); | 259 destruction_observers_.AddObserver(destruction_observer); |
258 } | 260 } |
259 | 261 |
260 void MessageLoop::RemoveDestructionObserver( | 262 void MessageLoop::RemoveDestructionObserver( |
261 DestructionObserver* destruction_observer) { | 263 DestructionObserver* destruction_observer) { |
262 DCHECK_EQ(this, current()); | 264 DCHECK_EQ(this, current()); |
263 destruction_observers_.RemoveObserver(destruction_observer); | 265 destruction_observers_.RemoveObserver(destruction_observer); |
264 } | 266 } |
265 | 267 |
| 268 void MessageLoop::AddNestingObserver(NestingObserver* observer) { |
| 269 DCHECK_EQ(this, current()); |
| 270 nesting_observers_.AddObserver(observer); |
| 271 } |
| 272 |
| 273 void MessageLoop::RemoveNestingObserver(NestingObserver* observer) { |
| 274 DCHECK_EQ(this, current()); |
| 275 nesting_observers_.RemoveObserver(observer); |
| 276 } |
| 277 |
266 void MessageLoop::PostTask( | 278 void MessageLoop::PostTask( |
267 const tracked_objects::Location& from_here, | 279 const tracked_objects::Location& from_here, |
268 const Closure& task) { | 280 const Closure& task) { |
269 task_runner_->PostTask(from_here, task); | 281 task_runner_->PostTask(from_here, task); |
270 } | 282 } |
271 | 283 |
272 void MessageLoop::PostDelayedTask( | 284 void MessageLoop::PostDelayedTask( |
273 const tracked_objects::Location& from_here, | 285 const tracked_objects::Location& from_here, |
274 const Closure& task, | 286 const Closure& task, |
275 TimeDelta delay) { | 287 TimeDelta delay) { |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 #endif | 581 #endif |
570 } | 582 } |
571 | 583 |
572 void MessageLoop::HistogramEvent(int event) { | 584 void MessageLoop::HistogramEvent(int event) { |
573 #if !defined(OS_NACL) | 585 #if !defined(OS_NACL) |
574 if (message_histogram_) | 586 if (message_histogram_) |
575 message_histogram_->Add(event); | 587 message_histogram_->Add(event); |
576 #endif | 588 #endif |
577 } | 589 } |
578 | 590 |
| 591 void MessageLoop::NotifyBeginNestedLoop() { |
| 592 FOR_EACH_OBSERVER(NestingObserver, nesting_observers_, |
| 593 OnBeginNestedMessageLoop()); |
| 594 } |
| 595 |
579 bool MessageLoop::DoWork() { | 596 bool MessageLoop::DoWork() { |
580 if (!nestable_tasks_allowed_) { | 597 if (!nestable_tasks_allowed_) { |
581 // Task can't be executed right now. | 598 // Task can't be executed right now. |
582 return false; | 599 return false; |
583 } | 600 } |
584 | 601 |
585 for (;;) { | 602 for (;;) { |
586 ReloadWorkQueue(); | 603 ReloadWorkQueue(); |
587 if (work_queue_.empty()) | 604 if (work_queue_.empty()) |
588 break; | 605 break; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 persistent, | 765 persistent, |
749 mode, | 766 mode, |
750 controller, | 767 controller, |
751 delegate); | 768 delegate); |
752 } | 769 } |
753 #endif | 770 #endif |
754 | 771 |
755 #endif // !defined(OS_NACL_SFI) | 772 #endif // !defined(OS_NACL_SFI) |
756 | 773 |
757 } // namespace base | 774 } // namespace base |
OLD | NEW |