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

Side by Side Diff: base/message_loop.cc

Issue 10572030: Remove old Sleep and PostDelayedTask interfaces that use int ms instead of TimeDelta. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix minor nits. Created 8 years, 6 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
« no previous file with comments | « base/message_loop.h ('k') | base/message_loop_proxy_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 251
252 void MessageLoop::RemoveDestructionObserver( 252 void MessageLoop::RemoveDestructionObserver(
253 DestructionObserver* destruction_observer) { 253 DestructionObserver* destruction_observer) {
254 DCHECK_EQ(this, current()); 254 DCHECK_EQ(this, current());
255 destruction_observers_.RemoveObserver(destruction_observer); 255 destruction_observers_.RemoveObserver(destruction_observer);
256 } 256 }
257 257
258 void MessageLoop::PostTask( 258 void MessageLoop::PostTask(
259 const tracked_objects::Location& from_here, const base::Closure& task) { 259 const tracked_objects::Location& from_here, const base::Closure& task) {
260 DCHECK(!task.is_null()) << from_here.ToString(); 260 DCHECK(!task.is_null()) << from_here.ToString();
261 PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), true); 261 PendingTask pending_task(
262 from_here, task, CalculateDelayedRuntime(TimeDelta()), true);
262 AddToIncomingQueue(&pending_task); 263 AddToIncomingQueue(&pending_task);
263 } 264 }
264 265
265 void MessageLoop::PostDelayedTask( 266 void MessageLoop::PostDelayedTask(
266 const tracked_objects::Location& from_here, 267 const tracked_objects::Location& from_here,
267 const base::Closure& task, 268 const base::Closure& task,
268 int64 delay_ms) { 269 TimeDelta delay) {
269 DCHECK(!task.is_null()) << from_here.ToString(); 270 DCHECK(!task.is_null()) << from_here.ToString();
270 PendingTask pending_task(from_here, task, 271 PendingTask pending_task(
271 CalculateDelayedRuntime(delay_ms), true); 272 from_here, task, CalculateDelayedRuntime(delay), true);
272 AddToIncomingQueue(&pending_task); 273 AddToIncomingQueue(&pending_task);
273 } 274 }
274 275
275 void MessageLoop::PostDelayedTask( 276 void MessageLoop::PostNonNestableTask(
276 const tracked_objects::Location& from_here, 277 const tracked_objects::Location& from_here,
277 const base::Closure& task, 278 const base::Closure& task) {
278 base::TimeDelta delay) {
279 PostDelayedTask(from_here, task, delay.InMillisecondsRoundedUp());
280 }
281
282 void MessageLoop::PostNonNestableTask(
283 const tracked_objects::Location& from_here, const base::Closure& task) {
284 DCHECK(!task.is_null()) << from_here.ToString(); 279 DCHECK(!task.is_null()) << from_here.ToString();
285 PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), false); 280 PendingTask pending_task(
286 AddToIncomingQueue(&pending_task); 281 from_here, task, CalculateDelayedRuntime(TimeDelta()), false);
287 }
288
289 void MessageLoop::PostNonNestableDelayedTask(
290 const tracked_objects::Location& from_here, const base::Closure& task,
291 int64 delay_ms) {
292 DCHECK(!task.is_null()) << from_here.ToString();
293 PendingTask pending_task(from_here, task,
294 CalculateDelayedRuntime(delay_ms), false);
295 AddToIncomingQueue(&pending_task); 282 AddToIncomingQueue(&pending_task);
296 } 283 }
297 284
298 void MessageLoop::PostNonNestableDelayedTask( 285 void MessageLoop::PostNonNestableDelayedTask(
299 const tracked_objects::Location& from_here, 286 const tracked_objects::Location& from_here,
300 const base::Closure& task, 287 const base::Closure& task,
301 base::TimeDelta delay) { 288 TimeDelta delay) {
302 PostNonNestableDelayedTask(from_here, task, delay.InMillisecondsRoundedUp()); 289 DCHECK(!task.is_null()) << from_here.ToString();
290 PendingTask pending_task(
291 from_here, task, CalculateDelayedRuntime(delay), false);
292 AddToIncomingQueue(&pending_task);
303 } 293 }
304 294
305 void MessageLoop::Run() { 295 void MessageLoop::Run() {
306 AutoRunState save_state(this); 296 AutoRunState save_state(this);
307 RunHandler(); 297 RunHandler();
308 } 298 }
309 299
310 void MessageLoop::RunAllPending() { 300 void MessageLoop::RunAllPending() {
311 AutoRunState save_state(this); 301 AutoRunState save_state(this);
312 state_->quit_received = true; // Means run until we would otherwise block. 302 state_->quit_received = true; // Means run until we would otherwise block.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // not completely clear why we want to leak them in the loops above. This 526 // not completely clear why we want to leak them in the loops above. This
537 // code is replicating legacy behavior, and should not be considered 527 // code is replicating legacy behavior, and should not be considered
538 // absolutely "correct" behavior. See TODO above about deleting all tasks 528 // absolutely "correct" behavior. See TODO above about deleting all tasks
539 // when it's safe. 529 // when it's safe.
540 while (!delayed_work_queue_.empty()) { 530 while (!delayed_work_queue_.empty()) {
541 delayed_work_queue_.pop(); 531 delayed_work_queue_.pop();
542 } 532 }
543 return did_work; 533 return did_work;
544 } 534 }
545 535
546 TimeTicks MessageLoop::CalculateDelayedRuntime(int64 delay_ms) { 536 TimeTicks MessageLoop::CalculateDelayedRuntime(TimeDelta delay) {
547 TimeTicks delayed_run_time; 537 TimeTicks delayed_run_time;
548 if (delay_ms > 0) { 538 if (delay > TimeDelta()) {
549 delayed_run_time = 539 delayed_run_time = TimeTicks::Now() + delay;
550 TimeTicks::Now() + TimeDelta::FromMilliseconds(delay_ms);
551 540
552 #if defined(OS_WIN) 541 #if defined(OS_WIN)
553 if (high_resolution_timer_expiration_.is_null()) { 542 if (high_resolution_timer_expiration_.is_null()) {
554 // Windows timers are granular to 15.6ms. If we only set high-res 543 // Windows timers are granular to 15.6ms. If we only set high-res
555 // timers for those under 15.6ms, then a 18ms timer ticks at ~32ms, 544 // timers for those under 15.6ms, then a 18ms timer ticks at ~32ms,
556 // which as a percentage is pretty inaccurate. So enable high 545 // which as a percentage is pretty inaccurate. So enable high
557 // res timers for any timer which is within 2x of the granularity. 546 // res timers for any timer which is within 2x of the granularity.
558 // This is a tradeoff between accuracy and power management. 547 // This is a tradeoff between accuracy and power management.
559 bool needs_high_res_timers = 548 bool needs_high_res_timers = delay.InMilliseconds() <
560 delay_ms < (2 * base::Time::kMinLowResolutionThresholdMs); 549 (2 * base::Time::kMinLowResolutionThresholdMs);
561 if (needs_high_res_timers) { 550 if (needs_high_res_timers) {
562 if (base::Time::ActivateHighResolutionTimer(true)) { 551 if (base::Time::ActivateHighResolutionTimer(true)) {
563 high_resolution_timer_expiration_ = TimeTicks::Now() + 552 high_resolution_timer_expiration_ = TimeTicks::Now() +
564 TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs); 553 TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs);
565 } 554 }
566 } 555 }
567 } 556 }
568 #endif 557 #endif
569 } else { 558 } else {
570 DCHECK_EQ(delay_ms, 0) << "delay should not be negative"; 559 DCHECK_EQ(delay.InMilliseconds(), 0) << "delay should not be negative";
571 } 560 }
572 561
573 #if defined(OS_WIN) 562 #if defined(OS_WIN)
574 if (!high_resolution_timer_expiration_.is_null()) { 563 if (!high_resolution_timer_expiration_.is_null()) {
575 if (TimeTicks::Now() > high_resolution_timer_expiration_) { 564 if (TimeTicks::Now() > high_resolution_timer_expiration_) {
576 base::Time::ActivateHighResolutionTimer(false); 565 base::Time::ActivateHighResolutionTimer(false);
577 high_resolution_timer_expiration_ = TimeTicks(); 566 high_resolution_timer_expiration_ = TimeTicks();
578 } 567 }
579 } 568 }
580 #endif 569 #endif
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 Watcher *delegate) { 790 Watcher *delegate) {
802 return pump_libevent()->WatchFileDescriptor( 791 return pump_libevent()->WatchFileDescriptor(
803 fd, 792 fd,
804 persistent, 793 persistent,
805 static_cast<base::MessagePumpLibevent::Mode>(mode), 794 static_cast<base::MessagePumpLibevent::Mode>(mode),
806 controller, 795 controller,
807 delegate); 796 delegate);
808 } 797 }
809 798
810 #endif 799 #endif
OLDNEW
« no previous file with comments | « base/message_loop.h ('k') | base/message_loop_proxy_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698