| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "base/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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 AutoRunState save_state(this); | 306 AutoRunState save_state(this); |
| 307 RunHandler(); | 307 RunHandler(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 void MessageLoop::RunAllPending() { | 310 void MessageLoop::RunAllPending() { |
| 311 AutoRunState save_state(this); | 311 AutoRunState save_state(this); |
| 312 state_->quit_received = true; // Means run until we would otherwise block. | 312 state_->quit_received = true; // Means run until we would otherwise block. |
| 313 RunHandler(); | 313 RunHandler(); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void MessageLoop::Quit() { | 316 void MessageLoop::QuitWhenIdle() { |
| 317 DCHECK_EQ(this, current()); | 317 DCHECK_EQ(this, current()); |
| 318 if (state_) { | 318 if (state_) { |
| 319 state_->quit_received = true; | 319 state_->quit_received = true; |
| 320 } else { | 320 } else { |
| 321 NOTREACHED() << "Must be inside Run to call Quit"; | 321 NOTREACHED() << "Must be inside Run to call Quit"; |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 | 324 |
| 325 void MessageLoop::QuitNow() { | 325 void MessageLoop::QuitNow() { |
| 326 DCHECK_EQ(this, current()); | 326 DCHECK_EQ(this, current()); |
| 327 if (state_) { | 327 if (state_) { |
| 328 pump_->Quit(); | 328 pump_->Quit(); |
| 329 } else { | 329 } else { |
| 330 NOTREACHED() << "Must be inside Run to call Quit"; | 330 NOTREACHED() << "Must be inside Run to call Quit"; |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 static void QuitCurrent() { | 334 void MessageLoop::QuitAfterPending() { |
| 335 MessageLoop::current()->Quit(); | 335 DCHECK_EQ(this, current()); |
| 336 if (state_) { |
| 337 PostTask(FROM_HERE, MessageLoop::QuitNowClosure()); |
| 338 } else { |
| 339 NOTREACHED() << "Must be inside Run to call Quit"; |
| 340 } |
| 341 } |
| 342 |
| 343 static void QuitWhenIdleCurrent() { |
| 344 MessageLoop::current()->QuitWhenIdle(); |
| 345 } |
| 346 |
| 347 static void QuitNowCurrent() { |
| 348 MessageLoop::current()->QuitNow(); |
| 349 } |
| 350 |
| 351 static void QuitAfterPendingCurrent() { |
| 352 MessageLoop::current()->QuitAfterPending(); |
| 336 } | 353 } |
| 337 | 354 |
| 338 // static | 355 // static |
| 339 base::Closure MessageLoop::QuitClosure() { | 356 base::Closure MessageLoop::QuitWhenIdleClosure() { |
| 340 return base::Bind(&QuitCurrent); | 357 return base::Bind(&QuitWhenIdleCurrent); |
| 358 } |
| 359 |
| 360 // static |
| 361 base::Closure MessageLoop::QuitNowClosure() { |
| 362 return base::Bind(&QuitNowCurrent); |
| 363 } |
| 364 |
| 365 // static |
| 366 base::Closure MessageLoop::QuitAfterPendingClosure() { |
| 367 return base::Bind(&QuitAfterPendingCurrent); |
| 341 } | 368 } |
| 342 | 369 |
| 343 void MessageLoop::SetNestableTasksAllowed(bool allowed) { | 370 void MessageLoop::SetNestableTasksAllowed(bool allowed) { |
| 344 if (nestable_tasks_allowed_ != allowed) { | 371 if (nestable_tasks_allowed_ != allowed) { |
| 345 nestable_tasks_allowed_ = allowed; | 372 nestable_tasks_allowed_ = allowed; |
| 346 if (!nestable_tasks_allowed_) | 373 if (!nestable_tasks_allowed_) |
| 347 return; | 374 return; |
| 348 // Start the native pump if we are not already pumping. | 375 // Start the native pump if we are not already pumping. |
| 349 pump_->ScheduleWork(); | 376 pump_->ScheduleWork(); |
| 350 } | 377 } |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 Watcher *delegate) { | 828 Watcher *delegate) { |
| 802 return pump_libevent()->WatchFileDescriptor( | 829 return pump_libevent()->WatchFileDescriptor( |
| 803 fd, | 830 fd, |
| 804 persistent, | 831 persistent, |
| 805 static_cast<base::MessagePumpLibevent::Mode>(mode), | 832 static_cast<base::MessagePumpLibevent::Mode>(mode), |
| 806 controller, | 833 controller, |
| 807 delegate); | 834 delegate); |
| 808 } | 835 } |
| 809 | 836 |
| 810 #endif | 837 #endif |
| OLD | NEW |