OLD | NEW |
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 "content/renderer/scheduler/webthread_impl_for_scheduler.h" | 5 #include "content/renderer/scheduler/webthread_impl_for_scheduler.h" |
6 | 6 |
7 #include "content/renderer/scheduler/renderer_scheduler.h" | 7 #include "content/renderer/scheduler/renderer_scheduler.h" |
8 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | 8 #include "third_party/WebKit/public/platform/WebTraceLocation.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 WebThreadImplForScheduler::WebThreadImplForScheduler( | 12 WebThreadImplForScheduler::WebThreadImplForScheduler( |
13 RendererScheduler* scheduler) | 13 RendererScheduler* scheduler) |
14 : task_runner_(scheduler->DefaultTaskRunner()), | 14 : task_runner_(scheduler->DefaultTaskRunner()), |
15 scheduler_(scheduler), | 15 scheduler_(scheduler), |
16 thread_id_(base::PlatformThread::CurrentId()) { | 16 thread_id_(base::PlatformThread::CurrentId()) { |
17 } | 17 } |
18 | 18 |
19 void WebThreadImplForScheduler::postTask(Task* task) { | 19 WebThreadImplForScheduler::~WebThreadImplForScheduler() { |
20 postDelayedTask(task, 0); | |
21 } | |
22 | |
23 void WebThreadImplForScheduler::postTask( | |
24 const blink::WebTraceLocation& location, | |
25 Task* task) { | |
26 postDelayedTask(location, task, 0); | |
27 } | |
28 | |
29 void WebThreadImplForScheduler::postDelayedTask(Task* task, | |
30 long long delay_ms) { | |
31 task_runner_->PostDelayedTask( | |
32 FROM_HERE, | |
33 base::Bind(RunWebThreadTask, base::Passed(make_scoped_ptr(task))), | |
34 base::TimeDelta::FromMilliseconds(delay_ms)); | |
35 } | |
36 | |
37 void WebThreadImplForScheduler::postDelayedTask( | |
38 const blink::WebTraceLocation& web_location, | |
39 Task* task, | |
40 long long delay_ms) { | |
41 tracked_objects::Location location(web_location.functionName(), | |
42 web_location.fileName(), -1, nullptr); | |
43 task_runner_->PostDelayedTask( | |
44 location, | |
45 base::Bind(RunWebThreadTask, base::Passed(make_scoped_ptr(task))), | |
46 base::TimeDelta::FromMilliseconds(delay_ms)); | |
47 } | |
48 | |
49 void WebThreadImplForScheduler::enterRunLoop() { | |
50 CHECK(isCurrentThread()); | |
51 // We don't support nesting. | |
52 CHECK(!base::MessageLoop::current()->is_running()); | |
53 base::MessageLoop::current()->Run(); | |
54 } | |
55 | |
56 void WebThreadImplForScheduler::exitRunLoop() { | |
57 CHECK(isCurrentThread()); | |
58 CHECK(base::MessageLoop::current()->is_running()); | |
59 base::MessageLoop::current()->Quit(); | |
60 } | |
61 | |
62 bool WebThreadImplForScheduler::isCurrentThread() const { | |
63 return task_runner_->BelongsToCurrentThread(); | |
64 } | 20 } |
65 | 21 |
66 blink::PlatformThreadId WebThreadImplForScheduler::threadId() const { | 22 blink::PlatformThreadId WebThreadImplForScheduler::threadId() const { |
67 return thread_id_; | 23 return thread_id_; |
68 } | 24 } |
69 | 25 |
70 WebThreadImplForScheduler::~WebThreadImplForScheduler() { | 26 base::MessageLoop* WebThreadImplForScheduler::MessageLoop() const { |
| 27 DCHECK(isCurrentThread()); |
| 28 return base::MessageLoop::current(); |
| 29 } |
| 30 |
| 31 base::SingleThreadTaskRunner* WebThreadImplForScheduler::TaskRunner() const { |
| 32 return task_runner_.get(); |
71 } | 33 } |
72 | 34 |
73 void WebThreadImplForScheduler::AddTaskObserverInternal( | 35 void WebThreadImplForScheduler::AddTaskObserverInternal( |
74 base::MessageLoop::TaskObserver* observer) { | 36 base::MessageLoop::TaskObserver* observer) { |
75 scheduler_->AddTaskObserver(observer); | 37 scheduler_->AddTaskObserver(observer); |
76 } | 38 } |
77 | 39 |
78 void WebThreadImplForScheduler::RemoveTaskObserverInternal( | 40 void WebThreadImplForScheduler::RemoveTaskObserverInternal( |
79 base::MessageLoop::TaskObserver* observer) { | 41 base::MessageLoop::TaskObserver* observer) { |
80 scheduler_->RemoveTaskObserver(observer); | 42 scheduler_->RemoveTaskObserver(observer); |
81 } | 43 } |
82 | 44 |
83 } // namespace content | 45 } // namespace content |
OLD | NEW |