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 "components/scheduler/renderer/throttled_time_domain.h" | 5 #include "components/scheduler/renderer/throttled_time_domain.h" |
6 | 6 |
7 #include "base/time/tick_clock.h" | |
8 | |
9 namespace scheduler { | 7 namespace scheduler { |
10 | 8 |
11 ThrottledTimeDomain::ThrottledTimeDomain(TimeDomain::Observer* observer, | 9 ThrottledTimeDomain::ThrottledTimeDomain(TimeDomain::Observer* observer, |
12 base::TickClock* tick_clock) | 10 const char* tracing_category) |
13 : VirtualTimeDomain(observer, tick_clock->NowTicks()), | 11 : RealTimeDomain(observer, tracing_category) {} |
14 tick_clock_(tick_clock) {} | |
15 | 12 |
16 ThrottledTimeDomain::~ThrottledTimeDomain() {} | 13 ThrottledTimeDomain::~ThrottledTimeDomain() {} |
17 | 14 |
18 base::TimeTicks ThrottledTimeDomain::ComputeDelayedRunTime( | |
19 base::TimeTicks, | |
20 base::TimeDelta delay) const { | |
21 // We ignore the |time_domain_now| parameter since its the virtual time but we | |
22 // need to use the current real time when computing the delayed runtime. If | |
23 // don't do that, throttled timers may fire sooner than expected. | |
24 return tick_clock_->NowTicks() + delay; | |
25 } | |
26 | |
27 const char* ThrottledTimeDomain::GetName() const { | 15 const char* ThrottledTimeDomain::GetName() const { |
28 return "ThrottledTimeDomain"; | 16 return "ThrottledTimeDomain"; |
29 } | 17 } |
30 | 18 |
| 19 void ThrottledTimeDomain::RequestWakeup(base::TimeTicks now, |
| 20 base::TimeDelta delay) { |
| 21 // We assume the owner (i.e. ThrottlingHelper) will manage wakeups on our |
| 22 // behalf. |
| 23 } |
| 24 |
| 25 bool ThrottledTimeDomain::MaybeAdvanceTime() { |
| 26 base::TimeTicks next_run_time; |
| 27 if (!NextScheduledRunTime(&next_run_time)) |
| 28 return false; |
| 29 |
| 30 base::TimeTicks now = Now(); |
| 31 if (now >= next_run_time) |
| 32 return true; // Causes DoWork to post a continuation. |
| 33 |
| 34 // Unlike RealTimeDomain::MaybeAdvanceTime we don't request a wake up here, we |
| 35 // assume the owner (i.e. ThrottlingHelper) will manage wakeups on our behalf. |
| 36 return false; |
| 37 } |
| 38 |
31 } // namespace scheduler | 39 } // namespace scheduler |
OLD | NEW |