diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 23:16:45 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 23:16:45 +0000 |
commit | 4f9113b5f4ba5960af4b4a0e1bb6de7605088fc8 (patch) | |
tree | c7318e3e513a2b9d41c3b481c93ea46694a4a97f | |
parent | 68a7dd361794f9c28de6801cfcbf9cc1cc8106e8 (diff) | |
download | chromium_src-4f9113b5f4ba5960af4b4a0e1bb6de7605088fc8.zip chromium_src-4f9113b5f4ba5960af4b4a0e1bb6de7605088fc8.tar.gz chromium_src-4f9113b5f4ba5960af4b4a0e1bb6de7605088fc8.tar.bz2 |
Derive DomStorageTaskRunner from base::TaskRunner now that it exists.
BUG=106763
Review URL: https://chromiumcodereview.appspot.com/9689033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126500 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/dom_storage/dom_storage_task_runner.cc | 45 | ||||
-rw-r--r-- | webkit/dom_storage/dom_storage_task_runner.h | 35 |
2 files changed, 47 insertions, 33 deletions
diff --git a/webkit/dom_storage/dom_storage_task_runner.cc b/webkit/dom_storage/dom_storage_task_runner.cc index 3ea1b3a..050cf16 100644 --- a/webkit/dom_storage/dom_storage_task_runner.cc +++ b/webkit/dom_storage/dom_storage_task_runner.cc @@ -21,47 +21,53 @@ DomStorageTaskRunner::DomStorageTaskRunner( DomStorageTaskRunner::~DomStorageTaskRunner() { } -bool DomStorageTaskRunner::PostTask( +bool DomStorageTaskRunner::PostDelayedTask( const tracked_objects::Location& from_here, - const base::Closure& task) { - return message_loop_->PostTask(from_here, task); + const base::Closure& task, + base::TimeDelta delay) { + return message_loop_->PostDelayedTask(from_here, task, delay); } bool DomStorageTaskRunner::PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, - base::TimeDelta delay) { - return message_loop_->PostDelayedTask(from_here, task, delay); + int64 delay_ms) { + return PostDelayedTask( + from_here, task, base::TimeDelta::FromMilliseconds(delay_ms)); +} + +bool DomStorageTaskRunner::RunsTasksOnCurrentThread() const { + return true; } // DomStorageWorkerPoolTaskRunner DomStorageWorkerPoolTaskRunner::DomStorageWorkerPoolTaskRunner( base::SequencedWorkerPool* sequenced_worker_pool, + base::SequencedWorkerPool::SequenceToken sequence_token, base::MessageLoopProxy* delayed_task_loop) : DomStorageTaskRunner(delayed_task_loop), sequenced_worker_pool_(sequenced_worker_pool), - sequence_token_( - sequenced_worker_pool->GetNamedSequenceToken("dom_storage_token")) { + sequence_token_(sequence_token) { } DomStorageWorkerPoolTaskRunner::~DomStorageWorkerPoolTaskRunner() { } -bool DomStorageWorkerPoolTaskRunner::PostTask( - const tracked_objects::Location& from_here, - const base::Closure& task) { - // We can skip on shutdown as the destructor of DomStorageArea will ensure - // that any remaining data is committed to disk. - return sequenced_worker_pool_->PostSequencedWorkerTaskWithShutdownBehavior( - sequence_token_, from_here, task, - base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); -} - bool DomStorageWorkerPoolTaskRunner::PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay) { + // Note base::TaskRunner implements PostTask in terms of PostDelayedTask + // with a delay of zero, we detect that usage and avoid the unecessary + // trip thru the message_loop. + if (delay == base::TimeDelta()) { + // We can skip on shutdown as the destructor of DomStorageArea will ensure + // that any remaining data is committed to disk. + return sequenced_worker_pool_->PostSequencedWorkerTaskWithShutdownBehavior( + sequence_token_, from_here, task, + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); + } // Post a task to call this->PostTask() after the delay. return message_loop_->PostDelayedTask( FROM_HERE, @@ -81,8 +87,9 @@ bool MockDomStorageTaskRunner::PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay) { - // Don't wait in unit tests. - return PostTask(from_here, task); + // Squash all delays to zero in our mock. + return DomStorageTaskRunner::PostDelayedTask( + from_here, task, base::TimeDelta()); } } // namespace dom_storage diff --git a/webkit/dom_storage/dom_storage_task_runner.h b/webkit/dom_storage/dom_storage_task_runner.h index 4c5600e..9fde32f 100644 --- a/webkit/dom_storage/dom_storage_task_runner.h +++ b/webkit/dom_storage/dom_storage_task_runner.h @@ -7,6 +7,7 @@ #pragma once #include "base/memory/ref_counted.h" +#include "base/task_runner.h" #include "base/threading/sequenced_worker_pool.h" #include "base/time.h" @@ -18,23 +19,31 @@ namespace dom_storage { // Tasks must run serially with respect to one another, but may // execute on different OS threads. The base class is implemented -// in terms of a MessageLoopProxy for use in testing. -class DomStorageTaskRunner - : public base::RefCountedThreadSafe<DomStorageTaskRunner> { +// in terms of a MessageLoopProxy. +class DomStorageTaskRunner : public base::TaskRunner { public: explicit DomStorageTaskRunner(base::MessageLoopProxy* message_loop); virtual ~DomStorageTaskRunner(); - // Schedules a task to be run immediately. - virtual bool PostTask( - const tracked_objects::Location& from_here, - const base::Closure& task); + // The PostTask() method, defined by TaskRunner, schedules a task + // to run immediately. // Schedules a task to be run after a delay. virtual bool PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, - base::TimeDelta delay); + base::TimeDelta delay) OVERRIDE; + + // 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; + + // Only here because base::TaskRunner requires it, the return + // value is hard coded to true. + virtual bool RunsTasksOnCurrentThread() const OVERRIDE; protected: const scoped_refptr<base::MessageLoopProxy> message_loop_; @@ -47,20 +56,18 @@ class DomStorageWorkerPoolTaskRunner : public DomStorageTaskRunner { public: DomStorageWorkerPoolTaskRunner( base::SequencedWorkerPool* sequenced_worker_pool, + base::SequencedWorkerPool::SequenceToken sequence_token, base::MessageLoopProxy* delayed_task_loop); virtual ~DomStorageWorkerPoolTaskRunner(); - // Schedules a sequenced worker task to be run immediately. - virtual bool PostTask( - const tracked_objects::Location& from_here, - const base::Closure& task) OVERRIDE; - // Schedules a sequenced worker task to be run after a delay. virtual bool PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay) OVERRIDE; + base::SequencedWorkerPool::SequenceToken sequence_token() const; + private: const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; base::SequencedWorkerPool::SequenceToken sequence_token_; @@ -72,7 +79,7 @@ class DomStorageWorkerPoolTaskRunner : public DomStorageTaskRunner { class MockDomStorageTaskRunner : public DomStorageTaskRunner { public: explicit MockDomStorageTaskRunner(base::MessageLoopProxy* message_loop); - virtual ~MockDomStorageTaskRunner() { } + virtual ~MockDomStorageTaskRunner() {} virtual bool PostDelayedTask( const tracked_objects::Location& from_here, |