Chromium Code Reviews| 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 void WebThreadImplForScheduler::postTask(Task* task) { | |
| 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 } | |
| 65 | |
| 66 blink::PlatformThreadId WebThreadImplForScheduler::threadId() const { | |
| 67 return thread_id_; | |
| 68 } | |
| 69 | |
| 70 WebThreadImplForScheduler::~WebThreadImplForScheduler() { | |
|
alex clarke (OOO till 29th)
2015/02/13 11:02:07
nit: Shouldn't this be after the constructor?
Sami
2015/02/13 12:09:09
Fixed.
| |
| 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 |