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