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

Unified Diff: third_party/WebKit/Source/core/workers/WorkletPendingTasks.h

Issue 2839123003: Worklet: Introduce "pending tasks struct" concept defined in the Worklet spec (Closed)
Patch Set: address review comments Created 3 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: 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

Powered by Google App Engine
This is Rietveld 408576698