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