Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: components/scheduler/child/web_scheduler_impl.cc

Issue 1309423004: Introduce WebTaskRunner Patch 4/5 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Try and fix compile Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 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 "components/scheduler/child/web_scheduler_impl.h" 5 #include "components/scheduler/child/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 "base/single_thread_task_runner.h"
9 #include "components/scheduler/child/web_task_runner_impl.h" 9 #include "components/scheduler/child/web_task_runner_impl.h"
10 #include "components/scheduler/child/worker_scheduler.h" 10 #include "components/scheduler/child/worker_scheduler.h"
11 #include "third_party/WebKit/public/platform/WebTraceLocation.h" 11 #include "third_party/WebKit/public/platform/WebTraceLocation.h"
12 12
13 namespace scheduler { 13 namespace scheduler {
14 14
15 WebSchedulerImpl::WebSchedulerImpl( 15 WebSchedulerImpl::WebSchedulerImpl(
16 ChildScheduler* child_scheduler, 16 ChildScheduler* child_scheduler,
17 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner, 17 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner,
18 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner, 18 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner,
19 scoped_refptr<TaskQueue> timer_task_runner) 19 scoped_refptr<TaskQueue> timer_task_runner)
20 : child_scheduler_(child_scheduler), 20 : child_scheduler_(child_scheduler),
21 idle_task_runner_(idle_task_runner), 21 idle_task_runner_(idle_task_runner),
22 loading_task_runner_(loading_task_runner),
23 timer_task_runner_(timer_task_runner), 22 timer_task_runner_(timer_task_runner),
24 loading_web_task_runner_(new WebTaskRunnerImpl(loading_task_runner)), 23 loading_web_task_runner_(new WebTaskRunnerImpl(loading_task_runner)),
25 timer_web_task_runner_(new WebTaskRunnerImpl(timer_task_runner)) {} 24 timer_web_task_runner_(new WebTaskRunnerImpl(timer_task_runner)) {}
26 25
27 WebSchedulerImpl::~WebSchedulerImpl() { 26 WebSchedulerImpl::~WebSchedulerImpl() {
28 } 27 }
29 28
30 void WebSchedulerImpl::shutdown() { 29 void WebSchedulerImpl::shutdown() {
31 child_scheduler_->Shutdown(); 30 child_scheduler_->Shutdown();
32 } 31 }
33 32
34 bool WebSchedulerImpl::shouldYieldForHighPriorityWork() { 33 bool WebSchedulerImpl::shouldYieldForHighPriorityWork() {
35 return child_scheduler_->ShouldYieldForHighPriorityWork(); 34 return child_scheduler_->ShouldYieldForHighPriorityWork();
36 } 35 }
37 36
38 bool WebSchedulerImpl::canExceedIdleDeadlineIfRequired() { 37 bool WebSchedulerImpl::canExceedIdleDeadlineIfRequired() {
39 return child_scheduler_->CanExceedIdleDeadlineIfRequired(); 38 return child_scheduler_->CanExceedIdleDeadlineIfRequired();
40 } 39 }
41 40
42 void WebSchedulerImpl::runIdleTask(scoped_ptr<blink::WebThread::IdleTask> task, 41 void WebSchedulerImpl::runIdleTask(scoped_ptr<blink::WebThread::IdleTask> task,
43 base::TimeTicks deadline) { 42 base::TimeTicks deadline) {
44 task->run((deadline - base::TimeTicks()).InSecondsF()); 43 task->run((deadline - base::TimeTicks()).InSecondsF());
45 } 44 }
46 45
47 void WebSchedulerImpl::runTask(scoped_ptr<blink::WebThread::Task> task) {
48 task->run();
49 }
50
51 void WebSchedulerImpl::postIdleTask(const blink::WebTraceLocation& web_location, 46 void WebSchedulerImpl::postIdleTask(const blink::WebTraceLocation& web_location,
52 blink::WebThread::IdleTask* task) { 47 blink::WebThread::IdleTask* task) {
53 DCHECK(idle_task_runner_); 48 DCHECK(idle_task_runner_);
54 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task); 49 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task);
55 tracked_objects::Location location(web_location.functionName(), 50 tracked_objects::Location location(web_location.functionName(),
56 web_location.fileName(), -1, nullptr); 51 web_location.fileName(), -1, nullptr);
57 idle_task_runner_->PostIdleTask( 52 idle_task_runner_->PostIdleTask(
58 location, 53 location,
59 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); 54 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task)));
60 } 55 }
(...skipping 15 matching lines...) Expand all
76 blink::WebThread::IdleTask* task) { 71 blink::WebThread::IdleTask* task) {
77 DCHECK(idle_task_runner_); 72 DCHECK(idle_task_runner_);
78 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task); 73 scoped_ptr<blink::WebThread::IdleTask> scoped_task(task);
79 tracked_objects::Location location(web_location.functionName(), 74 tracked_objects::Location location(web_location.functionName(),
80 web_location.fileName(), -1, nullptr); 75 web_location.fileName(), -1, nullptr);
81 idle_task_runner_->PostIdleTaskAfterWakeup( 76 idle_task_runner_->PostIdleTaskAfterWakeup(
82 location, 77 location,
83 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task))); 78 base::Bind(&WebSchedulerImpl::runIdleTask, base::Passed(&scoped_task)));
84 } 79 }
85 80
86 void WebSchedulerImpl::postLoadingTask(
87 const blink::WebTraceLocation& web_location,
88 blink::WebThread::Task* task) {
89 DCHECK(loading_task_runner_);
90 scoped_ptr<blink::WebThread::Task> scoped_task(task);
91 tracked_objects::Location location(web_location.functionName(),
92 web_location.fileName(), -1, nullptr);
93 loading_task_runner_->PostTask(
94 location,
95 base::Bind(&WebSchedulerImpl::runTask, base::Passed(&scoped_task)));
96 }
97
98 void WebSchedulerImpl::postTimerTask(
99 const blink::WebTraceLocation& web_location,
100 blink::WebThread::Task* task,
101 long long delayMs) {
102 DCHECK(timer_task_runner_);
103 scoped_ptr<blink::WebThread::Task> scoped_task(task);
104 tracked_objects::Location location(web_location.functionName(),
105 web_location.fileName(), -1, nullptr);
106 timer_task_runner_->PostDelayedTask(
107 location,
108 base::Bind(&WebSchedulerImpl::runTask, base::Passed(&scoped_task)),
109 base::TimeDelta::FromMilliseconds(delayMs));
110 }
111
112 void WebSchedulerImpl::postTimerTask(
113 const blink::WebTraceLocation& web_location,
114 blink::WebThread::Task* task,
115 double delaySecs) {
116 DCHECK(timer_task_runner_);
117 scoped_ptr<blink::WebThread::Task> scoped_task(task);
118 tracked_objects::Location location(web_location.functionName(),
119 web_location.fileName(), -1, nullptr);
120 timer_task_runner_->PostDelayedTask(
121 location,
122 base::Bind(&WebSchedulerImpl::runTask, base::Passed(&scoped_task)),
123 base::TimeDelta::FromSecondsD(delaySecs));
124 }
125
126 blink::WebTaskRunner* WebSchedulerImpl::loadingTaskRunner() { 81 blink::WebTaskRunner* WebSchedulerImpl::loadingTaskRunner() {
127 return loading_web_task_runner_.get(); 82 return loading_web_task_runner_.get();
128 } 83 }
129 84
130 blink::WebTaskRunner* WebSchedulerImpl::timerTaskRunner() { 85 blink::WebTaskRunner* WebSchedulerImpl::timerTaskRunner() {
131 return timer_web_task_runner_.get(); 86 return timer_web_task_runner_.get();
132 } 87 }
133 88
134 void WebSchedulerImpl::postTimerTaskAt( 89 void WebSchedulerImpl::postTimerTaskAt(
135 const blink::WebTraceLocation& web_location, 90 const blink::WebTraceLocation& web_location,
136 blink::WebThread::Task* task,
137 double monotonicTime) {
138 DCHECK(timer_task_runner_);
139 scoped_ptr<blink::WebThread::Task> scoped_task(task);
140 tracked_objects::Location location(web_location.functionName(),
141 web_location.fileName(), -1, nullptr);
142 timer_task_runner_->PostDelayedTaskAt(
143 location,
144 base::Bind(&WebSchedulerImpl::runTask, base::Passed(&scoped_task)),
145 base::TimeTicks() + base::TimeDelta::FromSecondsD(monotonicTime));
146 }
147
148 void WebSchedulerImpl::postTimerTaskAt(
149 const blink::WebTraceLocation& web_location,
150 blink::WebTaskRunner::Task* task, 91 blink::WebTaskRunner::Task* task,
151 double monotonicTime) { 92 double monotonicTime) {
152 DCHECK(timer_task_runner_); 93 DCHECK(timer_task_runner_);
153 tracked_objects::Location location(web_location.functionName(), 94 tracked_objects::Location location(web_location.functionName(),
154 web_location.fileName(), -1, nullptr); 95 web_location.fileName(), -1, nullptr);
155 timer_task_runner_->PostDelayedTaskAt( 96 timer_task_runner_->PostDelayedTaskAt(
156 location, base::Bind(&blink::WebTaskRunner::Task::run, base::Owned(task)), 97 location, base::Bind(&blink::WebTaskRunner::Task::run, base::Owned(task)),
157 base::TimeTicks() + base::TimeDelta::FromSecondsD(monotonicTime)); 98 base::TimeTicks() + base::TimeDelta::FromSecondsD(monotonicTime));
158 } 99 }
159 100
160 } // namespace scheduler 101 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/child/web_scheduler_impl.h ('k') | components/scheduler/child/webthread_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698