| 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 "platform/scheduler/base/real_time_domain.h" | 5 #include "platform/scheduler/base/real_time_domain.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "platform/scheduler/base/task_queue_impl.h" | 8 #include "platform/scheduler/base/task_queue_impl.h" |
| 9 #include "platform/scheduler/base/task_queue_manager.h" | 9 #include "platform/scheduler/base/task_queue_manager.h" |
| 10 #include "platform/scheduler/base/task_queue_manager_delegate.h" | 10 #include "platform/scheduler/base/task_queue_manager_delegate.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 | 33 |
| 34 LazyNow RealTimeDomain::CreateLazyNow() const { | 34 LazyNow RealTimeDomain::CreateLazyNow() const { |
| 35 return task_queue_manager_->CreateLazyNow(); | 35 return task_queue_manager_->CreateLazyNow(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 base::TimeTicks RealTimeDomain::Now() const { | 38 base::TimeTicks RealTimeDomain::Now() const { |
| 39 return task_queue_manager_->delegate()->NowTicks(); | 39 return task_queue_manager_->delegate()->NowTicks(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void RealTimeDomain::RequestWakeup(base::TimeTicks now, base::TimeDelta delay) { | 42 void RealTimeDomain::RequestWakeupAt(LazyNow* lazy_now, |
| 43 base::TimeTicks run_time) { |
| 43 // NOTE this is only called if the scheduled runtime is sooner than any | 44 // NOTE this is only called if the scheduled runtime is sooner than any |
| 44 // previously scheduled runtime, or there is no (outstanding) previously | 45 // previously scheduled runtime, or there is no (outstanding) previously |
| 45 // scheduled runtime. | 46 // scheduled runtime. |
| 46 task_queue_manager_->MaybeScheduleDelayedWork(FROM_HERE, now, delay); | 47 task_queue_manager_->MaybeScheduleDelayedWork(FROM_HERE, this, lazy_now, |
| 48 run_time); |
| 49 } |
| 50 |
| 51 void RealTimeDomain::CancelWakeupAt(base::TimeTicks run_time) { |
| 52 task_queue_manager_->CancelDelayedWork(this, run_time); |
| 47 } | 53 } |
| 48 | 54 |
| 49 base::Optional<base::TimeDelta> RealTimeDomain::DelayTillNextTask( | 55 base::Optional<base::TimeDelta> RealTimeDomain::DelayTillNextTask( |
| 50 LazyNow* lazy_now) { | 56 LazyNow* lazy_now) { |
| 51 base::TimeTicks next_run_time; | 57 base::TimeTicks next_run_time; |
| 52 if (!NextScheduledRunTime(&next_run_time)) | 58 if (!NextScheduledRunTime(&next_run_time)) |
| 53 return base::nullopt; | 59 return base::nullopt; |
| 54 | 60 |
| 55 base::TimeTicks now = lazy_now->Now(); | 61 base::TimeTicks now = lazy_now->Now(); |
| 56 if (now >= next_run_time) | 62 if (now >= next_run_time) |
| 57 return base::TimeDelta(); // Makes DoWork post an immediate continuation. | 63 return base::TimeDelta(); // Makes DoWork post an immediate continuation. |
| 58 | 64 |
| 59 base::TimeDelta delay = next_run_time - now; | 65 base::TimeDelta delay = next_run_time - now; |
| 60 TRACE_EVENT1(tracing_category_, "RealTimeDomain::DelayTillNextTask", | 66 TRACE_EVENT1(tracing_category_, "RealTimeDomain::DelayTillNextTask", |
| 61 "delay_ms", delay.InMillisecondsF()); | 67 "delay_ms", delay.InMillisecondsF()); |
| 62 | 68 |
| 63 // The next task is sometime in the future. DoWork will make sure it gets | 69 // The next task is sometime in the future. DoWork will make sure it gets |
| 64 // run at the right time. | 70 // run at the right time. |
| 65 return delay; | 71 return delay; |
| 66 } | 72 } |
| 67 | 73 |
| 68 void RealTimeDomain::AsValueIntoInternal( | 74 void RealTimeDomain::AsValueIntoInternal( |
| 69 base::trace_event::TracedValue* state) const {} | 75 base::trace_event::TracedValue* state) const {} |
| 70 | 76 |
| 71 const char* RealTimeDomain::GetName() const { | 77 const char* RealTimeDomain::GetName() const { |
| 72 return "RealTimeDomain"; | 78 return "RealTimeDomain"; |
| 73 } | 79 } |
| 74 } // namespace scheduler | 80 } // namespace scheduler |
| 75 } // namespace blink | 81 } // namespace blink |
| OLD | NEW |