| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/renderer/throttled_time_domain.h" | 5 #include "platform/scheduler/renderer/throttled_time_domain.h" |
| 6 | 6 |
| 7 namespace blink { | 7 namespace blink { |
| 8 namespace scheduler { | 8 namespace scheduler { |
| 9 | 9 |
| 10 ThrottledTimeDomain::ThrottledTimeDomain() : RealTimeDomain() {} | 10 ThrottledTimeDomain::ThrottledTimeDomain() : RealTimeDomain() {} |
| 11 | 11 |
| 12 ThrottledTimeDomain::~ThrottledTimeDomain() {} | 12 ThrottledTimeDomain::~ThrottledTimeDomain() {} |
| 13 | 13 |
| 14 const char* ThrottledTimeDomain::GetName() const { | 14 const char* ThrottledTimeDomain::GetName() const { |
| 15 return "ThrottledTimeDomain"; | 15 return "ThrottledTimeDomain"; |
| 16 } | 16 } |
| 17 | 17 |
| 18 void ThrottledTimeDomain::RequestWakeUpAt(base::TimeTicks now, | 18 void ThrottledTimeDomain::RequestWakeUpAt(base::TimeTicks now, |
| 19 base::TimeTicks run_time) { | 19 base::TimeTicks run_time) { |
| 20 // We assume the owner (i.e. TaskQueueThrottler) will manage wake-ups on our | 20 // We assume the owner (i.e. TaskQueueThrottler) will manage wake-ups on our |
| 21 // behalf. | 21 // behalf. |
| 22 } | 22 } |
| 23 | 23 |
| 24 void ThrottledTimeDomain::CancelWakeUpAt(base::TimeTicks run_time) { | 24 void ThrottledTimeDomain::CancelWakeUpAt(base::TimeTicks run_time) { |
| 25 // We ignore this because RequestWakeUpAt is a NOP. | 25 // We ignore this because RequestWakeUpAt is a NOP. |
| 26 } | 26 } |
| 27 | 27 |
| 28 void ThrottledTimeDomain::SetNextTaskRunTime(base::TimeTicks run_time) { |
| 29 next_task_run_time_ = run_time; |
| 30 } |
| 31 |
| 28 base::Optional<base::TimeDelta> ThrottledTimeDomain::DelayTillNextTask( | 32 base::Optional<base::TimeDelta> ThrottledTimeDomain::DelayTillNextTask( |
| 29 LazyNow* lazy_now) { | 33 LazyNow* lazy_now) { |
| 34 if (next_task_run_time_ && next_task_run_time_ > lazy_now->Now()) |
| 35 return next_task_run_time_.value() - lazy_now->Now(); |
| 36 |
| 30 base::TimeTicks next_run_time; | 37 base::TimeTicks next_run_time; |
| 31 if (!NextScheduledRunTime(&next_run_time)) | 38 if (!NextScheduledRunTime(&next_run_time)) |
| 32 return base::nullopt; | 39 return base::nullopt; |
| 33 | 40 |
| 34 base::TimeTicks now = lazy_now->Now(); | 41 base::TimeTicks now = lazy_now->Now(); |
| 35 if (now >= next_run_time) | 42 if (now >= next_run_time) |
| 36 return base::TimeDelta(); // Makes DoWork post an immediate continuation. | 43 return base::TimeDelta(); // Makes DoWork post an immediate continuation. |
| 37 | 44 |
| 38 // We assume the owner (i.e. TaskQueueThrottler) will manage wake-ups on our | 45 // We assume the owner (i.e. TaskQueueThrottler) will manage wake-ups on our |
| 39 // behalf. | 46 // behalf. |
| 40 return base::nullopt; | 47 return base::nullopt; |
| 41 } | 48 } |
| 42 | 49 |
| 43 } // namespace scheduler | 50 } // namespace scheduler |
| 44 } // namespace blink | 51 } // namespace blink |
| OLD | NEW |