diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/message_loop.cc | 51 | ||||
-rw-r--r-- | base/message_loop.h | 10 | ||||
-rw-r--r-- | base/message_loop_proxy_impl.cc | 18 | ||||
-rw-r--r-- | base/message_loop_proxy_impl.h | 7 | ||||
-rw-r--r-- | base/sequenced_task_runner.cc | 2 | ||||
-rw-r--r-- | base/sequenced_task_runner.h | 5 | ||||
-rw-r--r-- | base/task_runner.cc | 2 | ||||
-rw-r--r-- | base/task_runner.h | 5 | ||||
-rw-r--r-- | base/threading/platform_thread.h | 3 | ||||
-rw-r--r-- | base/threading/platform_thread_posix.cc | 7 | ||||
-rw-r--r-- | base/threading/platform_thread_win.cc | 5 | ||||
-rw-r--r-- | base/threading/sequenced_worker_pool.cc | 74 | ||||
-rw-r--r-- | base/threading/sequenced_worker_pool.h | 3 | ||||
-rw-r--r-- | base/threading/sequenced_worker_pool_task_runner.cc | 52 | ||||
-rw-r--r-- | base/threading/sequenced_worker_pool_task_runner.h | 63 | ||||
-rw-r--r-- | base/threading/worker_pool.cc | 18 |
16 files changed, 146 insertions, 179 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc index a207659..b040ecc 100644 --- a/base/message_loop.cc +++ b/base/message_loop.cc @@ -258,48 +258,38 @@ 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) { + const tracked_objects::Location& from_here, + const base::Closure& task) { 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 +533,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 +545,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 +556,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) diff --git a/base/message_loop.h b/base/message_loop.h index d78b58a..a92ff7e 100644 --- a/base/message_loop.h +++ b/base/message_loop.h @@ -165,10 +165,6 @@ 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); @@ -178,10 +174,6 @@ 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); @@ -449,7 +441,7 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate { bool DeletePendingTasks(); // Calculates the time at which a PendingTask should run. - base::TimeTicks CalculateDelayedRuntime(int64 delay_ms); + base::TimeTicks CalculateDelayedRuntime(base::TimeDelta delay); // 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 9f6cb1f..b4ca210 100644 --- a/base/message_loop_proxy_impl.cc +++ b/base/message_loop_proxy_impl.cc @@ -12,24 +12,6 @@ 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 140c244..fd28194 100644 --- a/base/message_loop_proxy_impl.h +++ b/base/message_loop_proxy_impl.h @@ -21,17 +21,10 @@ 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 bab7d1c..00d4048 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, 0); + return PostNonNestableDelayedTask(from_here, task, base::TimeDelta()); } bool SequencedTaskRunner::DeleteSoonInternal( diff --git a/base/sequenced_task_runner.h b/base/sequenced_task_runner.h index 0db9128f..5e0c89f 100644 --- a/base/sequenced_task_runner.h +++ b/base/sequenced_task_runner.h @@ -114,11 +114,6 @@ 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 734674f..b0563d4 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, 0); + return PostDelayedTask(from_here, task, base::TimeDelta()); } bool TaskRunner::PostTaskAndReply( diff --git a/base/task_runner.h b/base/task_runner.h index 894eb87..c1e1758 100644 --- a/base/task_runner.h +++ b/base/task_runner.h @@ -72,11 +72,6 @@ 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 3843ce5..fc64f78 100644 --- a/base/threading/platform_thread.h +++ b/base/threading/platform_thread.h @@ -64,9 +64,6 @@ 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 77039a0..59162b9 100644 --- a/base/threading/platform_thread_posix.cc +++ b/base/threading/platform_thread_posix.cc @@ -176,13 +176,6 @@ 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 4dc839b..82981ad 100644 --- a/base/threading/platform_thread_win.cc +++ b/base/threading/platform_thread_win.cc @@ -110,11 +110,6 @@ 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 59c4187..3bc26b4 100644 --- a/base/threading/sequenced_worker_pool.cc +++ b/base/threading/sequenced_worker_pool.cc @@ -62,9 +62,6 @@ 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; @@ -76,10 +73,6 @@ 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_; @@ -102,13 +95,6 @@ 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); } @@ -120,24 +106,15 @@ bool SequencedWorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { bool SequencedWorkerPoolTaskRunner::PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, const Closure& task, - int64 delay_ms) { + TimeDelta delay) { // TODO(francoisk777@gmail.com): Change the following two statements once // SequencedWorkerPool supports non-zero delays. - DCHECK_EQ(delay_ms, 0) + DCHECK_EQ(delay.InMillisecondsRoundedUp(), 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. @@ -153,9 +130,6 @@ 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; @@ -163,10 +137,6 @@ 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: @@ -177,10 +147,6 @@ 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_; @@ -208,13 +174,6 @@ 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); } @@ -226,13 +185,6 @@ 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); } @@ -240,25 +192,16 @@ bool SequencedWorkerPoolSequencedTaskRunner::PostNonNestableDelayedTask( bool SequencedWorkerPoolSequencedTaskRunner::PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, const Closure& task, - int64 delay_ms) { + TimeDelta delay) { // TODO(francoisk777@gmail.com): Change the following two statements once // SequencedWorkerPool supports non-zero delays. - DCHECK_EQ(delay_ms, 0) + DCHECK_EQ(delay.InMillisecondsRoundedUp(), 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 --------------------------------------------------------------------- @@ -1033,15 +976,6 @@ 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 740c26d..73c670f 100644 --- a/base/threading/sequenced_worker_pool.h +++ b/base/threading/sequenced_worker_pool.h @@ -231,9 +231,6 @@ 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 new file mode 100644 index 0000000..b7579a7 --- /dev/null +++ b/base/threading/sequenced_worker_pool_task_runner.cc @@ -0,0 +1,52 @@ +// 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 new file mode 100644 index 0000000..068fb3e --- /dev/null +++ b/base/threading/sequenced_worker_pool_task_runner.h @@ -0,0 +1,63 @@ +// 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_WORKER_POOL_TASK_RUNNER_H_ diff --git a/base/threading/worker_pool.cc b/base/threading/worker_pool.cc index 978584c..16cc061 100644 --- a/base/threading/worker_pool.cc +++ b/base/threading/worker_pool.cc @@ -41,9 +41,6 @@ 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; @@ -55,7 +52,7 @@ class WorkerPoolTaskRunner : public TaskRunner { bool PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, const Closure& task, - int64 delay_ms); + base::TimeDelta delay); const bool tasks_are_slow_; @@ -72,15 +69,8 @@ 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 PostDelayedTask(from_here, task, delay.InMillisecondsRoundedUp()); + return PostDelayedTaskAssertZeroDelay(from_here, task, delay); } bool WorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { @@ -90,8 +80,8 @@ bool WorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { bool WorkerPoolTaskRunner::PostDelayedTaskAssertZeroDelay( const tracked_objects::Location& from_here, const Closure& task, - int64 delay_ms) { - DCHECK_EQ(delay_ms, 0) + base::TimeDelta delay) { + DCHECK_EQ(delay.InMillisecondsRoundedUp(), 0) << "WorkerPoolTaskRunner does not support non-zero delays"; return WorkerPool::PostTask(from_here, task, tasks_are_slow_); } |