| 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/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 WebSchedulerImpl::WebSchedulerImpl( | |
| 15 ChildScheduler* child_scheduler, | |
| 16 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner, | |
| 17 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner, | |
| 18 scoped_refptr<base::SingleThreadTaskRunner> timer_task_runner) | |
| 19 : child_scheduler_(child_scheduler), | |
| 20 idle_task_runner_(idle_task_runner), | |
| 21 loading_task_runner_(loading_task_runner), | |
| 22 timer_task_runner_(timer_task_runner) { | |
| 23 } | |
| 24 | |
| 25 WebSchedulerImpl::~WebSchedulerImpl() { | |
| 26 } | |
| 27 | |
| 28 bool WebSchedulerImpl::shouldYieldForHighPriorityWork() { | |
| 29 return child_scheduler_->ShouldYieldForHighPriorityWork(); | |
| 30 } | |
| 31 | |
| 32 bool WebSchedulerImpl::canExceedIdleDeadlineIfRequired() { | |
| 33 return child_scheduler_->CanExceedIdleDeadlineIfRequired(); | |
| 34 } | |
| 35 | |
| 36 void WebSchedulerImpl::runIdleTask(scoped_ptr<blink::WebThread::IdleTask> task, | |
| 37 base::TimeTicks deadline) { | |
| 38 task->run((deadline - base::TimeTicks()).InSecondsF()); | |
| 39 } | |
| 40 | |
| 41 void WebSchedulerImpl::runTask(scoped_ptr<blink::WebThread::Task> task) { | |
| 42 task->run(); | |
| 43 } | |
| 44 | |
| 45 void WebSchedulerImpl::postIdleTask(const blink::WebTraceLocation& web_location, | |
| 46 blink::WebThread::IdleTask* task) { | |
| 47 DCHECK(idle_task_runner_); | |
| 48 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
| 49 tracked_objects::Location location(web_location.functionName(), | |
| 50 web_location.fileName(), -1, nullptr); | |
| 51 idle_task_runner_->PostIdleTask( | |
| 52 location, | |
| 53 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); | |
| 54 } | |
| 55 | |
| 56 void WebSchedulerImpl::postNonNestableIdleTask( | |
| 57 const blink::WebTraceLocation& web_location, | |
| 58 blink::WebThread::IdleTask* task) { | |
| 59 DCHECK(idle_task_runner_); | |
| 60 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
| 61 tracked_objects::Location location(web_location.functionName(), | |
| 62 web_location.fileName(), -1, nullptr); | |
| 63 idle_task_runner_->PostNonNestableIdleTask( | |
| 64 location, | |
| 65 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); | |
| 66 } | |
| 67 | |
| 68 void WebSchedulerImpl::postIdleTaskAfterWakeup( | |
| 69 const blink::WebTraceLocation& web_location, | |
| 70 blink::WebThread::IdleTask* task) { | |
| 71 DCHECK(idle_task_runner_); | |
| 72 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task); | |
| 73 tracked_objects::Location location(web_location.functionName(), | |
| 74 web_location.fileName(), -1, nullptr); | |
| 75 idle_task_runner_->PostIdleTaskAfterWakeup( | |
| 76 location, | |
| 77 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); | |
| 78 } | |
| 79 | |
| 80 void WebSchedulerImpl::postLoadingTask( | |
| 81 const blink::WebTraceLocation& web_location, | |
| 82 blink::WebThread::Task* task) { | |
| 83 DCHECK(loading_task_runner_); | |
| 84 scoped_ptr<blink::WebThread::Task> scoped_task(task); | |
| 85 tracked_objects::Location location(web_location.functionName(), | |
| 86 web_location.fileName(), -1, nullptr); | |
| 87 loading_task_runner_->PostTask( | |
| 88 location, | |
| 89 base::Bind(&WebSchedulerImpl::runTask, base::Passed(&scoped_task))); | |
| 90 } | |
| 91 | |
| 92 void WebSchedulerImpl::postTimerTask( | |
| 93 const blink::WebTraceLocation& web_location, | |
| 94 blink::WebThread::Task* task, | |
| 95 long long delayMs) { | |
| 96 DCHECK(timer_task_runner_); | |
| 97 scoped_ptr<blink::WebThread::Task> scoped_task(task); | |
| 98 tracked_objects::Location location(web_location.functionName(), | |
| 99 web_location.fileName(), -1, nullptr); | |
| 100 timer_task_runner_->PostDelayedTask( | |
| 101 location, | |
| 102 base::Bind(&WebSchedulerImpl::runTask, base::Passed(&scoped_task)), | |
| 103 base::TimeDelta::FromMilliseconds(delayMs)); | |
| 104 } | |
| 105 | |
| 106 } // namespace content | |
| OLD | NEW |