OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MainThreadWorklet_h | 5 #ifndef MainThreadWorklet_h |
6 #define MainThreadWorklet_h | 6 #define MainThreadWorklet_h |
7 | 7 |
8 #include "core/workers/Worklet.h" | 8 #include "core/workers/Worklet.h" |
9 | 9 |
10 #include "bindings/core/v8/ScriptPromise.h" | 10 #include "bindings/core/v8/ScriptPromise.h" |
11 #include "core/CoreExport.h" | 11 #include "core/CoreExport.h" |
12 #include "platform/heap/Handle.h" | 12 #include "platform/heap/Handle.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class LocalFrame; | 16 class LocalFrame; |
17 class ScriptPromiseResolver; | 17 class ScriptPromiseResolver; |
18 class WorkletGlobalScopeProxy; | |
18 | 19 |
19 // A MainThreadWorklet is a worklet that runs only on the main thread. | 20 // A MainThreadWorklet is a worklet that runs only on the main thread. |
20 // TODO(nhiroki): This is a temporary class to support module loading for main | 21 // TODO(nhiroki): This is a temporary class to support module loading for main |
21 // thread worklets. This and ThreadedWorklet will be merged into the base | 22 // thread worklets. This and ThreadedWorklet will be merged into the base |
22 // Worklet class once threaded worklets are ready to use module loading. | 23 // Worklet class once threaded worklets are ready to use module loading. |
23 class CORE_EXPORT MainThreadWorklet : public Worklet { | 24 class CORE_EXPORT MainThreadWorklet : public Worklet { |
24 USING_GARBAGE_COLLECTED_MIXIN(MainThreadWorklet); | 25 USING_GARBAGE_COLLECTED_MIXIN(MainThreadWorklet); |
25 WTF_MAKE_NONCOPYABLE(MainThreadWorklet); | 26 WTF_MAKE_NONCOPYABLE(MainThreadWorklet); |
26 | 27 |
27 public: | 28 public: |
28 virtual ~MainThreadWorklet() = default; | 29 virtual ~MainThreadWorklet() = default; |
29 | 30 |
30 // ContextLifecycleObserver | 31 // ContextLifecycleObserver |
31 void ContextDestroyed(ExecutionContext*) final; | 32 void ContextDestroyed(ExecutionContext*) final; |
32 | 33 |
33 DECLARE_VIRTUAL_TRACE(); | 34 DECLARE_VIRTUAL_TRACE(); |
34 | 35 |
35 protected: | 36 protected: |
36 explicit MainThreadWorklet(LocalFrame*); | 37 explicit MainThreadWorklet(LocalFrame*); |
37 | 38 |
39 // Returns one of available global scopes. | |
40 WorkletGlobalScopeProxy* FindAvailableGlobalScope() const; | |
41 | |
42 size_t GetNumberOfGlobalScopes() const { return proxies_.size(); } | |
43 | |
38 private: | 44 private: |
39 // Worklet. | 45 // Worklet. |
40 void FetchAndInvokeScript(const KURL& module_url_record, | 46 void FetchAndInvokeScript(const KURL& module_url_record, |
41 const WorkletOptions&, | 47 const WorkletOptions&, |
42 ScriptPromiseResolver*) override; | 48 ScriptPromiseResolver*) override; |
49 | |
50 // Returns true if there are no global scopes or additional global scopes are | |
51 // necessary. CreateGlobalScope() will be called in that case. Each worklet | |
52 // can define how to pool global scopes here. | |
53 virtual bool NeedsToCreateGlobalScope() = 0; | |
54 virtual std::unique_ptr<WorkletGlobalScopeProxy> CreateGlobalScope() = 0; | |
55 | |
56 // "A Worklet has a list of the worklet's WorkletGlobalScopes. Initially this | |
57 // list is empty; it is populated when the user agent chooses to create its | |
58 // WorkletGlobalScope." | |
59 // https://drafts.css-houdini.org/worklets/#worklet-section | |
60 // TODO(nhiroki): Make (Paint)WorkletGlobalScopeProxy GC-managed object to | |
61 // avoid that GC graphs are disjointed (https://crbug.com/719775). | |
62 WTF::HashSet<std::unique_ptr<WorkletGlobalScopeProxy>> proxies_; | |
haraken
2017/05/29 07:38:48
WTF:: is not needed.
nhiroki
2017/05/29 08:52:00
Done.
| |
43 }; | 63 }; |
44 | 64 |
45 } // namespace blink | 65 } // namespace blink |
46 | 66 |
47 #endif // MainThreadWorklet_h | 67 #endif // MainThreadWorklet_h |
OLD | NEW |