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