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

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

Powered by Google App Engine
This is Rietveld 408576698