OLD | NEW |
---|---|
(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 "content/child/scheduler/worker_web_scheduler_impl.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/single_thread_task_runner.h" | |
9 #include "content/child/scheduler/worker_scheduler.h" | |
10 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | |
11 | |
12 namespace content { | |
13 | |
14 WorkerWebSchedulerImpl::WorkerWebSchedulerImpl( | |
rmcilroy
2015/04/15 12:27:28
Do we need a separate one of these for Worker and
alex clarke (OOO till 29th)
2015/04/15 14:25:46
There are enough common bits to do that, and I thi
rmcilroy
2015/04/15 17:58:15
This wasn't actually what I meant. I meant that we
alex clarke (OOO till 29th)
2015/04/16 09:11:55
I suspect we'd end up with diamond inheritance pro
Sami
2015/04/16 10:44:01
My view is that the WebScheduler adapters should b
rmcilroy
2015/04/16 11:21:05
CL adds the common base scheduler (which I've name
| |
15 WorkerScheduler* worker_scheduler) | |
16 : worker_scheduler_(worker_scheduler), | |
17 idle_task_runner_(worker_scheduler_->IdleTaskRunner()), | |
18 task_runner_(worker_scheduler_->DefaultTaskRunner()) { | |
19 } | |
20 | |
21 WorkerWebSchedulerImpl::~WorkerWebSchedulerImpl() { | |
22 } | |
23 | |
24 bool WorkerWebSchedulerImpl::shouldYieldForHighPriorityWork() { | |
25 return false; | |
26 } | |
27 | |
28 bool WorkerWebSchedulerImpl::canExceedIdleDeadlineIfRequired() { | |
29 return worker_scheduler_->CanExceedIdleDeadlineIfRequired(); | |
30 } | |
31 | |
32 void WorkerWebSchedulerImpl::runIdleTask( | |
33 scoped_ptr<blink::WebThread::IdleTask> task, | |
34 base::TimeTicks deadline) { | |
35 task->run((deadline - base::TimeTicks()).InSecondsF()); | |
36 } | |
37 | |
38 void WorkerWebSchedulerImpl::runTask(scoped_ptr<blink::WebThread::Task> task) { | |
39 task->run(); | |
40 } | |
41 | |
42 void WorkerWebSchedulerImpl::postIdleTask( | |
43 const blink::WebTraceLocation& web_location, | |
44 blink::WebThread::IdleTask* task) { | |
45 DCHECK(idle_task_runner_); | |
46 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
47 tracked_objects::Location location(web_location.functionName(), | |
Sami
2015/04/15 12:37:13
Is it worth writing a (possibly templated) helper
alex clarke (OOO till 29th)
2015/04/15 14:25:46
I was unable to get one template that can do it al
Sami
2015/04/16 10:44:01
Okay, thanks for giving it a try anyway!
| |
48 web_location.fileName(), -1, nullptr); | |
49 idle_task_runner_->PostIdleTask( | |
50 location, base::Bind(&WorkerWebSchedulerImpl::runIdleTask, | |
51 base::Passed(&scoped_task))); | |
52 } | |
53 | |
54 void WorkerWebSchedulerImpl::postNonNestableIdleTask( | |
55 const blink::WebTraceLocation& web_location, | |
56 blink::WebThread::IdleTask* task) { | |
57 DCHECK(idle_task_runner_); | |
58 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
59 tracked_objects::Location location(web_location.functionName(), | |
60 web_location.fileName(), -1, nullptr); | |
61 idle_task_runner_->PostNonNestableIdleTask( | |
62 location, base::Bind(&WorkerWebSchedulerImpl::runIdleTask, | |
63 base::Passed(&scoped_task))); | |
64 } | |
65 | |
66 void WorkerWebSchedulerImpl::postIdleTaskAfterWakeup( | |
67 const blink::WebTraceLocation& web_location, | |
68 blink::WebThread::IdleTask* task) { | |
69 DCHECK(idle_task_runner_); | |
70 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
71 tracked_objects::Location location(web_location.functionName(), | |
72 web_location.fileName(), -1, nullptr); | |
73 idle_task_runner_->PostIdleTaskAfterWakeup( | |
74 location, base::Bind(&WorkerWebSchedulerImpl::runIdleTask, | |
75 base::Passed(&scoped_task))); | |
76 } | |
77 | |
78 void WorkerWebSchedulerImpl::postLoadingTask( | |
79 const blink::WebTraceLocation& web_location, | |
80 blink::WebThread::Task* task) { | |
81 DCHECK(task_runner_); | |
82 scoped_ptr<blink::WebThread::Task> scoped_task(task); | |
83 tracked_objects::Location location(web_location.functionName(), | |
84 web_location.fileName(), -1, nullptr); | |
85 task_runner_->PostTask(location, base::Bind(&WorkerWebSchedulerImpl::runTask, | |
86 base::Passed(&scoped_task))); | |
87 } | |
88 | |
89 void WorkerWebSchedulerImpl::postTimerTask( | |
90 const blink::WebTraceLocation& web_location, | |
91 blink::WebThread::Task* task, | |
92 long long delayMs) { | |
93 DCHECK(task_runner_); | |
94 scoped_ptr<blink::WebThread::Task> scoped_task(task); | |
95 tracked_objects::Location location(web_location.functionName(), | |
96 web_location.fileName(), -1, nullptr); | |
97 task_runner_->PostDelayedTask( | |
98 location, | |
99 base::Bind(&WorkerWebSchedulerImpl::runTask, base::Passed(&scoped_task)), | |
100 base::TimeDelta::FromMilliseconds(delayMs)); | |
101 } | |
102 | |
103 } // namespace content | |
OLD | NEW |