| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 DCHECK(task); | 265 DCHECK(task); |
| 266 PendingTask pending_task( | 266 PendingTask pending_task( |
| 267 from_here, | 267 from_here, |
| 268 base::Bind( | 268 base::Bind( |
| 269 &base::subtle::TaskClosureAdapter::Run, | 269 &base::subtle::TaskClosureAdapter::Run, |
| 270 new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)), | 270 new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)), |
| 271 CalculateDelayedRuntime(delay_ms), true); | 271 CalculateDelayedRuntime(delay_ms), true); |
| 272 AddToIncomingQueue(&pending_task); | 272 AddToIncomingQueue(&pending_task); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void MessageLoop::PostDelayedTask( |
| 276 const tracked_objects::Location& from_here, |
| 277 Task* task, |
| 278 base::TimeDelta delay) { |
| 279 PostDelayedTask(from_here, task, delay.InMillisecondsRoundedUp()); |
| 280 } |
| 281 |
| 275 void MessageLoop::PostNonNestableTask( | 282 void MessageLoop::PostNonNestableTask( |
| 276 const tracked_objects::Location& from_here, Task* task) { | 283 const tracked_objects::Location& from_here, Task* task) { |
| 277 DCHECK(task); | 284 DCHECK(task); |
| 278 PendingTask pending_task( | 285 PendingTask pending_task( |
| 279 from_here, | 286 from_here, |
| 280 base::Bind( | 287 base::Bind( |
| 281 &base::subtle::TaskClosureAdapter::Run, | 288 &base::subtle::TaskClosureAdapter::Run, |
| 282 new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)), | 289 new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)), |
| 283 CalculateDelayedRuntime(0), false); | 290 CalculateDelayedRuntime(0), false); |
| 284 AddToIncomingQueue(&pending_task); | 291 AddToIncomingQueue(&pending_task); |
| 285 } | 292 } |
| 286 | 293 |
| 287 void MessageLoop::PostNonNestableDelayedTask( | 294 void MessageLoop::PostNonNestableDelayedTask( |
| 288 const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { | 295 const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { |
| 289 DCHECK(task); | 296 DCHECK(task); |
| 290 PendingTask pending_task( | 297 PendingTask pending_task( |
| 291 from_here, | 298 from_here, |
| 292 base::Bind( | 299 base::Bind( |
| 293 &base::subtle::TaskClosureAdapter::Run, | 300 &base::subtle::TaskClosureAdapter::Run, |
| 294 new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)), | 301 new base::subtle::TaskClosureAdapter(task, &should_leak_tasks_)), |
| 295 CalculateDelayedRuntime(delay_ms), false); | 302 CalculateDelayedRuntime(delay_ms), false); |
| 296 AddToIncomingQueue(&pending_task); | 303 AddToIncomingQueue(&pending_task); |
| 297 } | 304 } |
| 298 | 305 |
| 306 void MessageLoop::PostNonNestableDelayedTask( |
| 307 const tracked_objects::Location& from_here, |
| 308 Task* task, |
| 309 base::TimeDelta delay) { |
| 310 PostNonNestableDelayedTask(from_here, task, delay.InMillisecondsRoundedUp()); |
| 311 } |
| 312 |
| 299 void MessageLoop::PostTask( | 313 void MessageLoop::PostTask( |
| 300 const tracked_objects::Location& from_here, const base::Closure& task) { | 314 const tracked_objects::Location& from_here, const base::Closure& task) { |
| 301 DCHECK(!task.is_null()) << from_here.ToString(); | 315 DCHECK(!task.is_null()) << from_here.ToString(); |
| 302 PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), true); | 316 PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), true); |
| 303 AddToIncomingQueue(&pending_task); | 317 AddToIncomingQueue(&pending_task); |
| 304 } | 318 } |
| 305 | 319 |
| 306 void MessageLoop::PostDelayedTask( | 320 void MessageLoop::PostDelayedTask( |
| 307 const tracked_objects::Location& from_here, const base::Closure& task, | 321 const tracked_objects::Location& from_here, |
| 322 const base::Closure& task, |
| 308 int64 delay_ms) { | 323 int64 delay_ms) { |
| 309 DCHECK(!task.is_null()) << from_here.ToString(); | 324 DCHECK(!task.is_null()) << from_here.ToString(); |
| 310 PendingTask pending_task(from_here, task, | 325 PendingTask pending_task(from_here, task, |
| 311 CalculateDelayedRuntime(delay_ms), true); | 326 CalculateDelayedRuntime(delay_ms), true); |
| 312 AddToIncomingQueue(&pending_task); | 327 AddToIncomingQueue(&pending_task); |
| 313 } | 328 } |
| 314 | 329 |
| 330 void MessageLoop::PostDelayedTask( |
| 331 const tracked_objects::Location& from_here, |
| 332 const base::Closure& task, |
| 333 base::TimeDelta delay) { |
| 334 PostDelayedTask(from_here, task, delay.InMillisecondsRoundedUp()); |
| 335 } |
| 336 |
| 315 void MessageLoop::PostNonNestableTask( | 337 void MessageLoop::PostNonNestableTask( |
| 316 const tracked_objects::Location& from_here, const base::Closure& task) { | 338 const tracked_objects::Location& from_here, const base::Closure& task) { |
| 317 DCHECK(!task.is_null()) << from_here.ToString(); | 339 DCHECK(!task.is_null()) << from_here.ToString(); |
| 318 PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), false); | 340 PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), false); |
| 319 AddToIncomingQueue(&pending_task); | 341 AddToIncomingQueue(&pending_task); |
| 320 } | 342 } |
| 321 | 343 |
| 322 void MessageLoop::PostNonNestableDelayedTask( | 344 void MessageLoop::PostNonNestableDelayedTask( |
| 323 const tracked_objects::Location& from_here, const base::Closure& task, | 345 const tracked_objects::Location& from_here, const base::Closure& task, |
| 324 int64 delay_ms) { | 346 int64 delay_ms) { |
| 325 DCHECK(!task.is_null()) << from_here.ToString(); | 347 DCHECK(!task.is_null()) << from_here.ToString(); |
| 326 PendingTask pending_task(from_here, task, | 348 PendingTask pending_task(from_here, task, |
| 327 CalculateDelayedRuntime(delay_ms), false); | 349 CalculateDelayedRuntime(delay_ms), false); |
| 328 AddToIncomingQueue(&pending_task); | 350 AddToIncomingQueue(&pending_task); |
| 329 } | 351 } |
| 330 | 352 |
| 353 void MessageLoop::PostNonNestableDelayedTask( |
| 354 const tracked_objects::Location& from_here, |
| 355 const base::Closure& task, |
| 356 base::TimeDelta delay) { |
| 357 PostNonNestableDelayedTask(from_here, task, delay.InMillisecondsRoundedUp()); |
| 358 } |
| 359 |
| 331 void MessageLoop::Run() { | 360 void MessageLoop::Run() { |
| 332 AutoRunState save_state(this); | 361 AutoRunState save_state(this); |
| 333 RunHandler(); | 362 RunHandler(); |
| 334 } | 363 } |
| 335 | 364 |
| 336 void MessageLoop::RunAllPending() { | 365 void MessageLoop::RunAllPending() { |
| 337 AutoRunState save_state(this); | 366 AutoRunState save_state(this); |
| 338 state_->quit_received = true; // Means run until we would otherwise block. | 367 state_->quit_received = true; // Means run until we would otherwise block. |
| 339 RunHandler(); | 368 RunHandler(); |
| 340 } | 369 } |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 Watcher *delegate) { | 856 Watcher *delegate) { |
| 828 return pump_libevent()->WatchFileDescriptor( | 857 return pump_libevent()->WatchFileDescriptor( |
| 829 fd, | 858 fd, |
| 830 persistent, | 859 persistent, |
| 831 static_cast<base::MessagePumpLibevent::Mode>(mode), | 860 static_cast<base::MessagePumpLibevent::Mode>(mode), |
| 832 controller, | 861 controller, |
| 833 delegate); | 862 delegate); |
| 834 } | 863 } |
| 835 | 864 |
| 836 #endif | 865 #endif |
| OLD | NEW |