diff options
28 files changed, 294 insertions, 162 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc index 5c3b2bf..a207659 100644 --- a/base/message_loop.cc +++ b/base/message_loop.cc @@ -258,39 +258,50 @@ 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(TimeDelta()), true); + PendingTask pending_task(from_here, task, CalculateDelayedRuntime(0), true); AddToIncomingQueue(&pending_task); } void MessageLoop::PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, - TimeDelta delay) { + int64 delay_ms) { DCHECK(!task.is_null()) << from_here.ToString(); - PendingTask pending_task( - from_here, task, CalculateDelayedRuntime(delay), true); + PendingTask pending_task(from_here, task, + CalculateDelayedRuntime(delay_ms), 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(TimeDelta()), false); + 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, - TimeDelta delay) { + 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), false); + PendingTask pending_task(from_here, task, + CalculateDelayedRuntime(delay_ms), 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()); +} + void MessageLoop::Run() { AutoRunState save_state(this); RunHandler(); @@ -532,10 +543,11 @@ bool MessageLoop::DeletePendingTasks() { return did_work; } -TimeTicks MessageLoop::CalculateDelayedRuntime(TimeDelta delay) { +TimeTicks MessageLoop::CalculateDelayedRuntime(int64 delay_ms) { TimeTicks delayed_run_time; - if (delay > TimeDelta()) { - delayed_run_time = TimeTicks::Now() + delay; + if (delay_ms > 0) { + delayed_run_time = + TimeTicks::Now() + TimeDelta::FromMilliseconds(delay_ms); #if defined(OS_WIN) if (high_resolution_timer_expiration_.is_null()) { @@ -544,8 +556,8 @@ TimeTicks MessageLoop::CalculateDelayedRuntime(TimeDelta delay) { // 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.InMilliseconds() < - (2 * base::Time::kMinLowResolutionThresholdMs); + bool needs_high_res_timers = + delay_ms < (2 * base::Time::kMinLowResolutionThresholdMs); if (needs_high_res_timers) { if (base::Time::ActivateHighResolutionTimer(true)) { high_resolution_timer_expiration_ = TimeTicks::Now() + @@ -555,7 +567,7 @@ TimeTicks MessageLoop::CalculateDelayedRuntime(TimeDelta delay) { } #endif } else { - DCHECK_EQ(delay.InMilliseconds(), 0) << "delay should not be negative"; + DCHECK_EQ(delay_ms, 0) << "delay should not be negative"; } #if defined(OS_WIN) diff --git a/base/message_loop.h b/base/message_loop.h index a92ff7e..d78b58a 100644 --- a/base/message_loop.h +++ b/base/message_loop.h @@ -165,6 +165,10 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate { void PostDelayedTask( const tracked_objects::Location& from_here, + const base::Closure& task, int64 delay_ms); + + void PostDelayedTask( + const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay); @@ -174,6 +178,10 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate { void PostNonNestableDelayedTask( const tracked_objects::Location& from_here, + const base::Closure& task, int64 delay_ms); + + void PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay); @@ -441,7 +449,7 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate { bool DeletePendingTasks(); // Calculates the time at which a PendingTask should run. - base::TimeTicks CalculateDelayedRuntime(base::TimeDelta delay); + base::TimeTicks CalculateDelayedRuntime(int64 delay_ms); // Start recording histogram info about events and action IF it was enabled // and IF the statistics recorder can accept a registration of our histogram. diff --git a/base/message_loop_proxy_impl.cc b/base/message_loop_proxy_impl.cc index b4ca210..9f6cb1f 100644 --- a/base/message_loop_proxy_impl.cc +++ b/base/message_loop_proxy_impl.cc @@ -12,6 +12,24 @@ namespace base { MessageLoopProxyImpl::~MessageLoopProxyImpl() { } +// This function will be removed later in the fixing of CR Bug #108171. +bool MessageLoopProxyImpl::PostDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, + int64 delay_ms) { + return PostDelayedTask( + from_here, task, base::TimeDelta::FromMilliseconds(delay_ms)); +} + +// This function will be removed later in the fixing of CR Bug #108171. +bool MessageLoopProxyImpl::PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, + int64 delay_ms) { + return PostNonNestableDelayedTask( + from_here, task, base::TimeDelta::FromMilliseconds(delay_ms)); +} + bool MessageLoopProxyImpl::PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, diff --git a/base/message_loop_proxy_impl.h b/base/message_loop_proxy_impl.h index fd28194..140c244 100644 --- a/base/message_loop_proxy_impl.h +++ b/base/message_loop_proxy_impl.h @@ -21,10 +21,17 @@ class BASE_EXPORT MessageLoopProxyImpl : public MessageLoopProxy { // MessageLoopProxy implementation virtual bool PostDelayedTask(const tracked_objects::Location& from_here, const base::Closure& task, + int64 delay_ms) OVERRIDE; + virtual bool PostDelayedTask(const tracked_objects::Location& from_here, + const base::Closure& task, base::TimeDelta delay) OVERRIDE; virtual bool PostNonNestableDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, + int64 delay_ms) OVERRIDE; + virtual bool PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, base::TimeDelta delay) OVERRIDE; virtual bool RunsTasksOnCurrentThread() const OVERRIDE; diff --git a/base/sequenced_task_runner.cc b/base/sequenced_task_runner.cc index 00d4048..bab7d1c 100644 --- a/base/sequenced_task_runner.cc +++ b/base/sequenced_task_runner.cc @@ -11,7 +11,7 @@ namespace base { bool SequencedTaskRunner::PostNonNestableTask( const tracked_objects::Location& from_here, const Closure& task) { - return PostNonNestableDelayedTask(from_here, task, base::TimeDelta()); + return PostNonNestableDelayedTask(from_here, task, 0); } bool SequencedTaskRunner::DeleteSoonInternal( diff --git a/base/sequenced_task_runner.h b/base/sequenced_task_runner.h index 5e0c89f..0db9128f 100644 --- a/base/sequenced_task_runner.h +++ b/base/sequenced_task_runner.h @@ -114,6 +114,11 @@ class BASE_EXPORT SequencedTaskRunner : public TaskRunner { virtual bool PostNonNestableDelayedTask( const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms) = 0; + + virtual bool PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, + const Closure& task, base::TimeDelta delay) = 0; // Submits a non-nestable task to delete the given object. Returns diff --git a/base/task_runner.cc b/base/task_runner.cc index b0563d4..734674f 100644 --- a/base/task_runner.cc +++ b/base/task_runner.cc @@ -42,7 +42,7 @@ bool PostTaskAndReplyTaskRunner::PostTask( bool TaskRunner::PostTask(const tracked_objects::Location& from_here, const Closure& task) { - return PostDelayedTask(from_here, task, base::TimeDelta()); + return PostDelayedTask(from_here, task, 0); } bool TaskRunner::PostTaskAndReply( diff --git a/base/task_runner.h b/base/task_runner.h index c1e1758..894eb87 100644 --- a/base/task_runner.h +++ b/base/task_runner.h @@ -72,6 +72,11 @@ class BASE_EXPORT TaskRunner // // It is valid for an implementation to ignore |delay_ms|; that is, // to have PostDelayedTask behave the same as PostTask. + // + // TODO(tedv): Make PostDelayedTask use TimeDelta instead. + virtual bool PostDelayedTask(const tracked_objects::Location& from_here, + const Closure& task, + int64 delay_ms) = 0; virtual bool PostDelayedTask(const tracked_objects::Location& from_here, const Closure& task, base::TimeDelta delay) = 0; diff --git a/base/threading/platform_thread.h b/base/threading/platform_thread.h index fc64f78..3843ce5 100644 --- a/base/threading/platform_thread.h +++ b/base/threading/platform_thread.h @@ -64,6 +64,9 @@ class BASE_EXPORT PlatformThread { // Yield the current thread so another thread can be scheduled. static void YieldCurrentThread(); + // Sleeps for the specified duration (units are milliseconds). + static void Sleep(int duration_ms); + // Sleeps for the specified duration. static void Sleep(base::TimeDelta duration); diff --git a/base/threading/platform_thread_posix.cc b/base/threading/platform_thread_posix.cc index 59162b9..77039a0 100644 --- a/base/threading/platform_thread_posix.cc +++ b/base/threading/platform_thread_posix.cc @@ -176,6 +176,13 @@ void PlatformThread::YieldCurrentThread() { } // static +void PlatformThread::Sleep(int duration_ms) { + // NOTE: This function will be supplanted by the other version of Sleep + // in the future. See issue 108171 for more information. + Sleep(TimeDelta::FromMilliseconds(duration_ms)); +} + +// static void PlatformThread::Sleep(TimeDelta duration) { struct timespec sleep_time, remaining; diff --git a/base/threading/platform_thread_win.cc b/base/threading/platform_thread_win.cc index 82981ad..4dc839b 100644 --- a/base/threading/platform_thread_win.cc +++ b/base/threading/platform_thread_win.cc @@ -110,6 +110,11 @@ void PlatformThread::YieldCurrentThread() { } // static +void PlatformThread::Sleep(int duration_ms) { + ::Sleep(duration_ms); +} + +// static void PlatformThread::Sleep(TimeDelta duration) { ::Sleep(duration.InMillisecondsRoundedUp()); } diff --git a/base/threading/sequenced_worker_pool.cc b/base/threading/sequenced_worker_pool.cc index 3bc26b4..59c4187 100644 --- a/base/threading/sequenced_worker_pool.cc +++ b/base/threading/sequenced_worker_pool.cc @@ -62,6 +62,9 @@ class SequencedWorkerPoolTaskRunner : public TaskRunner { // TaskRunner implementation virtual bool PostDelayedTask(const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms) OVERRIDE; + virtual bool PostDelayedTask(const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay) OVERRIDE; virtual bool RunsTasksOnCurrentThread() const OVERRIDE; @@ -73,6 +76,10 @@ class SequencedWorkerPoolTaskRunner : public TaskRunner { bool PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms); + bool PostDelayedTaskAssertZeroDelay( + const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay); const scoped_refptr<SequencedWorkerPool> pool_; @@ -95,6 +102,13 @@ SequencedWorkerPoolTaskRunner::~SequencedWorkerPoolTaskRunner() { bool SequencedWorkerPoolTaskRunner::PostDelayedTask( const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms) { + return PostDelayedTaskAssertZeroDelay(from_here, task, delay_ms); +} + +bool SequencedWorkerPoolTaskRunner::PostDelayedTask( + const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay) { return PostDelayedTaskAssertZeroDelay(from_here, task, delay); } @@ -106,15 +120,24 @@ bool SequencedWorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { bool SequencedWorkerPoolTaskRunner::PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, const Closure& task, - TimeDelta delay) { + int64 delay_ms) { // TODO(francoisk777@gmail.com): Change the following two statements once // SequencedWorkerPool supports non-zero delays. - DCHECK_EQ(delay.InMillisecondsRoundedUp(), 0) + DCHECK_EQ(delay_ms, 0) << "SequencedWorkerPoolTaskRunner does not yet support non-zero delays"; return pool_->PostWorkerTaskWithShutdownBehavior( from_here, task, shutdown_behavior_); } +bool SequencedWorkerPoolTaskRunner::PostDelayedTaskAssertZeroDelay( + const tracked_objects::Location& from_here, + const Closure& task, + TimeDelta delay) { + return PostDelayedTaskAssertZeroDelay(from_here, + task, + delay.InMillisecondsRoundedUp()); +} + // SequencedWorkerPoolSequencedTaskRunner ------------------------------------ // A SequencedTaskRunner which posts tasks to a SequencedWorkerPool with a // fixed sequence token. @@ -130,6 +153,9 @@ class SequencedWorkerPoolSequencedTaskRunner : public SequencedTaskRunner { // TaskRunner implementation virtual bool PostDelayedTask(const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms) OVERRIDE; + virtual bool PostDelayedTask(const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay) OVERRIDE; virtual bool RunsTasksOnCurrentThread() const OVERRIDE; @@ -137,6 +163,10 @@ class SequencedWorkerPoolSequencedTaskRunner : public SequencedTaskRunner { virtual bool PostNonNestableDelayedTask( const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms) OVERRIDE; + virtual bool PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay) OVERRIDE; private: @@ -147,6 +177,10 @@ class SequencedWorkerPoolSequencedTaskRunner : public SequencedTaskRunner { bool PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms); + bool PostDelayedTaskAssertZeroDelay( + const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay); const scoped_refptr<SequencedWorkerPool> pool_; @@ -174,6 +208,13 @@ SequencedWorkerPoolSequencedTaskRunner:: bool SequencedWorkerPoolSequencedTaskRunner::PostDelayedTask( const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms) { + return PostDelayedTaskAssertZeroDelay(from_here, task, delay_ms); +} + +bool SequencedWorkerPoolSequencedTaskRunner::PostDelayedTask( + const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay) { return PostDelayedTaskAssertZeroDelay(from_here, task, delay); } @@ -185,6 +226,13 @@ bool SequencedWorkerPoolSequencedTaskRunner::RunsTasksOnCurrentThread() const { bool SequencedWorkerPoolSequencedTaskRunner::PostNonNestableDelayedTask( const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms) { + return PostDelayedTaskAssertZeroDelay(from_here, task, delay_ms); +} + +bool SequencedWorkerPoolSequencedTaskRunner::PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay) { return PostDelayedTaskAssertZeroDelay(from_here, task, delay); } @@ -192,16 +240,25 @@ bool SequencedWorkerPoolSequencedTaskRunner::PostNonNestableDelayedTask( bool SequencedWorkerPoolSequencedTaskRunner::PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, const Closure& task, - TimeDelta delay) { + int64 delay_ms) { // TODO(francoisk777@gmail.com): Change the following two statements once // SequencedWorkerPool supports non-zero delays. - DCHECK_EQ(delay.InMillisecondsRoundedUp(), 0) + DCHECK_EQ(delay_ms, 0) << "SequencedWorkerPoolSequencedTaskRunner does not yet support non-zero" " delays"; return pool_->PostSequencedWorkerTaskWithShutdownBehavior( token_, from_here, task, shutdown_behavior_); } +bool SequencedWorkerPoolSequencedTaskRunner::PostDelayedTaskAssertZeroDelay( + const tracked_objects::Location& from_here, + const Closure& task, + TimeDelta delay) { + return PostDelayedTaskAssertZeroDelay(from_here, + task, + delay.InMillisecondsRoundedUp()); +} + } // namespace // Worker --------------------------------------------------------------------- @@ -976,6 +1033,15 @@ bool SequencedWorkerPool::PostSequencedWorkerTaskWithShutdownBehavior( bool SequencedWorkerPool::PostDelayedTask( const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms) { + // TODO(akalin): Add support for non-zero delays. + DCHECK_EQ(delay_ms, 0); + return PostWorkerTask(from_here, task); +} + +bool SequencedWorkerPool::PostDelayedTask( + const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay) { // TODO(akalin): Add support for non-zero delays. DCHECK_EQ(delay.InMillisecondsRoundedUp(), 0); diff --git a/base/threading/sequenced_worker_pool.h b/base/threading/sequenced_worker_pool.h index 73c670f..740c26d 100644 --- a/base/threading/sequenced_worker_pool.h +++ b/base/threading/sequenced_worker_pool.h @@ -231,6 +231,9 @@ class BASE_EXPORT SequencedWorkerPool : public TaskRunner { // TaskRunner implementation. Forwards to PostWorkerTask(). virtual bool PostDelayedTask(const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms) OVERRIDE; + virtual bool PostDelayedTask(const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay) OVERRIDE; virtual bool RunsTasksOnCurrentThread() const OVERRIDE; diff --git a/base/threading/sequenced_worker_pool_task_runner.cc b/base/threading/sequenced_worker_pool_task_runner.cc deleted file mode 100644 index b7579a7..0000000 --- a/base/threading/sequenced_worker_pool_task_runner.cc +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/threading/sequenced_worker_pool_task_runner.h" - -#include "base/callback.h" -#include "base/location.h" -#include "base/logging.h" - -namespace base { - -SequencedWorkerPoolTaskRunner::SequencedWorkerPoolTaskRunner( - const scoped_refptr<SequencedWorkerPool>& pool, - SequencedWorkerPool::SequenceToken token) - : pool_(pool), - token_(token) { -} - -SequencedWorkerPoolTaskRunner::~SequencedWorkerPoolTaskRunner() { -} - -bool SequencedWorkerPoolTaskRunner::PostDelayedTask( - const tracked_objects::Location& from_here, - const Closure& task, - TimeDelta delay) { - return PostDelayedTaskAssertZeroDelay(from_here, task, delay); -} - -bool SequencedWorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { - return pool_->IsRunningSequenceOnCurrentThread(token_); -} - -bool SequencedWorkerPoolTaskRunner::PostNonNestableDelayedTask( - const tracked_objects::Location& from_here, - const Closure& task, - TimeDelta delay) { - return PostDelayedTaskAssertZeroDelay(from_here, task, delay); -} - -bool SequencedWorkerPoolTaskRunner::PostDelayedTaskAssertZeroDelay( - const tracked_objects::Location& from_here, - const Closure& task, - TimeDelta delay) { - // TODO(francoisk777@gmail.com): Change the following two statements once - // SequencedWorkerPool supports non-zero delays. - DCHECK_EQ(delay.InMillisecondsRoundedUp(), 0) - << "SequencedWorkerPoolTaskRunner does not yet support non-zero delays"; - return pool_->PostSequencedWorkerTask(token_, from_here, task); -} - -} // namespace base diff --git a/base/threading/sequenced_worker_pool_task_runner.h b/base/threading/sequenced_worker_pool_task_runner.h deleted file mode 100644 index 6827663..0000000 --- a/base/threading/sequenced_worker_pool_task_runner.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BASE_THREADING_SEQUENCED_WORKER_POOL_TASK_RUNNER_H_ -#define BASE_THREADING_SEQUENCED_WORKER_POOL_TASK_RUNNER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/callback_forward.h" -#include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" -#include "base/sequenced_task_runner.h" -#include "base/threading/sequenced_worker_pool.h" -#include "base/time.h" - -namespace tracked_objects { -class Location; -} // namespace tracked_objects - -namespace base { - -// A SequencedTaskRunner which posts tasks to a SequencedWorkerPool with a -// fixed sequence token. -// -// Note that this class is RefCountedThreadSafe (inherited from TaskRunner). -class BASE_EXPORT SequencedWorkerPoolTaskRunner : public SequencedTaskRunner { - public: - SequencedWorkerPoolTaskRunner(const scoped_refptr<SequencedWorkerPool>& pool, - SequencedWorkerPool::SequenceToken token); - - // TaskRunner implementation - virtual bool PostDelayedTask(const tracked_objects::Location& from_here, - const Closure& task, - TimeDelta delay) OVERRIDE; - virtual bool RunsTasksOnCurrentThread() const OVERRIDE; - - // SequencedTaskRunner implementation - virtual bool PostNonNestableDelayedTask( - const tracked_objects::Location& from_here, - const Closure& task, - TimeDelta delay) OVERRIDE; - - private: - virtual ~SequencedWorkerPoolTaskRunner(); - - // Helper function for posting a delayed task. Asserts that the delay is - // zero because non-zero delays are not yet supported. - bool PostDelayedTaskAssertZeroDelay( - const tracked_objects::Location& from_here, - const Closure& task, - TimeDelta delay); - - const scoped_refptr<SequencedWorkerPool> pool_; - - const SequencedWorkerPool::SequenceToken token_; - - DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolTaskRunner); -}; - -} // namespace base - -#endif // BASE_THREADING_SEQUENCED_TASK_RUNNER_IMPL_H_ diff --git a/base/threading/worker_pool.cc b/base/threading/worker_pool.cc index 16cc061..978584c 100644 --- a/base/threading/worker_pool.cc +++ b/base/threading/worker_pool.cc @@ -41,6 +41,9 @@ class WorkerPoolTaskRunner : public TaskRunner { // TaskRunner implementation virtual bool PostDelayedTask(const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms) OVERRIDE; + virtual bool PostDelayedTask(const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay) OVERRIDE; virtual bool RunsTasksOnCurrentThread() const OVERRIDE; @@ -52,7 +55,7 @@ class WorkerPoolTaskRunner : public TaskRunner { bool PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, const Closure& task, - base::TimeDelta delay); + int64 delay_ms); const bool tasks_are_slow_; @@ -69,8 +72,15 @@ WorkerPoolTaskRunner::~WorkerPoolTaskRunner() { bool WorkerPoolTaskRunner::PostDelayedTask( const tracked_objects::Location& from_here, const Closure& task, + int64 delay_ms) { + return PostDelayedTaskAssertZeroDelay(from_here, task, delay_ms); +} + +bool WorkerPoolTaskRunner::PostDelayedTask( + const tracked_objects::Location& from_here, + const Closure& task, TimeDelta delay) { - return PostDelayedTaskAssertZeroDelay(from_here, task, delay); + return PostDelayedTask(from_here, task, delay.InMillisecondsRoundedUp()); } bool WorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { @@ -80,8 +90,8 @@ bool WorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { bool WorkerPoolTaskRunner::PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, const Closure& task, - base::TimeDelta delay) { - DCHECK_EQ(delay.InMillisecondsRoundedUp(), 0) + int64 delay_ms) { + DCHECK_EQ(delay_ms, 0) << "WorkerPoolTaskRunner does not support non-zero delays"; return WorkerPool::PostTask(from_here, task, tasks_are_slow_); } diff --git a/chrome/browser/policy/cloud_policy_refresh_scheduler_unittest.cc b/chrome/browser/policy/cloud_policy_refresh_scheduler_unittest.cc index ae3d6c1..32920c5 100644 --- a/chrome/browser/policy/cloud_policy_refresh_scheduler_unittest.cc +++ b/chrome/browser/policy/cloud_policy_refresh_scheduler_unittest.cc @@ -35,6 +35,12 @@ class TestTaskRunner : public base::TaskRunner { TestTaskRunner() {} virtual bool RunsTasksOnCurrentThread() const OVERRIDE { return true; } + virtual bool PostDelayedTask(const tracked_objects::Location&, + const base::Closure&, + int64) OVERRIDE { + ADD_FAILURE(); + return false; + } MOCK_METHOD3(PostDelayedTask, bool(const tracked_objects::Location&, const base::Closure&, base::TimeDelta)); diff --git a/cloud_print/service/win/service_state.cc b/cloud_print/service/win/service_state.cc index 5c1453f..8641000 100644 --- a/cloud_print/service/win/service_state.cc +++ b/cloud_print/service/win/service_state.cc @@ -180,9 +180,8 @@ std::string ServiceState::LoginToGoogle(const std::string& service, request.set_method("POST"); request.Start(); - MessageLoop::current()->PostDelayedTask(FROM_HERE, - MessageLoop::QuitClosure(), - base::TimeDelta::FromMilliseconds(kRequestTimeoutMs)); + MessageLoop::current()->PostDelayedTask( + FROM_HERE, MessageLoop::QuitClosure(), kRequestTimeoutMs); MessageLoop::current()->Run(); diff --git a/content/browser/browser_thread_impl.cc b/content/browser/browser_thread_impl.cc index 13ab5a5..297bb30 100644 --- a/content/browser/browser_thread_impl.cc +++ b/content/browser/browser_thread_impl.cc @@ -186,6 +186,11 @@ class BrowserThreadMessageLoopProxy : public base::MessageLoopProxy { // MessageLoopProxy implementation. virtual bool PostDelayedTask( const tracked_objects::Location& from_here, + const base::Closure& task, int64 delay_ms) OVERRIDE { + return BrowserThread::PostDelayedTask(id_, from_here, task, delay_ms); + } + virtual bool PostDelayedTask( + const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay) OVERRIDE { return BrowserThread::PostDelayedTask(id_, from_here, task, delay); } @@ -193,6 +198,13 @@ class BrowserThreadMessageLoopProxy : public base::MessageLoopProxy { virtual bool PostNonNestableDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, + int64 delay_ms) OVERRIDE { + return BrowserThread::PostNonNestableDelayedTask(id_, from_here, task, + delay_ms); + } + virtual bool PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, base::TimeDelta delay) OVERRIDE { return BrowserThread::PostNonNestableDelayedTask(id_, from_here, task, delay); @@ -289,6 +301,19 @@ bool BrowserThread::PostTask(ID identifier, bool BrowserThread::PostDelayedTask(ID identifier, const tracked_objects::Location& from_here, const base::Closure& task, + int64 delay_ms) { + return BrowserThreadImpl::PostTaskHelper( + identifier, + from_here, + task, + base::TimeDelta::FromMilliseconds(delay_ms), + true); +} + +// static +bool BrowserThread::PostDelayedTask(ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, base::TimeDelta delay) { return BrowserThreadImpl::PostTaskHelper( identifier, from_here, task, delay, true); @@ -308,6 +333,20 @@ bool BrowserThread::PostNonNestableDelayedTask( ID identifier, const tracked_objects::Location& from_here, const base::Closure& task, + int64 delay_ms) { + return BrowserThreadImpl::PostTaskHelper( + identifier, + from_here, + task, + base::TimeDelta::FromMilliseconds(delay_ms), + false); +} + +// static +bool BrowserThread::PostNonNestableDelayedTask( + ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, base::TimeDelta delay) { return BrowserThreadImpl::PostTaskHelper( identifier, from_here, task, delay, false); diff --git a/content/browser/download/byte_stream_unittest.cc b/content/browser/download/byte_stream_unittest.cc index 42f08ec..44bca9a 100644 --- a/content/browser/download/byte_stream_unittest.cc +++ b/content/browser/download/byte_stream_unittest.cc @@ -33,11 +33,18 @@ class MockTaskRunner : public base::SequencedTaskRunner { // TaskRunner functions. MOCK_METHOD3(PostDelayedTask, bool(const tracked_objects::Location&, + const base::Closure&, int64)); + MOCK_METHOD3(PostDelayedTask, bool(const tracked_objects::Location&, const base::Closure&, base::TimeDelta)); MOCK_METHOD3(PostNonNestableDelayedTask, bool( const tracked_objects::Location&, const base::Closure&, + int64 delay_ms)); + + MOCK_METHOD3(PostNonNestableDelayedTask, bool( + const tracked_objects::Location&, + const base::Closure&, base::TimeDelta)); MOCK_CONST_METHOD0(RunsTasksOnCurrentThread, bool()); @@ -330,7 +337,7 @@ TEST_F(ByteStreamTest, ByteStream_SinkCallback) { int num_callbacks = 0; byte_stream_output->RegisterCallback( base::Bind(CountCallbacks, &num_callbacks)); - EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, base::TimeDelta())) + EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), Return(true))); @@ -404,7 +411,7 @@ TEST_F(ByteStreamTest, ByteStream_SourceCallback) { EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); // Setup expectations. - EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, base::TimeDelta())) + EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), Return(true))); @@ -423,7 +430,7 @@ TEST_F(ByteStreamTest, ByteStream_SourceCallback) { EXPECT_EQ(1, num_callbacks); // Same drill with final buffer. - EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, base::TimeDelta())) + EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), Return(true))); EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, @@ -462,7 +469,7 @@ TEST_F(ByteStreamTest, ByteStream_SinkInterrupt) { int num_callbacks = 0; byte_stream_output->RegisterCallback( base::Bind(CountCallbacks, &num_callbacks)); - EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, base::TimeDelta())) + EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), Return(true))); @@ -528,7 +535,7 @@ TEST_F(ByteStreamTest, ByteStream_SourceInterrupt) { message_loop_.RunAllPending(); // Setup expectations. - EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, base::TimeDelta())) + EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), Return(true))); @@ -549,7 +556,7 @@ TEST_F(ByteStreamTest, ByteStream_SourceInterrupt) { EXPECT_EQ(1, num_alt_callbacks); // Third get should also trigger callback. - EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, base::TimeDelta())) + EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), Return(true))); EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, @@ -581,7 +588,7 @@ TEST_F(ByteStreamTest, ByteStream_ZeroCallback) { int num_callbacks = 0; byte_stream_output->RegisterCallback( base::Bind(CountCallbacks, &num_callbacks)); - EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, base::TimeDelta())) + EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), Return(true))); diff --git a/content/public/browser/browser_thread.h b/content/public/browser/browser_thread.h index bf6a763..0ac582b 100644 --- a/content/public/browser/browser_thread.h +++ b/content/public/browser/browser_thread.h @@ -110,6 +110,10 @@ class CONTENT_EXPORT BrowserThread { static bool PostDelayedTask(ID identifier, const tracked_objects::Location& from_here, const base::Closure& task, + int64 delay_ms); + static bool PostDelayedTask(ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, base::TimeDelta delay); static bool PostNonNestableTask(ID identifier, const tracked_objects::Location& from_here, @@ -118,6 +122,11 @@ class CONTENT_EXPORT BrowserThread { ID identifier, const tracked_objects::Location& from_here, const base::Closure& task, + int64 delay_ms); + static bool PostNonNestableDelayedTask( + ID identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, base::TimeDelta delay); static bool PostTaskAndReply( diff --git a/remoting/base/plugin_message_loop_proxy.cc b/remoting/base/plugin_message_loop_proxy.cc index ad595c8..9d9a599 100644 --- a/remoting/base/plugin_message_loop_proxy.cc +++ b/remoting/base/plugin_message_loop_proxy.cc @@ -27,6 +27,14 @@ void PluginMessageLoopProxy::Detach() { bool PluginMessageLoopProxy::PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, + int64 delay_ms) { + return PostDelayedTask( + from_here, task, base::TimeDelta::FromMilliseconds(delay_ms)); +} + +bool PluginMessageLoopProxy::PostDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, base::TimeDelta delay) { base::AutoLock auto_lock(lock_); if (!delegate_) @@ -41,6 +49,14 @@ bool PluginMessageLoopProxy::PostDelayedTask( bool PluginMessageLoopProxy::PostNonNestableDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, + int64 delay_ms) { + // All tasks running on this message loop are non-nestable. + return PostDelayedTask(from_here, task, delay_ms); +} + +bool PluginMessageLoopProxy::PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, base::TimeDelta delay) { // All tasks running on this message loop are non-nestable. return PostDelayedTask(from_here, task, delay); diff --git a/remoting/base/plugin_message_loop_proxy.h b/remoting/base/plugin_message_loop_proxy.h index 1088344..23e2c7a 100644 --- a/remoting/base/plugin_message_loop_proxy.h +++ b/remoting/base/plugin_message_loop_proxy.h @@ -34,10 +34,18 @@ class PluginMessageLoopProxy : public base::MessageLoopProxy { virtual bool PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, + int64 delay_ms) OVERRIDE; + virtual bool PostDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, base::TimeDelta delay) OVERRIDE; virtual bool PostNonNestableDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, + int64 delay_ms) OVERRIDE; + virtual bool PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, base::TimeDelta delay) OVERRIDE; virtual bool RunsTasksOnCurrentThread() const OVERRIDE; diff --git a/remoting/base/scoped_thread_proxy.cc b/remoting/base/scoped_thread_proxy.cc index 7209a52..d1dcc26 100644 --- a/remoting/base/scoped_thread_proxy.cc +++ b/remoting/base/scoped_thread_proxy.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -24,9 +24,9 @@ class ScopedThreadProxy::Core : public base::RefCountedThreadSafe<Core> { void PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& closure, - base::TimeDelta delay) { + int64 delay_ms) { if (!canceled_) { - message_loop_->PostDelayedTask(from_here, Wrap(closure), delay); + message_loop_->PostDelayedTask(from_here, Wrap(closure), delay_ms); } } @@ -75,8 +75,8 @@ void ScopedThreadProxy::PostTask(const tracked_objects::Location& from_here, void ScopedThreadProxy::PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& closure, - base::TimeDelta delay) { - core_->PostDelayedTask(from_here, closure, delay); + int64 delay_ms) { + core_->PostDelayedTask(from_here, closure, delay_ms); } void ScopedThreadProxy::Detach() { diff --git a/remoting/base/scoped_thread_proxy.h b/remoting/base/scoped_thread_proxy.h index 8e69d8f..9e43a15 100644 --- a/remoting/base/scoped_thread_proxy.h +++ b/remoting/base/scoped_thread_proxy.h @@ -54,7 +54,7 @@ class ScopedThreadProxy { const base::Closure& closure); void PostDelayedTask(const tracked_objects::Location& from_here, const base::Closure& closure, - base::TimeDelta delay); + int64 delay_ms); // Cancels all tasks posted via this proxy. Must be called on the // thread this object belongs to. diff --git a/remoting/host/it2me_host_user_interface.cc b/remoting/host/it2me_host_user_interface.cc index 3edb144..c39f6d3 100644 --- a/remoting/host/it2me_host_user_interface.cc +++ b/remoting/host/it2me_host_user_interface.cc @@ -30,8 +30,7 @@ class It2MeHostUserInterface::TimerTask { const base::Closure& task, int delay_ms) : thread_proxy_(message_loop) { - thread_proxy_.PostDelayedTask( - FROM_HERE, task, base::TimeDelta::FromMilliseconds(delay_ms)); + thread_proxy_.PostDelayedTask(FROM_HERE, task, delay_ms); } private: diff --git a/webkit/dom_storage/dom_storage_task_runner.cc b/webkit/dom_storage/dom_storage_task_runner.cc index 9935ad7..f25699c 100644 --- a/webkit/dom_storage/dom_storage_task_runner.cc +++ b/webkit/dom_storage/dom_storage_task_runner.cc @@ -17,6 +17,14 @@ bool DomStorageTaskRunner::RunsTasksOnCurrentThread() const { return IsRunningOnSequence(PRIMARY_SEQUENCE); } +bool DomStorageTaskRunner::PostDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, + int64 delay_ms) { + return PostDelayedTask( + from_here, task, base::TimeDelta::FromMilliseconds(delay_ms)); +} + // DomStorageWorkerPoolTaskRunner DomStorageWorkerPoolTaskRunner::DomStorageWorkerPoolTaskRunner( diff --git a/webkit/dom_storage/dom_storage_task_runner.h b/webkit/dom_storage/dom_storage_task_runner.h index 4266509..eb9da80 100644 --- a/webkit/dom_storage/dom_storage_task_runner.h +++ b/webkit/dom_storage/dom_storage_task_runner.h @@ -59,6 +59,13 @@ class DomStorageTaskRunner : public base::TaskRunner { return IsRunningOnSequence(COMMIT_SEQUENCE); } + // DEPRECATED: Only here because base::TaskRunner requires it, implemented + // by calling the virtual PostDelayedTask(..., TimeDelta) variant. + virtual bool PostDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, + int64 delay_ms) OVERRIDE; + protected: virtual ~DomStorageTaskRunner() {} }; |