OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/renderer/scheduler/web_scheduler_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/single_thread_task_runner.h" |
8 #include "content/renderer/scheduler/renderer_scheduler.h" | 9 #include "content/renderer/scheduler/renderer_scheduler.h" |
9 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | 10 #include "third_party/WebKit/public/platform/WebTraceLocation.h" |
10 | 11 |
11 namespace content { | 12 namespace content { |
12 | 13 |
13 WebSchedulerImpl::WebSchedulerImpl(RendererScheduler* renderer_scheduler) | 14 WebSchedulerImpl::WebSchedulerImpl(RendererScheduler* renderer_scheduler) |
14 : renderer_scheduler_(renderer_scheduler), | 15 : renderer_scheduler_(renderer_scheduler), |
15 idle_task_runner_(renderer_scheduler_->IdleTaskRunner()) { | 16 idle_task_runner_(renderer_scheduler_->IdleTaskRunner()), |
| 17 loading_task_runner_(renderer_scheduler_->LoadingTaskRunner()) { |
16 } | 18 } |
17 | 19 |
18 WebSchedulerImpl::~WebSchedulerImpl() { | 20 WebSchedulerImpl::~WebSchedulerImpl() { |
19 } | 21 } |
20 | 22 |
21 bool WebSchedulerImpl::shouldYieldForHighPriorityWork() { | 23 bool WebSchedulerImpl::shouldYieldForHighPriorityWork() { |
22 return renderer_scheduler_->ShouldYieldForHighPriorityWork(); | 24 return renderer_scheduler_->ShouldYieldForHighPriorityWork(); |
23 } | 25 } |
24 | 26 |
25 void WebSchedulerImpl::runIdleTask( | 27 void WebSchedulerImpl::runIdleTask( |
26 scoped_ptr<blink::WebScheduler::IdleTask> task, | 28 scoped_ptr<blink::WebScheduler::IdleTask> task, |
27 base::TimeTicks deadline) { | 29 base::TimeTicks deadline) { |
28 task->run((deadline - base::TimeTicks()).InSecondsF()); | 30 task->run((deadline - base::TimeTicks()).InSecondsF()); |
29 } | 31 } |
30 | 32 |
31 void WebSchedulerImpl::runTask(scoped_ptr<blink::WebThread::Task> task) { | 33 void WebSchedulerImpl::runTask(scoped_ptr<blink::WebThread::Task> task) { |
32 task->run(); | 34 task->run(); |
33 } | 35 } |
34 | 36 |
35 void WebSchedulerImpl::postIdleTask(const blink::WebTraceLocation& web_location, | 37 void WebSchedulerImpl::postIdleTask(const blink::WebTraceLocation& web_location, |
36 blink::WebScheduler::IdleTask* task) { | 38 blink::WebScheduler::IdleTask* task) { |
| 39 DCHECK(idle_task_runner_); |
37 scoped_ptr<blink::WebScheduler::IdleTask> scoped_task(task); | 40 scoped_ptr<blink::WebScheduler::IdleTask> scoped_task(task); |
38 tracked_objects::Location location(web_location.functionName(), | 41 tracked_objects::Location location(web_location.functionName(), |
39 web_location.fileName(), -1, nullptr); | 42 web_location.fileName(), -1, nullptr); |
40 idle_task_runner_->PostIdleTask( | 43 idle_task_runner_->PostIdleTask( |
41 location, | 44 location, |
42 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); | 45 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); |
43 } | 46 } |
44 | 47 |
45 void WebSchedulerImpl::postLoadingTask( | 48 void WebSchedulerImpl::postLoadingTask( |
46 const blink::WebTraceLocation& web_location, blink::WebThread::Task* task) { | 49 const blink::WebTraceLocation& web_location, blink::WebThread::Task* task) { |
| 50 DCHECK(loading_task_runner_); |
47 scoped_ptr<blink::WebThread::Task> scoped_task(task); | 51 scoped_ptr<blink::WebThread::Task> scoped_task(task); |
48 tracked_objects::Location location(web_location.functionName(), | 52 tracked_objects::Location location(web_location.functionName(), |
49 web_location.fileName(), -1, nullptr); | 53 web_location.fileName(), -1, nullptr); |
50 renderer_scheduler_->LoadingTaskRunner()->PostTask( | 54 loading_task_runner_->PostTask( |
51 location, | 55 location, |
52 base::Bind(&WebSchedulerImpl::runTask, base::Passed(&scoped_task))); | 56 base::Bind(&WebSchedulerImpl::runTask, base::Passed(&scoped_task))); |
53 } | 57 } |
54 | 58 |
55 void WebSchedulerImpl::shutdown() { | 59 void WebSchedulerImpl::shutdown() { |
| 60 idle_task_runner_ = nullptr; |
| 61 loading_task_runner_ = nullptr; |
56 return renderer_scheduler_->Shutdown(); | 62 return renderer_scheduler_->Shutdown(); |
57 } | 63 } |
58 | 64 |
59 } // namespace content | 65 } // namespace content |
OLD | NEW |