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 28 matching lines...) Expand all Loading... |
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::RequestWakeup(base::TimeTicks now, base::TimeDelta delay) { |
43 // NOTE this is only called if the scheduled runtime is sooner than any | 43 // NOTE this is only called if the scheduled runtime is sooner than any |
44 // previously scheduled runtime, or there is no (outstanding) previously | 44 // previously scheduled runtime, or there is no (outstanding) previously |
45 // scheduled runtime. | 45 // scheduled runtime. |
46 task_queue_manager_->MaybeScheduleDelayedWork(FROM_HERE, now, delay); | 46 task_queue_manager_->MaybeScheduleDelayedWork(FROM_HERE, now, delay); |
47 } | 47 } |
48 | 48 |
49 base::Optional<base::TimeDelta> RealTimeDomain::DelayTillNextTask( | 49 bool RealTimeDomain::MaybeAdvanceTime() { |
50 LazyNow* lazy_now) { | |
51 base::TimeTicks next_run_time; | 50 base::TimeTicks next_run_time; |
52 if (!NextScheduledRunTime(&next_run_time)) | 51 if (!NextScheduledRunTime(&next_run_time)) |
53 return base::Optional<base::TimeDelta>(); | 52 return false; |
54 | 53 |
55 base::TimeTicks now = lazy_now->Now(); | 54 base::TimeTicks now = Now(); |
56 if (now >= next_run_time) | 55 if (now >= next_run_time) |
57 return base::TimeDelta(); // Makes DoWork post an immediate continuation. | 56 return true; // Causes DoWork to post a continuation. |
58 | 57 |
59 base::TimeDelta delay = next_run_time - now; | 58 base::TimeDelta delay = next_run_time - now; |
60 TRACE_EVENT1(tracing_category_, "RealTimeDomain::DelayTillNextTask", | 59 TRACE_EVENT1(tracing_category_, "RealTimeDomain::MaybeAdvanceTime", |
61 "delay_ms", delay.InMillisecondsF()); | 60 "delay_ms", delay.InMillisecondsF()); |
62 | 61 |
63 // The next task is sometime in the future. DoWork will make sure it gets | 62 // The next task is sometime in the future, make sure we schedule a DoWork to |
64 // run at the right time.. | 63 // run it. |
65 return delay; | 64 task_queue_manager_->MaybeScheduleDelayedWork(FROM_HERE, now, delay); |
| 65 return false; |
66 } | 66 } |
67 | 67 |
68 void RealTimeDomain::AsValueIntoInternal( | 68 void RealTimeDomain::AsValueIntoInternal( |
69 base::trace_event::TracedValue* state) const {} | 69 base::trace_event::TracedValue* state) const {} |
70 | 70 |
71 const char* RealTimeDomain::GetName() const { | 71 const char* RealTimeDomain::GetName() const { |
72 return "RealTimeDomain"; | 72 return "RealTimeDomain"; |
73 } | 73 } |
74 } // namespace scheduler | 74 } // namespace scheduler |
75 } // namespace blink | 75 } // namespace blink |
OLD | NEW |