Index: third_party/WebKit/Source/core/workers/WorkletPendingTasks.h |
diff --git a/third_party/WebKit/Source/core/workers/WorkletPendingTasks.h b/third_party/WebKit/Source/core/workers/WorkletPendingTasks.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5de3435e5a57bbd0e4a5f067fb7c05433d10d634 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/workers/WorkletPendingTasks.h |
@@ -0,0 +1,43 @@ |
+// Copyright 2017 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. |
+ |
+#ifndef WorkletPendingTasks_h |
+#define WorkletPendingTasks_h |
+ |
+#include "bindings/core/v8/ScriptPromiseResolver.h" |
+#include "platform/heap/Heap.h" |
+ |
+namespace blink { |
+ |
+// Implementation of the "pending tasks struct": |
+// https://drafts.css-houdini.org/worklets/#pending-tasks-struct |
+// |
+// This also implements a part of the "fetch and invoke a worklet script" |
+// algorithm: |
+// https://drafts.css-houdini.org/worklets/#fetch-and-invoke-a-worklet-script |
+// |
+// All functions must be accessed on the main thread. |
+class WorkletPendingTasks final : public GarbageCollected<WorkletPendingTasks> { |
+ public: |
+ WorkletPendingTasks(int counter, ScriptPromiseResolver*); |
+ |
+ // Sets |counter_| to -1 and rejects the promise. |
+ void Abort(); |
+ |
+ // Decrements |counter_| and resolves the promise if the counter becomes 0. |
+ void DecrementCounter(); |
+ |
+ DEFINE_INLINE_VIRTUAL_TRACE() { visitor->Trace(resolver_); } |
+ |
+ private: |
+ // The number of pending tasks. -1 indicates these tasks are aborted and |
+ // |resolver_| already rejected the promise. |
+ int counter_; |
+ |
+ Member<ScriptPromiseResolver> resolver_; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // WorkletPendingTasks_h |