Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(699)

Side by Side Diff: base/message_loop.cc

Issue 8965072: Add function support for Sleep and MessageLoop with TimeDelta input. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add TimeDelay interfaces for message loop code. Created 8 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, const base::Closure& task,
308 int64 delay_ms) { 322 int64 delay_ms) {
309 DCHECK(!task.is_null()) << from_here.ToString(); 323 DCHECK(!task.is_null()) << from_here.ToString();
310 PendingTask pending_task(from_here, task, 324 PendingTask pending_task(from_here, task,
311 CalculateDelayedRuntime(delay_ms), true); 325 CalculateDelayedRuntime(delay_ms), true);
312 AddToIncomingQueue(&pending_task); 326 AddToIncomingQueue(&pending_task);
313 } 327 }
314 328
329 void MessageLoop::PostDelayedTask(
330 const tracked_objects::Location& from_here, const base::Closure& task,
brettw 2011/12/28 20:10:27 The closure should be on the next line.
331 base::TimeDelta delay) {
332 PostDelayedTask(from_here, task, delay.InMillisecondsRoundedUp());
333 }
334
315 void MessageLoop::PostNonNestableTask( 335 void MessageLoop::PostNonNestableTask(
316 const tracked_objects::Location& from_here, const base::Closure& task) { 336 const tracked_objects::Location& from_here, const base::Closure& task) {
317 DCHECK(!task.is_null()) << from_here.ToString(); 337 DCHECK(!task.is_null()) << from_here.ToString();
318 PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), false); 338 PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), false);
319 AddToIncomingQueue(&pending_task); 339 AddToIncomingQueue(&pending_task);
320 } 340 }
321 341
322 void MessageLoop::PostNonNestableDelayedTask( 342 void MessageLoop::PostNonNestableDelayedTask(
323 const tracked_objects::Location& from_here, const base::Closure& task, 343 const tracked_objects::Location& from_here, const base::Closure& task,
324 int64 delay_ms) { 344 int64 delay_ms) {
325 DCHECK(!task.is_null()) << from_here.ToString(); 345 DCHECK(!task.is_null()) << from_here.ToString();
326 PendingTask pending_task(from_here, task, 346 PendingTask pending_task(from_here, task,
327 CalculateDelayedRuntime(delay_ms), false); 347 CalculateDelayedRuntime(delay_ms), false);
328 AddToIncomingQueue(&pending_task); 348 AddToIncomingQueue(&pending_task);
329 } 349 }
330 350
351 void MessageLoop::PostNonNestableDelayedTask(
352 const tracked_objects::Location& from_here,
353 const base::Closure& task,
354 base::TimeDelta delay) {
355 PostNonNestableDelayedTask(from_here, task, delay.InMillisecondsRoundedUp());
356 }
357
331 void MessageLoop::Run() { 358 void MessageLoop::Run() {
332 AutoRunState save_state(this); 359 AutoRunState save_state(this);
333 RunHandler(); 360 RunHandler();
334 } 361 }
335 362
336 void MessageLoop::RunAllPending() { 363 void MessageLoop::RunAllPending() {
337 AutoRunState save_state(this); 364 AutoRunState save_state(this);
338 state_->quit_received = true; // Means run until we would otherwise block. 365 state_->quit_received = true; // Means run until we would otherwise block.
339 RunHandler(); 366 RunHandler();
340 } 367 }
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 Watcher *delegate) { 854 Watcher *delegate) {
828 return pump_libevent()->WatchFileDescriptor( 855 return pump_libevent()->WatchFileDescriptor(
829 fd, 856 fd,
830 persistent, 857 persistent,
831 static_cast<base::MessagePumpLibevent::Mode>(mode), 858 static_cast<base::MessagePumpLibevent::Mode>(mode),
832 controller, 859 controller,
833 delegate); 860 delegate);
834 } 861 }
835 862
836 #endif 863 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698