| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/scheduler/base/real_time_domain.h" | 5 #include "components/scheduler/base/real_time_domain.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "components/scheduler/base/task_queue_impl.h" | 8 #include "components/scheduler/base/task_queue_impl.h" |
| 9 #include "components/scheduler/base/task_queue_manager.h" | 9 #include "components/scheduler/base/task_queue_manager.h" |
| 10 #include "components/scheduler/base/task_queue_manager_delegate.h" | 10 #include "components/scheduler/base/task_queue_manager_delegate.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 } | 23 } |
| 24 | 24 |
| 25 LazyNow RealTimeDomain::CreateLazyNow() const { | 25 LazyNow RealTimeDomain::CreateLazyNow() const { |
| 26 return task_queue_manager_->CreateLazyNow(); | 26 return task_queue_manager_->CreateLazyNow(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 base::TimeTicks RealTimeDomain::Now() const { | 29 base::TimeTicks RealTimeDomain::Now() const { |
| 30 return task_queue_manager_->delegate()->NowTicks(); | 30 return task_queue_manager_->delegate()->NowTicks(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 base::TimeTicks RealTimeDomain::ComputeDelayedRunTime( | |
| 34 base::TimeTicks time_domain_now, | |
| 35 base::TimeDelta delay) const { | |
| 36 return time_domain_now + delay; | |
| 37 } | |
| 38 | |
| 39 void RealTimeDomain::RequestWakeup(base::TimeTicks now, base::TimeDelta delay) { | 33 void RealTimeDomain::RequestWakeup(base::TimeTicks now, base::TimeDelta delay) { |
| 40 // NOTE this is only called if the scheduled runtime is sooner than any | 34 // NOTE this is only called if the scheduled runtime is sooner than any |
| 41 // previously scheduled runtime, or there is no (outstanding) previously | 35 // previously scheduled runtime, or there is no (outstanding) previously |
| 42 // scheduled runtime. | 36 // scheduled runtime. |
| 43 task_queue_manager_->MaybeScheduleDelayedWork(FROM_HERE, now, delay); | 37 task_queue_manager_->MaybeScheduleDelayedWork(FROM_HERE, now, delay); |
| 44 } | 38 } |
| 45 | 39 |
| 46 bool RealTimeDomain::MaybeAdvanceTime() { | 40 bool RealTimeDomain::MaybeAdvanceTime() { |
| 47 base::TimeTicks next_run_time; | 41 base::TimeTicks next_run_time; |
| 48 if (!NextScheduledRunTime(&next_run_time)) | 42 if (!NextScheduledRunTime(&next_run_time)) |
| 49 return false; | 43 return false; |
| 50 | 44 |
| 51 base::TimeTicks now = Now(); | 45 base::TimeTicks now = Now(); |
| 52 if (now >= next_run_time) | 46 if (now >= next_run_time) |
| 53 return true; // Causes DoWork to post a continuation. | 47 return true; // Causes DoWork to post a continuation. |
| 54 | 48 |
| 55 // The next task is sometime in the future, make sure we schedule a DoWork to | 49 // The next task is sometime in the future, make sure we schedule a DoWork to |
| 56 // run it. | 50 // run it. |
| 57 task_queue_manager_->MaybeScheduleDelayedWork(FROM_HERE, now, | 51 task_queue_manager_->MaybeScheduleDelayedWork(FROM_HERE, now, |
| 58 next_run_time - now); | 52 next_run_time - now); |
| 59 return false; | 53 return false; |
| 60 } | 54 } |
| 61 | 55 |
| 62 void RealTimeDomain::AsValueIntoInternal( | 56 void RealTimeDomain::AsValueIntoInternal( |
| 63 base::trace_event::TracedValue* state) const {} | 57 base::trace_event::TracedValue* state) const {} |
| 64 | 58 |
| 65 const char* RealTimeDomain::GetName() const { | 59 const char* RealTimeDomain::GetName() const { |
| 66 return "RealTimeDomain"; | 60 return "RealTimeDomain"; |
| 67 } | 61 } |
| 62 |
| 68 } // namespace scheduler | 63 } // namespace scheduler |
| OLD | NEW |