Index: content/renderer/scheduler/webthread_impl_for_scheduler.cc |
diff --git a/content/renderer/scheduler/webthread_impl_for_scheduler.cc b/content/renderer/scheduler/webthread_impl_for_scheduler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c84548d9570691c64dc9df529440df0e98f96679 |
--- /dev/null |
+++ b/content/renderer/scheduler/webthread_impl_for_scheduler.cc |
@@ -0,0 +1,83 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/renderer/scheduler/webthread_impl_for_scheduler.h" |
+ |
+#include "content/renderer/scheduler/renderer_scheduler.h" |
+#include "third_party/WebKit/public/platform/WebTraceLocation.h" |
+ |
+namespace content { |
+ |
+WebThreadImplForScheduler::WebThreadImplForScheduler( |
+ RendererScheduler* scheduler) |
+ : task_runner_(scheduler->DefaultTaskRunner()), |
+ scheduler_(scheduler), |
+ thread_id_(base::PlatformThread::CurrentId()) { |
+} |
+ |
+void WebThreadImplForScheduler::postTask(Task* task) { |
+ postDelayedTask(task, 0); |
+} |
+ |
+void WebThreadImplForScheduler::postTask( |
+ const blink::WebTraceLocation& location, |
+ Task* task) { |
+ postDelayedTask(location, task, 0); |
+} |
+ |
+void WebThreadImplForScheduler::postDelayedTask(Task* task, |
+ long long delay_ms) { |
+ task_runner_->PostDelayedTask( |
+ FROM_HERE, |
+ base::Bind(RunWebThreadTask, base::Passed(make_scoped_ptr(task))), |
+ base::TimeDelta::FromMilliseconds(delay_ms)); |
+} |
+ |
+void WebThreadImplForScheduler::postDelayedTask( |
+ const blink::WebTraceLocation& web_location, |
+ Task* task, |
+ long long delay_ms) { |
+ tracked_objects::Location location(web_location.functionName(), |
+ web_location.fileName(), -1, nullptr); |
+ task_runner_->PostDelayedTask( |
+ location, |
+ base::Bind(RunWebThreadTask, base::Passed(make_scoped_ptr(task))), |
+ base::TimeDelta::FromMilliseconds(delay_ms)); |
+} |
+ |
+void WebThreadImplForScheduler::enterRunLoop() { |
+ CHECK(isCurrentThread()); |
+ // We don't support nesting. |
+ CHECK(!base::MessageLoop::current()->is_running()); |
+ base::MessageLoop::current()->Run(); |
+} |
+ |
+void WebThreadImplForScheduler::exitRunLoop() { |
+ CHECK(isCurrentThread()); |
+ CHECK(base::MessageLoop::current()->is_running()); |
+ base::MessageLoop::current()->Quit(); |
+} |
+ |
+bool WebThreadImplForScheduler::isCurrentThread() const { |
+ return task_runner_->BelongsToCurrentThread(); |
+} |
+ |
+blink::PlatformThreadId WebThreadImplForScheduler::threadId() const { |
+ return thread_id_; |
+} |
+ |
+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.
|
+} |
+ |
+void WebThreadImplForScheduler::AddTaskObserverInternal( |
+ base::MessageLoop::TaskObserver* observer) { |
+ scheduler_->AddTaskObserver(observer); |
+} |
+ |
+void WebThreadImplForScheduler::RemoveTaskObserverInternal( |
+ base::MessageLoop::TaskObserver* observer) { |
+ scheduler_->RemoveTaskObserver(observer); |
+} |
+ |
+} // namespace content |