OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/scheduler/base/real_time_domain.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "components/scheduler/base/task_queue_impl.h" | |
9 #include "components/scheduler/base/task_queue_manager.h" | |
10 #include "components/scheduler/base/task_queue_manager_delegate.h" | |
11 | |
12 namespace scheduler { | |
13 | |
14 RealTimeDomain::RealTimeDomain(const char* tracing_category) | |
15 : TimeDomain(nullptr), | |
16 tracing_category_(tracing_category), | |
17 task_queue_manager_(nullptr) {} | |
18 | |
19 RealTimeDomain::RealTimeDomain(TimeDomain::Observer* observer, | |
20 const char* tracing_category) | |
21 : TimeDomain(observer), | |
22 tracing_category_(tracing_category), | |
23 task_queue_manager_(nullptr) {} | |
24 | |
25 RealTimeDomain::~RealTimeDomain() {} | |
26 | |
27 void RealTimeDomain::OnRegisterWithTaskQueueManager( | |
28 TaskQueueManager* task_queue_manager) { | |
29 task_queue_manager_ = task_queue_manager; | |
30 DCHECK(task_queue_manager_); | |
31 } | |
32 | |
33 LazyNow RealTimeDomain::CreateLazyNow() const { | |
34 return task_queue_manager_->CreateLazyNow(); | |
35 } | |
36 | |
37 base::TimeTicks RealTimeDomain::Now() const { | |
38 return task_queue_manager_->delegate()->NowTicks(); | |
39 } | |
40 | |
41 void RealTimeDomain::RequestWakeup(base::TimeTicks now, base::TimeDelta delay) { | |
42 // NOTE this is only called if the scheduled runtime is sooner than any | |
43 // previously scheduled runtime, or there is no (outstanding) previously | |
44 // scheduled runtime. | |
45 task_queue_manager_->MaybeScheduleDelayedWork(FROM_HERE, now, delay); | |
46 } | |
47 | |
48 bool RealTimeDomain::MaybeAdvanceTime() { | |
49 base::TimeTicks next_run_time; | |
50 if (!NextScheduledRunTime(&next_run_time)) | |
51 return false; | |
52 | |
53 base::TimeTicks now = Now(); | |
54 if (now >= next_run_time) | |
55 return true; // Causes DoWork to post a continuation. | |
56 | |
57 base::TimeDelta delay = next_run_time - now; | |
58 TRACE_EVENT1(tracing_category_, "RealTimeDomain::MaybeAdvanceTime", | |
59 "delay_ms", delay.InMillisecondsF()); | |
60 | |
61 // The next task is sometime in the future, make sure we schedule a DoWork to | |
62 // run it. | |
63 task_queue_manager_->MaybeScheduleDelayedWork(FROM_HERE, now, delay); | |
64 return false; | |
65 } | |
66 | |
67 void RealTimeDomain::AsValueIntoInternal( | |
68 base::trace_event::TracedValue* state) const {} | |
69 | |
70 const char* RealTimeDomain::GetName() const { | |
71 return "RealTimeDomain"; | |
72 } | |
73 } // namespace scheduler | |
OLD | NEW |