Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: components/scheduler/child/web_task_runner_impl.cc

Issue 2118903002: scheduler: Move the Blink scheduler into Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/child/web_task_runner_impl.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/memory/ptr_util.h"
10 #include "components/scheduler/base/task_queue.h"
11 #include "components/scheduler/base/time_domain.h"
12 #include "third_party/WebKit/public/platform/WebTraceLocation.h"
13
14 namespace scheduler {
15
16 WebTaskRunnerImpl::WebTaskRunnerImpl(scoped_refptr<TaskQueue> task_queue)
17 : task_queue_(task_queue) {}
18
19 WebTaskRunnerImpl::~WebTaskRunnerImpl() {}
20
21 void WebTaskRunnerImpl::postTask(const blink::WebTraceLocation& location,
22 blink::WebTaskRunner::Task* task) {
23 task_queue_->PostTask(
24 location,
25 base::Bind(&WebTaskRunnerImpl::runTask,
26 base::Passed(base::WrapUnique(task))));
27 }
28
29 void WebTaskRunnerImpl::postDelayedTask(
30 const blink::WebTraceLocation& location,
31 blink::WebTaskRunner::Task* task,
32 double delayMs) {
33 DCHECK_GE(delayMs, 0.0);
34 task_queue_->PostDelayedTask(
35 location,
36 base::Bind(&WebTaskRunnerImpl::runTask,
37 base::Passed(base::WrapUnique(task))),
38 base::TimeDelta::FromMillisecondsD(delayMs));
39 }
40
41 bool WebTaskRunnerImpl::runsTasksOnCurrentThread() {
42 return task_queue_->RunsTasksOnCurrentThread();
43 }
44
45 double WebTaskRunnerImpl::virtualTimeSeconds() const {
46 return (Now() - base::TimeTicks::UnixEpoch()).InSecondsF();
47 }
48
49 double WebTaskRunnerImpl::monotonicallyIncreasingVirtualTimeSeconds() const {
50 return Now().ToInternalValue() /
51 static_cast<double>(base::Time::kMicrosecondsPerSecond);
52 }
53
54 base::TimeTicks WebTaskRunnerImpl::Now() const {
55 TimeDomain* time_domain = task_queue_->GetTimeDomain();
56 // It's possible task_queue_ has been Unregistered which can lead to a null
57 // TimeDomain. If that happens just return the current real time.
58 if (!time_domain)
59 return base::TimeTicks::Now();
60 return time_domain->Now();
61 }
62
63 std::unique_ptr<blink::WebTaskRunner> WebTaskRunnerImpl::clone() {
64 return base::WrapUnique(new WebTaskRunnerImpl(task_queue_));
65 }
66
67 void WebTaskRunnerImpl::runTask(
68 std::unique_ptr<blink::WebTaskRunner::Task> task) {
69 task->run();
70 }
71
72 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/child/web_task_runner_impl.h ('k') | components/scheduler/child/webthread_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698