OLD | NEW |
| (Empty) |
1 // Copyright 2014 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/renderer/scheduler/web_scheduler_impl.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/single_thread_task_runner.h" | |
9 #include "content/renderer/scheduler/renderer_scheduler.h" | |
10 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | |
11 | |
12 namespace content { | |
13 | |
14 WebSchedulerImpl::WebSchedulerImpl(RendererScheduler* renderer_scheduler) | |
15 : renderer_scheduler_(renderer_scheduler), | |
16 idle_task_runner_(renderer_scheduler_->IdleTaskRunner()), | |
17 loading_task_runner_(renderer_scheduler_->LoadingTaskRunner()), | |
18 timer_task_runner_(renderer_scheduler_->TimerTaskRunner()) { | |
19 } | |
20 | |
21 WebSchedulerImpl::~WebSchedulerImpl() { | |
22 } | |
23 | |
24 bool WebSchedulerImpl::shouldYieldForHighPriorityWork() { | |
25 return renderer_scheduler_->ShouldYieldForHighPriorityWork(); | |
26 } | |
27 | |
28 bool WebSchedulerImpl::canExceedIdleDeadlineIfRequired() { | |
29 return renderer_scheduler_->CanExceedIdleDeadlineIfRequired(); | |
30 } | |
31 | |
32 void WebSchedulerImpl::runIdleTask(scoped_ptr<blink::WebThread::IdleTask> task, | |
33 base::TimeTicks deadline) { | |
34 task->run((deadline - base::TimeTicks()).InSecondsF()); | |
35 } | |
36 | |
37 void WebSchedulerImpl::runTask(scoped_ptr<blink::WebThread::Task> task) { | |
38 task->run(); | |
39 } | |
40 | |
41 void WebSchedulerImpl::postIdleTask(const blink::WebTraceLocation& web_location, | |
42 blink::WebThread::IdleTask* task) { | |
43 DCHECK(idle_task_runner_); | |
44 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
45 tracked_objects::Location location(web_location.functionName(), | |
46 web_location.fileName(), -1, nullptr); | |
47 idle_task_runner_->PostIdleTask( | |
48 location, | |
49 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); | |
50 } | |
51 | |
52 void WebSchedulerImpl::postNonNestableIdleTask( | |
53 const blink::WebTraceLocation& web_location, | |
54 blink::WebThread::IdleTask* task) { | |
55 DCHECK(idle_task_runner_); | |
56 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
57 tracked_objects::Location location(web_location.functionName(), | |
58 web_location.fileName(), -1, nullptr); | |
59 idle_task_runner_->PostNonNestableIdleTask( | |
60 location, | |
61 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); | |
62 } | |
63 | |
64 void WebSchedulerImpl::postIdleTaskAfterWakeup( | |
65 const blink::WebTraceLocation& web_location, | |
66 blink::WebThread::IdleTask* task) { | |
67 DCHECK(idle_task_runner_); | |
68 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
69 tracked_objects::Location location(web_location.functionName(), | |
70 web_location.fileName(), -1, nullptr); | |
71 idle_task_runner_->PostIdleTaskAfterWakeup( | |
72 location, | |
73 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); | |
74 } | |
75 | |
76 void WebSchedulerImpl::postLoadingTask( | |
77 const blink::WebTraceLocation& web_location, blink::WebThread::Task* task) { | |
78 DCHECK(loading_task_runner_); | |
79 scoped_ptr<blink::WebThread::Task> scoped_task(task); | |
80 tracked_objects::Location location(web_location.functionName(), | |
81 web_location.fileName(), -1, nullptr); | |
82 loading_task_runner_->PostTask( | |
83 location, | |
84 base::Bind(&WebSchedulerImpl::runTask, base::Passed(&scoped_task))); | |
85 } | |
86 | |
87 void WebSchedulerImpl::postTimerTask( | |
88 const blink::WebTraceLocation& web_location, | |
89 blink::WebThread::Task* task, | |
90 long long delayMs) { | |
91 DCHECK(timer_task_runner_); | |
92 scoped_ptr<blink::WebThread::Task> scoped_task(task); | |
93 tracked_objects::Location location(web_location.functionName(), | |
94 web_location.fileName(), -1, nullptr); | |
95 timer_task_runner_->PostDelayedTask( | |
96 location, | |
97 base::Bind(&WebSchedulerImpl::runTask, base::Passed(&scoped_task)), | |
98 base::TimeDelta::FromMilliseconds(delayMs)); | |
99 } | |
100 | |
101 } // namespace content | |
OLD | NEW |