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

Unified Diff: Source/platform/WebScheduler.cpp

Issue 1087203002: Patch 2/3 to get WebScheduler via WebThread (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix compile Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: Source/platform/WebScheduler.cpp
diff --git a/Source/platform/WebScheduler.cpp b/Source/platform/WebScheduler.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8878d1ec29a14107c42daa44d1ba2fd8519d9d2b
--- /dev/null
+++ b/Source/platform/WebScheduler.cpp
@@ -0,0 +1,95 @@
+// 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 "config.h"
+#include "public/platform/WebScheduler.h"
+
+#include "public/platform/WebTraceLocation.h"
+#include "wtf/Assertions.h"
+#include "wtf/OwnPtr.h"
+
+#if OS(WIN)
+#include <windows.h>
+#elif OS(POSIX)
+#include <unistd.h>
+#endif
+
+namespace blink {
+
+namespace {
+#if OS(WIN)
+static_assert(sizeof(blink::PlatformThreadId) >= sizeof(DWORD), "size of platform thread id is too small");
Sami 2015/04/16 11:22:22 What's this for?
alex clarke (OOO till 29th) 2015/04/16 13:41:36 I copied that. I think we can drop it though :)
+#elif OS(POSIX)
+static_assert(sizeof(blink::PlatformThreadId) >= sizeof(pid_t), "size of platform thread id is too small");
+#else
+#error Unexpected platform
+#endif
+
+class TaskRunner : public WebThread::Task {
+ WTF_MAKE_NONCOPYABLE(TaskRunner);
+
+public:
+ explicit TaskRunner(PassOwnPtr<WebScheduler::Task> task)
+ : m_task(task)
+ {
+ }
+
+ ~TaskRunner() override
+ {
+ }
+
+ // WebThread::Task implementation.
+ void run() override
+ {
+ (*m_task)();
+ }
+private:
+ OwnPtr<WebScheduler::Task> m_task;
+};
+
+class IdleTaskRunner : public WebThread::IdleTask {
+ WTF_MAKE_NONCOPYABLE(IdleTaskRunner);
+
+public:
+ explicit IdleTaskRunner(PassOwnPtr<WebScheduler::IdleTask> task)
+ : m_task(task)
+ {
+ }
+
+ ~IdleTaskRunner() override
+ {
+ }
+
+ // WebThread::IdleTask implementation.
+ void run(double deadlineSeconds) override
+ {
+ (*m_task)(deadlineSeconds);
+ }
+private:
+ OwnPtr<WebScheduler::IdleTask> m_task;
+};
+
+} // namespace
+
+void WebScheduler::postIdleTask(const WebTraceLocation& location, PassOwnPtr<IdleTask> idleTask)
+{
+ postIdleTask(location, new IdleTaskRunner(idleTask));
+}
+
+void WebScheduler::postNonNestableIdleTask(const WebTraceLocation& location, PassOwnPtr<IdleTask> idleTask)
+{
+ postNonNestableIdleTask(location, new IdleTaskRunner(idleTask));
+}
+
+void WebScheduler::postIdleTaskAfterWakeup(const WebTraceLocation& location, PassOwnPtr<IdleTask> idleTask)
+{
+ postIdleTaskAfterWakeup(location, new IdleTaskRunner(idleTask));
+}
+
+void WebScheduler::postLoadingTask(const WebTraceLocation& location, PassOwnPtr<Task> task)
+{
+ postLoadingTask(location, new TaskRunner(task));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698