| Index: third_party/WebKit/Source/core/dom/TaskRunnerHelper.h
|
| diff --git a/third_party/WebKit/Source/core/dom/TaskRunnerHelper.h b/third_party/WebKit/Source/core/dom/TaskRunnerHelper.h
|
| index 4a08df5ab2851b49f8b26f5ece82f310abd86af6..c7cd6cb6a01fa154dc9dc52b817a31ef16c12fff 100644
|
| --- a/third_party/WebKit/Source/core/dom/TaskRunnerHelper.h
|
| +++ b/third_party/WebKit/Source/core/dom/TaskRunnerHelper.h
|
| @@ -5,9 +5,14 @@
|
| #ifndef TaskRunnerHelper_h
|
| #define TaskRunnerHelper_h
|
|
|
| +#include <memory>
|
| #include "core/CoreExport.h"
|
| +#include "core/dom/ContextLifecycleObserver.h"
|
| +#include "platform/WebTaskRunner.h"
|
| +#include "platform/heap/Handle.h"
|
| #include "wtf/Allocator.h"
|
| #include "wtf/HashTraits.h"
|
| +#include "wtf/PtrUtil.h"
|
|
|
| namespace blink {
|
|
|
| @@ -15,7 +20,8 @@ class Document;
|
| class ExecutionContext;
|
| class LocalFrame;
|
| class ScriptState;
|
| -class WebTaskRunner;
|
| +class WorkerOrWorkletGlobalScope;
|
| +class WorkerThread;
|
|
|
| enum class TaskType : unsigned {
|
| // Speced tasks and related internal tasks should be posted to one of
|
| @@ -121,6 +127,9 @@ enum class TaskType : unsigned {
|
| // Tasks that must not be throttled should be posted here, but the usage
|
| // should be very limited.
|
| Unthrottled,
|
| +
|
| + // Add a new type before this.
|
| + NumberOfTaskTypes,
|
| };
|
|
|
| // HashTraits for TaskType.
|
| @@ -135,19 +144,61 @@ struct TaskTypeTraits : WTF::GenericHashTraits<TaskType> {
|
| }
|
| };
|
|
|
| +class CORE_EXPORT FrameTaskRunnersHolder final
|
| + : public GarbageCollectedFinalized<FrameTaskRunnersHolder>,
|
| + public ContextLifecycleObserver {
|
| + USING_GARBAGE_COLLECTED_MIXIN(FrameTaskRunnersHolder);
|
| + WTF_MAKE_NONCOPYABLE(FrameTaskRunnersHolder);
|
| +
|
| + public:
|
| + static FrameTaskRunnersHolder* create(LocalFrame* frame) {
|
| + return new FrameTaskRunnersHolder(frame);
|
| + }
|
| +
|
| + // Might return nullptr for unsupported task types.
|
| + RefPtr<WebTaskRunner> get(TaskType);
|
| +
|
| + DECLARE_VIRTUAL_TRACE();
|
| +
|
| + private:
|
| + using TaskRunnerHashMap = HashMap<TaskType,
|
| + RefPtr<WebTaskRunner>,
|
| + WTF::IntHash<TaskType>,
|
| + TaskTypeTraits>;
|
| +
|
| + // LocalFrame could be nullptr if the worker is not associated with a
|
| + // particular local frame.
|
| + explicit FrameTaskRunnersHolder(LocalFrame*);
|
| +
|
| + void contextDestroyed(ExecutionContext*) override;
|
| +
|
| + Mutex m_taskRunnersMutex;
|
| + TaskRunnerHashMap m_taskRunners;
|
| +};
|
| +
|
| // A set of helper functions to get a WebTaskRunner for TaskType and a context
|
| // object. The posted tasks are guaranteed to run in a sequence if they have the
|
| // same TaskType and the context objects belong to the same frame.
|
| -class CORE_EXPORT TaskRunnerHelper final {
|
| - STATIC_ONLY(TaskRunnerHelper);
|
| +class CORE_EXPORT FrameTaskRunnerHelper {
|
| + STATIC_ONLY(FrameTaskRunnerHelper);
|
|
|
| public:
|
| + static void setTaskRunners(ExecutionContext*, FrameTaskRunnersHolder*);
|
| +
|
| + // Used for posting a task from the main thread.
|
| static RefPtr<WebTaskRunner> get(TaskType, LocalFrame*);
|
| static RefPtr<WebTaskRunner> get(TaskType, Document*);
|
| static RefPtr<WebTaskRunner> get(TaskType, ExecutionContext*);
|
| static RefPtr<WebTaskRunner> get(TaskType, ScriptState*);
|
| +
|
| + // Used for posting a task from a worker thread.
|
| + static RefPtr<WebTaskRunner> get(TaskType, WorkerThread*);
|
| + static RefPtr<WebTaskRunner> get(TaskType, WorkerOrWorkletGlobalScope*);
|
| };
|
|
|
| +// TODO(nhiroki): Remove this workaround.
|
| +using TaskRunnerHelper = FrameTaskRunnerHelper;
|
| +
|
| } // namespace blink
|
|
|
| #endif
|
|
|