| 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 <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 DeletePendingTasks(); | 117 DeletePendingTasks(); |
| 118 ReloadWorkQueue(); | 118 ReloadWorkQueue(); |
| 119 // If we end up with empty queues, then break out of the loop. | 119 // If we end up with empty queues, then break out of the loop. |
| 120 did_work = DeletePendingTasks(); | 120 did_work = DeletePendingTasks(); |
| 121 if (!did_work) | 121 if (!did_work) |
| 122 break; | 122 break; |
| 123 } | 123 } |
| 124 DCHECK(!did_work); | 124 DCHECK(!did_work); |
| 125 | 125 |
| 126 // Let interested parties have one last shot at accessing this. | 126 // Let interested parties have one last shot at accessing this. |
| 127 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, | 127 if (enable_destruction_observers_) { |
| 128 WillDestroyCurrentMessageLoop()); | 128 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, |
| 129 WillDestroyCurrentMessageLoop()); |
| 130 } |
| 129 | 131 |
| 130 thread_task_runner_handle_.reset(); | 132 thread_task_runner_handle_.reset(); |
| 131 | 133 |
| 132 // Tell the incoming queue that we are dying. | 134 // Tell the incoming queue that we are dying. |
| 133 incoming_task_queue_->WillDestroyCurrentMessageLoop(); | 135 incoming_task_queue_->WillDestroyCurrentMessageLoop(); |
| 134 incoming_task_queue_ = NULL; | 136 incoming_task_queue_ = NULL; |
| 135 unbound_task_runner_ = NULL; | 137 unbound_task_runner_ = NULL; |
| 136 task_runner_ = NULL; | 138 task_runner_ = NULL; |
| 137 | 139 |
| 138 // OK, now make it so that no one can find us. | 140 // OK, now make it so that no one can find us. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 return std::unique_ptr<MessagePump>(new MessagePumpForUI()); | 200 return std::unique_ptr<MessagePump>(new MessagePumpForUI()); |
| 199 #endif | 201 #endif |
| 200 | 202 |
| 201 DCHECK_EQ(MessageLoop::TYPE_DEFAULT, type); | 203 DCHECK_EQ(MessageLoop::TYPE_DEFAULT, type); |
| 202 return MESSAGE_PUMP_DEFAULT; | 204 return MESSAGE_PUMP_DEFAULT; |
| 203 } | 205 } |
| 204 | 206 |
| 205 void MessageLoop::AddDestructionObserver( | 207 void MessageLoop::AddDestructionObserver( |
| 206 DestructionObserver* destruction_observer) { | 208 DestructionObserver* destruction_observer) { |
| 207 DCHECK_EQ(this, current()); | 209 DCHECK_EQ(this, current()); |
| 210 //DCHECK(enable_destruction_observers_); |
| 208 destruction_observers_.AddObserver(destruction_observer); | 211 destruction_observers_.AddObserver(destruction_observer); |
| 209 } | 212 } |
| 210 | 213 |
| 211 void MessageLoop::RemoveDestructionObserver( | 214 void MessageLoop::RemoveDestructionObserver( |
| 212 DestructionObserver* destruction_observer) { | 215 DestructionObserver* destruction_observer) { |
| 213 DCHECK_EQ(this, current()); | 216 DCHECK_EQ(this, current()); |
| 217 //DCHECK(enable_destruction_observers_); |
| 214 destruction_observers_.RemoveObserver(destruction_observer); | 218 destruction_observers_.RemoveObserver(destruction_observer); |
| 215 } | 219 } |
| 216 | 220 |
| 217 void MessageLoop::AddNestingObserver(NestingObserver* observer) { | 221 void MessageLoop::AddNestingObserver(NestingObserver* observer) { |
| 218 DCHECK_EQ(this, current()); | 222 DCHECK_EQ(this, current()); |
| 223 DCHECK(enable_nesting_); |
| 219 nesting_observers_.AddObserver(observer); | 224 nesting_observers_.AddObserver(observer); |
| 220 } | 225 } |
| 221 | 226 |
| 222 void MessageLoop::RemoveNestingObserver(NestingObserver* observer) { | 227 void MessageLoop::RemoveNestingObserver(NestingObserver* observer) { |
| 223 DCHECK_EQ(this, current()); | 228 DCHECK_EQ(this, current()); |
| 229 DCHECK(enable_nesting_); |
| 224 nesting_observers_.RemoveObserver(observer); | 230 nesting_observers_.RemoveObserver(observer); |
| 225 } | 231 } |
| 226 | 232 |
| 227 void MessageLoop::QuitWhenIdle() { | 233 void MessageLoop::QuitWhenIdle() { |
| 228 DCHECK_EQ(this, current()); | 234 DCHECK_EQ(this, current()); |
| 229 if (run_loop_) { | 235 if (run_loop_) { |
| 230 run_loop_->QuitWhenIdle(); | 236 run_loop_->QuitWhenIdle(); |
| 231 } else { | 237 } else { |
| 232 NOTREACHED() << "Must be inside Run to call QuitWhenIdle"; | 238 NOTREACHED() << "Must be inside Run to call QuitWhenIdle"; |
| 233 } | 239 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 bool MessageLoop::NestableTasksAllowed() const { | 273 bool MessageLoop::NestableTasksAllowed() const { |
| 268 return nestable_tasks_allowed_; | 274 return nestable_tasks_allowed_; |
| 269 } | 275 } |
| 270 | 276 |
| 271 bool MessageLoop::IsNested() { | 277 bool MessageLoop::IsNested() { |
| 272 return run_loop_->run_depth_ > 1; | 278 return run_loop_->run_depth_ > 1; |
| 273 } | 279 } |
| 274 | 280 |
| 275 void MessageLoop::AddTaskObserver(TaskObserver* task_observer) { | 281 void MessageLoop::AddTaskObserver(TaskObserver* task_observer) { |
| 276 DCHECK_EQ(this, current()); | 282 DCHECK_EQ(this, current()); |
| 283 DCHECK(enable_task_observers_); |
| 277 task_observers_.AddObserver(task_observer); | 284 task_observers_.AddObserver(task_observer); |
| 278 } | 285 } |
| 279 | 286 |
| 280 void MessageLoop::RemoveTaskObserver(TaskObserver* task_observer) { | 287 void MessageLoop::RemoveTaskObserver(TaskObserver* task_observer) { |
| 281 DCHECK_EQ(this, current()); | 288 DCHECK_EQ(this, current()); |
| 289 DCHECK(enable_task_observers_); |
| 282 task_observers_.RemoveObserver(task_observer); | 290 task_observers_.RemoveObserver(task_observer); |
| 283 } | 291 } |
| 284 | 292 |
| 285 bool MessageLoop::is_running() const { | 293 bool MessageLoop::is_running() const { |
| 286 DCHECK_EQ(this, current()); | 294 DCHECK_EQ(this, current()); |
| 287 return run_loop_ != NULL; | 295 return run_loop_ != NULL; |
| 288 } | 296 } |
| 289 | 297 |
| 290 bool MessageLoop::HasHighResolutionTasks() { | 298 bool MessageLoop::HasHighResolutionTasks() { |
| 291 return incoming_task_queue_->HasHighResolutionTasks(); | 299 return incoming_task_queue_->HasHighResolutionTasks(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 void MessageLoop::SetThreadTaskRunnerHandle() { | 368 void MessageLoop::SetThreadTaskRunnerHandle() { |
| 361 DCHECK_EQ(this, current()); | 369 DCHECK_EQ(this, current()); |
| 362 // Clear the previous thread task runner first, because only one can exist at | 370 // Clear the previous thread task runner first, because only one can exist at |
| 363 // a time. | 371 // a time. |
| 364 thread_task_runner_handle_.reset(); | 372 thread_task_runner_handle_.reset(); |
| 365 thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner_)); | 373 thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner_)); |
| 366 } | 374 } |
| 367 | 375 |
| 368 void MessageLoop::RunHandler() { | 376 void MessageLoop::RunHandler() { |
| 369 DCHECK_EQ(this, current()); | 377 DCHECK_EQ(this, current()); |
| 378 DCHECK(enable_nesting_ || run_loop_->run_depth_ == 1); |
| 370 pump_->Run(this); | 379 pump_->Run(this); |
| 371 } | 380 } |
| 372 | 381 |
| 373 bool MessageLoop::ProcessNextDelayedNonNestableTask() { | 382 bool MessageLoop::ProcessNextDelayedNonNestableTask() { |
| 374 if (run_loop_->run_depth_ != 1) | 383 if (run_loop_->run_depth_ != 1) |
| 375 return false; | 384 return false; |
| 376 | 385 |
| 377 if (deferred_non_nestable_work_queue_.empty()) | 386 if (deferred_non_nestable_work_queue_.empty()) |
| 378 return false; | 387 return false; |
| 379 | 388 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 persistent, | 655 persistent, |
| 647 mode, | 656 mode, |
| 648 controller, | 657 controller, |
| 649 delegate); | 658 delegate); |
| 650 } | 659 } |
| 651 #endif | 660 #endif |
| 652 | 661 |
| 653 #endif // !defined(OS_NACL_SFI) | 662 #endif // !defined(OS_NACL_SFI) |
| 654 | 663 |
| 655 } // namespace base | 664 } // namespace base |
| OLD | NEW |