Chromium Code Reviews| Index: third_party/WebKit/Source/core/workers/ParentFrameTaskRunners.h |
| diff --git a/third_party/WebKit/Source/core/workers/ParentFrameTaskRunners.h b/third_party/WebKit/Source/core/workers/ParentFrameTaskRunners.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ac851fad65b8e300c380d575591df6c369685c63 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/workers/ParentFrameTaskRunners.h |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2016 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 ParentFrameTaskRunners_h |
| +#define ParentFrameTaskRunners_h |
| + |
| +#include "core/CoreExport.h" |
| +#include "core/dom/TaskRunnerHelper.h" |
| +#include "core/frame/LocalFrameLifecycleObserver.h" |
| +#include "platform/heap/Handle.h" |
| +#include "wtf/Allocator.h" |
| +#include "wtf/Noncopyable.h" |
| +#include "wtf/PtrUtil.h" |
| +#include <memory> |
| + |
| +namespace blink { |
| + |
| +class LocalFrame; |
| +class WebTaskRunner; |
| + |
| +// Represents a set of task runners of the parent (or associated) document's |
| +// frame. This could be accessed from worker thread(s) and must be initialized |
| +// on the parent context thread (i.e. MainThread) on construction time, rather |
| +// than being done lazily. |
| +// |
| +// This observes LocalFrame lifecycle only for in-process worker cases (i.e. |
| +// only when a non-null LocalFrame is given). |
| +class CORE_EXPORT ParentFrameTaskRunners final : public GarbageCollectedFinalized<ParentFrameTaskRunners>, public LocalFrameLifecycleObserver { |
| + USING_GARBAGE_COLLECTED_MIXIN(ParentFrameTaskRunners); |
| + WTF_MAKE_NONCOPYABLE(ParentFrameTaskRunners); |
| + |
| +public: |
| + // LocalFrame could be nullptr if the worker is not associated with a |
| + // particular local frame. |
| + explicit ParentFrameTaskRunners(LocalFrame*); |
| + |
| + // Might return nullptr for unsupported task types for Workers. |
| + WebTaskRunner* get(TaskType); |
| + |
| + DECLARE_VIRTUAL_TRACE(); |
| + |
| +private: |
| + struct TaskTypeTraits : WTF::GenericHashTraits<TaskType> { |
|
haraken
2016/08/12 00:55:45
Shall we move this to TaskRunnerHelper.h?
kinuko
2016/08/15 22:56:19
Done.
|
| + static const bool emptyValueIsZero = false; |
| + static TaskType emptyValue() { return static_cast<TaskType>(std::numeric_limits<unsigned>::max()); } |
| + static void constructDeletedValue(TaskType& slot, bool) { slot = static_cast<TaskType>(-1); } |
| + static bool isDeletedValue(TaskType value) { return value == static_cast<TaskType>(-1); } |
| + }; |
| + using TaskRunnerHash = HashMap<TaskType, WebTaskRunner*, WTF::IntHash<TaskType>, TaskTypeTraits>; |
| + |
| + void contextDestroyed() override; |
| + |
| + Mutex m_taskRunnersMutex; |
| + TaskRunnerHash m_taskRunners; |
|
haraken
2016/08/12 00:55:45
TaskRunnerHash => TaskRunnerHashMap
kinuko
2016/08/15 22:56:19
Done.
|
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // ParentFrameTaskRunners_h |