diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 01:43:19 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 01:43:19 +0000 |
commit | 6b28d9469f63df13c9918d5f2d8d24ba8b9893a5 (patch) | |
tree | 195a09586b5388359914e63ebeca1aa66a2516fe /base/task_runner.cc | |
parent | 1005065913ee5ced3fd8fc915d31e0c0461e2b1d (diff) | |
download | chromium_src-6b28d9469f63df13c9918d5f2d8d24ba8b9893a5.zip chromium_src-6b28d9469f63df13c9918d5f2d8d24ba8b9893a5.tar.gz chromium_src-6b28d9469f63df13c9918d5f2d8d24ba8b9893a5.tar.bz2 |
Make new TaskRunner, SequencedTaskRunner, and SingleThreadTaskRunner interfaces
TaskRunner just has Post{,Delayed}Task(), SequencedTaskRunner
extends Executor to have ordering guarantees and PostNonNestable{,Delayed}Task(), and SingleThreadTaskRunner extends SequencedTaskRunner and guarantees execution on a single thread.
Move a bunch of methods from MessageLoopProxy into the TaskRunner classes and make it inherit from SingleThreadTaskRunner.
BUG=110973
TEST=
Review URL: https://chromiumcodereview.appspot.com/9169037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121999 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/task_runner.cc')
-rw-r--r-- | base/task_runner.cc | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/base/task_runner.cc b/base/task_runner.cc new file mode 100644 index 0000000..734674f --- /dev/null +++ b/base/task_runner.cc @@ -0,0 +1,68 @@ +// 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/task_runner.h" + +#include "base/compiler_specific.h" +#include "base/logging.h" +#include "base/threading/post_task_and_reply_impl.h" + +namespace base { + +namespace { + +// TODO(akalin): There's only one other implementation of +// PostTaskAndReplyImpl in WorkerPool. Investigate whether it'll be +// possible to merge the two. +class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl { + public: + PostTaskAndReplyTaskRunner(TaskRunner* destination); + + private: + virtual bool PostTask(const tracked_objects::Location& from_here, + const Closure& task) OVERRIDE; + + // Non-owning. + TaskRunner* destination_; +}; + +PostTaskAndReplyTaskRunner::PostTaskAndReplyTaskRunner( + TaskRunner* destination) : destination_(destination) { + DCHECK(destination_); +} + +bool PostTaskAndReplyTaskRunner::PostTask( + const tracked_objects::Location& from_here, + const Closure& task) { + return destination_->PostTask(from_here, task); +} + +} // namespace + +bool TaskRunner::PostTask(const tracked_objects::Location& from_here, + const Closure& task) { + return PostDelayedTask(from_here, task, 0); +} + +bool TaskRunner::PostTaskAndReply( + const tracked_objects::Location& from_here, + const Closure& task, + const Closure& reply) { + return PostTaskAndReplyTaskRunner(this).PostTaskAndReply( + from_here, task, reply); +} + +TaskRunner::TaskRunner() {} + +TaskRunner::~TaskRunner() {} + +void TaskRunner::OnDestruct() const { + delete this; +} + +void TaskRunnerTraits::Destruct(const TaskRunner* task_runner) { + task_runner->OnDestruct(); +} + +} // namespace base |