| 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 "components/scheduler/base/task_queue.h" | 9 #include "components/scheduler/base/task_queue.h" |
| 10 #include "components/scheduler/base/time_domain.h" |
| 10 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | 11 #include "third_party/WebKit/public/platform/WebTraceLocation.h" |
| 11 | 12 |
| 12 namespace scheduler { | 13 namespace scheduler { |
| 13 | 14 |
| 14 WebTaskRunnerImpl::WebTaskRunnerImpl(scoped_refptr<TaskQueue> task_queue) | 15 WebTaskRunnerImpl::WebTaskRunnerImpl(scoped_refptr<TaskQueue> task_queue) |
| 15 : task_queue_(task_queue) {} | 16 : task_queue_(task_queue) {} |
| 16 | 17 |
| 17 WebTaskRunnerImpl::~WebTaskRunnerImpl() {} | 18 WebTaskRunnerImpl::~WebTaskRunnerImpl() {} |
| 18 | 19 |
| 19 void WebTaskRunnerImpl::postTask(const blink::WebTraceLocation& web_location, | 20 void WebTaskRunnerImpl::postTask(const blink::WebTraceLocation& web_location, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 33 DCHECK_GE(delayMs, 0.0); | 34 DCHECK_GE(delayMs, 0.0); |
| 34 tracked_objects::Location location(web_location.functionName(), | 35 tracked_objects::Location location(web_location.functionName(), |
| 35 web_location.fileName(), -1, nullptr); | 36 web_location.fileName(), -1, nullptr); |
| 36 task_queue_->PostDelayedTask( | 37 task_queue_->PostDelayedTask( |
| 37 location, | 38 location, |
| 38 base::Bind(&WebTaskRunnerImpl::runTask, | 39 base::Bind(&WebTaskRunnerImpl::runTask, |
| 39 base::Passed(scoped_ptr<blink::WebTaskRunner::Task>(task))), | 40 base::Passed(scoped_ptr<blink::WebTaskRunner::Task>(task))), |
| 40 base::TimeDelta::FromMillisecondsD(delayMs)); | 41 base::TimeDelta::FromMillisecondsD(delayMs)); |
| 41 } | 42 } |
| 42 | 43 |
| 44 double WebTaskRunnerImpl::virtualTimeSeconds() const { |
| 45 return (Now() - base::TimeTicks::UnixEpoch()).InSecondsF(); |
| 46 } |
| 47 |
| 48 double WebTaskRunnerImpl::monotonicallyIncreasingVirtualTimeSeconds() const { |
| 49 return Now().ToInternalValue() / |
| 50 static_cast<double>(base::Time::kMicrosecondsPerSecond); |
| 51 } |
| 52 |
| 53 base::TimeTicks WebTaskRunnerImpl::Now() const { |
| 54 TimeDomain* time_domain = task_queue_->GetTimeDomain(); |
| 55 // It's possible task_queue_ has been Unregistered which can lead to a null |
| 56 // TimeDomain. If that happens just return the current real time. |
| 57 if (!time_domain) |
| 58 return base::TimeTicks::Now(); |
| 59 return time_domain->Now(); |
| 60 } |
| 61 |
| 43 blink::WebTaskRunner* WebTaskRunnerImpl::clone() { | 62 blink::WebTaskRunner* WebTaskRunnerImpl::clone() { |
| 44 return new WebTaskRunnerImpl(task_queue_); | 63 return new WebTaskRunnerImpl(task_queue_); |
| 45 } | 64 } |
| 46 | 65 |
| 47 void WebTaskRunnerImpl::runTask(scoped_ptr<blink::WebTaskRunner::Task> task) | 66 void WebTaskRunnerImpl::runTask(scoped_ptr<blink::WebTaskRunner::Task> task) |
| 48 { | 67 { |
| 49 task->run(); | 68 task->run(); |
| 50 } | 69 } |
| 51 | 70 |
| 52 } // namespace scheduler | 71 } // namespace scheduler |
| OLD | NEW |