| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/task_runner.h" | 5 #include "base/task_runner.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/post_task_and_reply_impl.h" | 9 #include "base/threading/post_task_and_reply_impl.h" |
| 10 #include "base/time/time.h" |
| 10 | 11 |
| 11 namespace base { | 12 namespace base { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // TODO(akalin): There's only one other implementation of | 16 // TODO(akalin): There's only one other implementation of |
| 16 // PostTaskAndReplyImpl in WorkerPool. Investigate whether it'll be | 17 // PostTaskAndReplyImpl in WorkerPool. Investigate whether it'll be |
| 17 // possible to merge the two. | 18 // possible to merge the two. |
| 18 class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl { | 19 class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl { |
| 19 public: | 20 public: |
| 20 explicit PostTaskAndReplyTaskRunner(TaskRunner* destination); | 21 explicit PostTaskAndReplyTaskRunner(TaskRunner* destination); |
| 21 | 22 |
| 22 private: | 23 private: |
| 23 bool PostTask(const tracked_objects::Location& from_here, | 24 bool PostTask(const tracked_objects::Location& from_here, |
| 24 const Closure& task) override; | 25 const Closure& task) override; |
| 26 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 27 const Closure& task, const TimeDelta& delay) override; |
| 25 | 28 |
| 26 // Non-owning. | 29 // Non-owning. |
| 27 TaskRunner* destination_; | 30 TaskRunner* destination_; |
| 28 }; | 31 }; |
| 29 | 32 |
| 30 PostTaskAndReplyTaskRunner::PostTaskAndReplyTaskRunner( | 33 PostTaskAndReplyTaskRunner::PostTaskAndReplyTaskRunner( |
| 31 TaskRunner* destination) : destination_(destination) { | 34 TaskRunner* destination) : destination_(destination) { |
| 32 DCHECK(destination_); | 35 DCHECK(destination_); |
| 33 } | 36 } |
| 34 | 37 |
| 35 bool PostTaskAndReplyTaskRunner::PostTask( | 38 bool PostTaskAndReplyTaskRunner::PostTask( |
| 36 const tracked_objects::Location& from_here, | 39 const tracked_objects::Location& from_here, |
| 37 const Closure& task) { | 40 const Closure& task) { |
| 38 return destination_->PostTask(from_here, task); | 41 return destination_->PostTask(from_here, task); |
| 39 } | 42 } |
| 40 | 43 |
| 44 bool PostTaskAndReplyTaskRunner::PostDelayedTask( |
| 45 const tracked_objects::Location& from_here, |
| 46 const Closure& task, |
| 47 const TimeDelta& delay) { |
| 48 return destination_->PostDelayedTask(from_here, task, delay); |
| 49 } |
| 50 |
| 41 } // namespace | 51 } // namespace |
| 42 | 52 |
| 43 bool TaskRunner::PostTask(const tracked_objects::Location& from_here, | 53 bool TaskRunner::PostTask(const tracked_objects::Location& from_here, |
| 44 const Closure& task) { | 54 const Closure& task) { |
| 45 return PostDelayedTask(from_here, task, base::TimeDelta()); | 55 return PostDelayedTask(from_here, task, TimeDelta()); |
| 46 } | 56 } |
| 47 | 57 |
| 48 bool TaskRunner::PostTaskAndReply( | 58 bool TaskRunner::PostTaskAndReply( |
| 49 const tracked_objects::Location& from_here, | 59 const tracked_objects::Location& from_here, |
| 50 const Closure& task, | 60 const Closure& task, |
| 51 const Closure& reply) { | 61 const Closure& reply) { |
| 52 return PostTaskAndReplyTaskRunner(this).PostTaskAndReply( | 62 return PostTaskAndReplyTaskRunner(this).PostTaskAndReply( |
| 53 from_here, task, reply); | 63 from_here, task, reply); |
| 54 } | 64 } |
| 55 | 65 |
| 66 bool TaskRunner::PostDelayedTaskAndReply( |
| 67 const tracked_objects::Location& from_here, |
| 68 const Closure& task, |
| 69 const Closure& reply, |
| 70 const TimeDelta& delay) { |
| 71 return PostTaskAndReplyTaskRunner(this).PostDelayedTaskAndReply( |
| 72 from_here, task, reply, delay); |
| 73 } |
| 74 |
| 56 TaskRunner::TaskRunner() {} | 75 TaskRunner::TaskRunner() {} |
| 57 | 76 |
| 58 TaskRunner::~TaskRunner() {} | 77 TaskRunner::~TaskRunner() {} |
| 59 | 78 |
| 60 void TaskRunner::OnDestruct() const { | 79 void TaskRunner::OnDestruct() const { |
| 61 delete this; | 80 delete this; |
| 62 } | 81 } |
| 63 | 82 |
| 64 void TaskRunnerTraits::Destruct(const TaskRunner* task_runner) { | 83 void TaskRunnerTraits::Destruct(const TaskRunner* task_runner) { |
| 65 task_runner->OnDestruct(); | 84 task_runner->OnDestruct(); |
| 66 } | 85 } |
| 67 | 86 |
| 68 } // namespace base | 87 } // namespace base |
| OLD | NEW |