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

Unified Diff: base/message_loop.cc

Issue 9703053: 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: Rebase onto master. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/message_loop.h ('k') | base/message_loop_proxy_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop.cc
diff --git a/base/message_loop.cc b/base/message_loop.cc
index a207659a4a922203a2e3850bbcdde4b1425dd21d..5c3b2bf648917f7275efdd8da653d98acbb3ddf4 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -258,48 +258,37 @@ void MessageLoop::RemoveDestructionObserver(
void MessageLoop::PostTask(
const tracked_objects::Location& from_here, const base::Closure& task) {
DCHECK(!task.is_null()) << from_here.ToString();
- PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), true);
+ PendingTask pending_task(
+ from_here, task, CalculateDelayedRuntime(TimeDelta()), true);
AddToIncomingQueue(&pending_task);
}
void MessageLoop::PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
- int64 delay_ms) {
+ TimeDelta delay) {
DCHECK(!task.is_null()) << from_here.ToString();
- PendingTask pending_task(from_here, task,
- CalculateDelayedRuntime(delay_ms), true);
+ PendingTask pending_task(
+ from_here, task, CalculateDelayedRuntime(delay), true);
AddToIncomingQueue(&pending_task);
}
-void MessageLoop::PostDelayedTask(
- const tracked_objects::Location& from_here,
- const base::Closure& task,
- base::TimeDelta delay) {
- PostDelayedTask(from_here, task, delay.InMillisecondsRoundedUp());
-}
-
void MessageLoop::PostNonNestableTask(
const tracked_objects::Location& from_here, const base::Closure& task) {
DCHECK(!task.is_null()) << from_here.ToString();
- PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), false);
- AddToIncomingQueue(&pending_task);
-}
-
-void MessageLoop::PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here, const base::Closure& task,
- int64 delay_ms) {
- DCHECK(!task.is_null()) << from_here.ToString();
- PendingTask pending_task(from_here, task,
- CalculateDelayedRuntime(delay_ms), false);
+ PendingTask pending_task(
+ from_here, task, CalculateDelayedRuntime(TimeDelta()), false);
AddToIncomingQueue(&pending_task);
}
void MessageLoop::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
- base::TimeDelta delay) {
- PostNonNestableDelayedTask(from_here, task, delay.InMillisecondsRoundedUp());
+ TimeDelta delay) {
+ DCHECK(!task.is_null()) << from_here.ToString();
+ PendingTask pending_task(
+ from_here, task, CalculateDelayedRuntime(delay), false);
+ AddToIncomingQueue(&pending_task);
}
void MessageLoop::Run() {
@@ -543,11 +532,10 @@ bool MessageLoop::DeletePendingTasks() {
return did_work;
}
-TimeTicks MessageLoop::CalculateDelayedRuntime(int64 delay_ms) {
+TimeTicks MessageLoop::CalculateDelayedRuntime(TimeDelta delay) {
TimeTicks delayed_run_time;
- if (delay_ms > 0) {
- delayed_run_time =
- TimeTicks::Now() + TimeDelta::FromMilliseconds(delay_ms);
+ if (delay > TimeDelta()) {
+ delayed_run_time = TimeTicks::Now() + delay;
#if defined(OS_WIN)
if (high_resolution_timer_expiration_.is_null()) {
@@ -556,8 +544,8 @@ TimeTicks MessageLoop::CalculateDelayedRuntime(int64 delay_ms) {
// which as a percentage is pretty inaccurate. So enable high
// res timers for any timer which is within 2x of the granularity.
// This is a tradeoff between accuracy and power management.
- bool needs_high_res_timers =
- delay_ms < (2 * base::Time::kMinLowResolutionThresholdMs);
+ bool needs_high_res_timers = delay.InMilliseconds() <
+ (2 * base::Time::kMinLowResolutionThresholdMs);
if (needs_high_res_timers) {
if (base::Time::ActivateHighResolutionTimer(true)) {
high_resolution_timer_expiration_ = TimeTicks::Now() +
@@ -567,7 +555,7 @@ TimeTicks MessageLoop::CalculateDelayedRuntime(int64 delay_ms) {
}
#endif
} else {
- DCHECK_EQ(delay_ms, 0) << "delay should not be negative";
+ DCHECK_EQ(delay.InMilliseconds(), 0) << "delay should not be negative";
}
#if defined(OS_WIN)
« 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