| 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/child/web_task_runner_impl.h" | 5 #include "components/scheduler/child/web_task_runner_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "components/scheduler/base/task_queue.h" | 10 #include "components/scheduler/base/task_queue.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 blink::WebTaskRunner::Task* task, | 31 blink::WebTaskRunner::Task* task, |
| 32 double delayMs) { | 32 double delayMs) { |
| 33 DCHECK_GE(delayMs, 0.0); | 33 DCHECK_GE(delayMs, 0.0); |
| 34 task_queue_->PostDelayedTask( | 34 task_queue_->PostDelayedTask( |
| 35 location, | 35 location, |
| 36 base::Bind(&WebTaskRunnerImpl::runTask, | 36 base::Bind(&WebTaskRunnerImpl::runTask, |
| 37 base::Passed(base::WrapUnique(task))), | 37 base::Passed(base::WrapUnique(task))), |
| 38 base::TimeDelta::FromMillisecondsD(delayMs)); | 38 base::TimeDelta::FromMillisecondsD(delayMs)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool WebTaskRunnerImpl::runsTasksOnCurrentThread() { |
| 42 return task_queue_->RunsTasksOnCurrentThread(); |
| 43 } |
| 44 |
| 41 double WebTaskRunnerImpl::virtualTimeSeconds() const { | 45 double WebTaskRunnerImpl::virtualTimeSeconds() const { |
| 42 return (Now() - base::TimeTicks::UnixEpoch()).InSecondsF(); | 46 return (Now() - base::TimeTicks::UnixEpoch()).InSecondsF(); |
| 43 } | 47 } |
| 44 | 48 |
| 45 double WebTaskRunnerImpl::monotonicallyIncreasingVirtualTimeSeconds() const { | 49 double WebTaskRunnerImpl::monotonicallyIncreasingVirtualTimeSeconds() const { |
| 46 return Now().ToInternalValue() / | 50 return Now().ToInternalValue() / |
| 47 static_cast<double>(base::Time::kMicrosecondsPerSecond); | 51 static_cast<double>(base::Time::kMicrosecondsPerSecond); |
| 48 } | 52 } |
| 49 | 53 |
| 50 base::TimeTicks WebTaskRunnerImpl::Now() const { | 54 base::TimeTicks WebTaskRunnerImpl::Now() const { |
| 51 TimeDomain* time_domain = task_queue_->GetTimeDomain(); | 55 TimeDomain* time_domain = task_queue_->GetTimeDomain(); |
| 52 // It's possible task_queue_ has been Unregistered which can lead to a null | 56 // It's possible task_queue_ has been Unregistered which can lead to a null |
| 53 // TimeDomain. If that happens just return the current real time. | 57 // TimeDomain. If that happens just return the current real time. |
| 54 if (!time_domain) | 58 if (!time_domain) |
| 55 return base::TimeTicks::Now(); | 59 return base::TimeTicks::Now(); |
| 56 return time_domain->Now(); | 60 return time_domain->Now(); |
| 57 } | 61 } |
| 58 | 62 |
| 59 blink::WebTaskRunner* WebTaskRunnerImpl::clone() { | 63 blink::WebTaskRunner* WebTaskRunnerImpl::clone() { |
| 60 return new WebTaskRunnerImpl(task_queue_); | 64 return new WebTaskRunnerImpl(task_queue_); |
| 61 } | 65 } |
| 62 | 66 |
| 63 void WebTaskRunnerImpl::runTask( | 67 void WebTaskRunnerImpl::runTask( |
| 64 std::unique_ptr<blink::WebTaskRunner::Task> task) { | 68 std::unique_ptr<blink::WebTaskRunner::Task> task) { |
| 65 task->run(); | 69 task->run(); |
| 66 } | 70 } |
| 67 | 71 |
| 68 } // namespace scheduler | 72 } // namespace scheduler |
| OLD | NEW |