| 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 "components/scheduler/child/web_scheduler_impl.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/single_thread_task_runner.h" | |
| 9 #include "components/scheduler/child/web_task_runner_impl.h" | |
| 10 #include "components/scheduler/child/worker_scheduler.h" | |
| 11 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | |
| 12 #include "third_party/WebKit/public/platform/WebViewScheduler.h" | |
| 13 | |
| 14 namespace scheduler { | |
| 15 | |
| 16 WebSchedulerImpl::WebSchedulerImpl( | |
| 17 ChildScheduler* child_scheduler, | |
| 18 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner, | |
| 19 scoped_refptr<TaskQueue> loading_task_runner, | |
| 20 scoped_refptr<TaskQueue> timer_task_runner) | |
| 21 : child_scheduler_(child_scheduler), | |
| 22 idle_task_runner_(idle_task_runner), | |
| 23 timer_task_runner_(timer_task_runner), | |
| 24 loading_web_task_runner_(new WebTaskRunnerImpl(loading_task_runner)), | |
| 25 timer_web_task_runner_(new WebTaskRunnerImpl(timer_task_runner)) {} | |
| 26 | |
| 27 WebSchedulerImpl::~WebSchedulerImpl() { | |
| 28 } | |
| 29 | |
| 30 void WebSchedulerImpl::shutdown() { | |
| 31 child_scheduler_->Shutdown(); | |
| 32 } | |
| 33 | |
| 34 bool WebSchedulerImpl::shouldYieldForHighPriorityWork() { | |
| 35 return child_scheduler_->ShouldYieldForHighPriorityWork(); | |
| 36 } | |
| 37 | |
| 38 bool WebSchedulerImpl::canExceedIdleDeadlineIfRequired() { | |
| 39 return child_scheduler_->CanExceedIdleDeadlineIfRequired(); | |
| 40 } | |
| 41 | |
| 42 void WebSchedulerImpl::runIdleTask( | |
| 43 std::unique_ptr<blink::WebThread::IdleTask> task, | |
| 44 base::TimeTicks deadline) { | |
| 45 task->run((deadline - base::TimeTicks()).InSecondsF()); | |
| 46 } | |
| 47 | |
| 48 void WebSchedulerImpl::postIdleTask(const blink::WebTraceLocation& web_location, | |
| 49 blink::WebThread::IdleTask* task) { | |
| 50 DCHECK(idle_task_runner_); | |
| 51 std::unique_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
| 52 tracked_objects::Location location(web_location.functionName(), | |
| 53 web_location.fileName(), -1, nullptr); | |
| 54 idle_task_runner_->PostIdleTask( | |
| 55 location, | |
| 56 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); | |
| 57 } | |
| 58 | |
| 59 void WebSchedulerImpl::postNonNestableIdleTask( | |
| 60 const blink::WebTraceLocation& web_location, | |
| 61 blink::WebThread::IdleTask* task) { | |
| 62 DCHECK(idle_task_runner_); | |
| 63 std::unique_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
| 64 tracked_objects::Location location(web_location.functionName(), | |
| 65 web_location.fileName(), -1, nullptr); | |
| 66 idle_task_runner_->PostNonNestableIdleTask( | |
| 67 location, | |
| 68 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); | |
| 69 } | |
| 70 | |
| 71 void WebSchedulerImpl::postIdleTaskAfterWakeup( | |
| 72 const blink::WebTraceLocation& web_location, | |
| 73 blink::WebThread::IdleTask* task) { | |
| 74 DCHECK(idle_task_runner_); | |
| 75 std::unique_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
| 76 tracked_objects::Location location(web_location.functionName(), | |
| 77 web_location.fileName(), -1, nullptr); | |
| 78 idle_task_runner_->PostIdleTaskAfterWakeup( | |
| 79 location, | |
| 80 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); | |
| 81 } | |
| 82 | |
| 83 blink::WebTaskRunner* WebSchedulerImpl::loadingTaskRunner() { | |
| 84 return loading_web_task_runner_.get(); | |
| 85 } | |
| 86 | |
| 87 blink::WebTaskRunner* WebSchedulerImpl::timerTaskRunner() { | |
| 88 return timer_web_task_runner_.get(); | |
| 89 } | |
| 90 | |
| 91 std::unique_ptr<blink::WebViewScheduler> | |
| 92 WebSchedulerImpl::createWebViewScheduler(blink::WebView*) { | |
| 93 NOTREACHED(); | |
| 94 return nullptr; | |
| 95 } | |
| 96 | |
| 97 } // namespace scheduler | |
| OLD | NEW |