OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/scheduler/base/delayed_task_delegate_impl.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "components/scheduler/base/task_queue_impl.h" |
| 9 #include "components/scheduler/base/task_queue_manager_delegate.h" |
| 10 |
| 11 namespace scheduler { |
| 12 |
| 13 DelayedTaskDelegateImpl::DelayedTaskDelegateImpl( |
| 14 TaskQueueManagerDelegate* delegate, base::Closure do_work_closure) |
| 15 : delegate_(delegate), |
| 16 do_work_closure_(do_work_closure), |
| 17 weak_factory_(this) {} |
| 18 |
| 19 DelayedTaskDelegateImpl::~DelayedTaskDelegateImpl() {} |
| 20 |
| 21 base::TimeTicks DelayedTaskDelegateImpl::CachedNow() { |
| 22 if (cached_now_.is_null()) |
| 23 cached_now_ = delegate_->NowTicks(); |
| 24 return cached_now_; |
| 25 } |
| 26 |
| 27 void DelayedTaskDelegateImpl::InvalidateNowCache() { |
| 28 cached_now_ = base::TimeTicks(); |
| 29 } |
| 30 |
| 31 bool DelayedTaskDelegateImpl::BelongsToCurrentThread() const { |
| 32 return delegate_ && delegate_->BelongsToCurrentThread(); |
| 33 } |
| 34 |
| 35 void DelayedTaskDelegateImpl::PostScheduleDelayedWorkTaskOnMainThread( |
| 36 internal::TaskQueueImpl* queue, base::TimeTicks delayed_run_time) { |
| 37 if (!delegate_) |
| 38 return; |
| 39 delegate_->PostTask( |
| 40 FROM_HERE, base::Bind(&DelayedTaskDelegateImpl::ScheduleDelayedWorkTask, |
| 41 weak_factory_.GetWeakPtr(), |
| 42 scoped_refptr<internal::TaskQueueImpl>(queue), |
| 43 delayed_run_time)); |
| 44 } |
| 45 |
| 46 void DelayedTaskDelegateImpl::ScheduleDoWork(base::TimeDelta delay) { |
| 47 if (!delegate_) |
| 48 return; |
| 49 delegate_->PostDelayedTask(FROM_HERE, do_work_closure_, delay); |
| 50 } |
| 51 |
| 52 } // namespace scheduler |
OLD | NEW |