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

Side by Side Diff: third_party/WebKit/Source/core/workers/Worklet.h

Issue 2912743002: [WIP] Worklet: Merge MainThreadWorklet and ThreadedWorklet into Worklet
Patch Set: WIP Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 Worklet_h 5 #ifndef Worklet_h
6 #define Worklet_h 6 #define Worklet_h
7 7
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "core/CoreExport.h" 9 #include "core/CoreExport.h"
10 #include "core/dom/ContextLifecycleObserver.h" 10 #include "core/dom/ContextLifecycleObserver.h"
11 #include "core/workers/WorkletGlobalScopeProxy.h"
11 #include "core/workers/WorkletOptions.h" 12 #include "core/workers/WorkletOptions.h"
12 #include "platform/bindings/ScriptWrappable.h" 13 #include "platform/bindings/ScriptWrappable.h"
13 #include "platform/heap/Handle.h" 14 #include "platform/heap/Handle.h"
14 15
15 namespace blink { 16 namespace blink {
16 17
17 class LocalFrame; 18 class LocalFrame;
18 class ScriptPromiseResolver; 19 class ScriptPromiseResolver;
19 20
20 // This is the base implementation of Worklet interface defined in the spec: 21 // This is the base implementation of Worklet interface defined in the spec:
21 // https://drafts.css-houdini.org/worklets/#worklet 22 // https://drafts.css-houdini.org/worklets/#worklet
22 // Although some worklets run off the main thread, this must be created and 23 // Although some worklets run off the main thread, this must be created and
23 // destroyed on the main thread. 24 // destroyed on the main thread.
24 class CORE_EXPORT Worklet : public GarbageCollectedFinalized<Worklet>, 25 class CORE_EXPORT Worklet : public GarbageCollectedFinalized<Worklet>,
25 public ScriptWrappable, 26 public ScriptWrappable,
26 public ContextLifecycleObserver { 27 public ContextLifecycleObserver {
27 DEFINE_WRAPPERTYPEINFO(); 28 DEFINE_WRAPPERTYPEINFO();
28 USING_GARBAGE_COLLECTED_MIXIN(Worklet); 29 USING_GARBAGE_COLLECTED_MIXIN(Worklet);
29 WTF_MAKE_NONCOPYABLE(Worklet); 30 WTF_MAKE_NONCOPYABLE(Worklet);
30 31
31 public: 32 public:
32 virtual ~Worklet() = default; 33 virtual ~Worklet() = default;
33 34
34 // Worklet.idl 35 // Worklet.idl
35 // addModule() imports ES6 module scripts. 36 // addModule() imports ES6 module scripts.
36 virtual ScriptPromise addModule(ScriptState*, 37 virtual ScriptPromise addModule(ScriptState*,
37 const String& module_url, 38 const String& module_url,
38 const WorkletOptions&); 39 const WorkletOptions&);
39 40
41 // ContextLifecycleObserver
42 void ContextDestroyed(ExecutionContext*) final;
43
40 DECLARE_VIRTUAL_TRACE(); 44 DECLARE_VIRTUAL_TRACE();
41 45
42 protected: 46 protected:
43 // The Worklet inherits the url and userAgent from the frame->document(). 47 // The Worklet inherits the url and userAgent from the frame->document().
44 explicit Worklet(LocalFrame*); 48 explicit Worklet(LocalFrame*);
45 49
50 // Returns one of available global scopes.
51 WorkletGlobalScopeProxy* FindAvailableGlobalScope() const;
52
53 size_t GetNumberOfGlobalScopes() const { return proxies_.size(); }
54
46 private: 55 private:
47 virtual void FetchAndInvokeScript(const KURL& module_url_record, 56 void FetchAndInvokeScript(const KURL& module_url_record,
48 const WorkletOptions&, 57 const WorkletOptions&,
49 ScriptPromiseResolver*) = 0; 58 ScriptPromiseResolver*);
59
60 // Returns true if there are no global scopes or additional global scopes are
61 // necessary. CreateGlobalScope() will be called in that case. Each worklet
62 // can define how to pool global scopes here.
63 virtual bool NeedsToCreateGlobalScope() = 0;
64 virtual std::unique_ptr<WorkletGlobalScopeProxy> CreateGlobalScope() = 0;
65
66 // "A Worklet has a list of the worklet's WorkletGlobalScopes. Initially this
67 // list is empty; it is populated when the user agent chooses to create its
68 // WorkletGlobalScope."
69 // https://drafts.css-houdini.org/worklets/#worklet-section
70 // TODO(nhiroki): Make (Paint)WorkletGlobalScopeProxy GC-managed object to
71 // avoid that GC graphs are disjointed (https://crbug.com/719775).
72 HashSet<std::unique_ptr<WorkletGlobalScopeProxy>> proxies_;
50 }; 73 };
51 74
52 } // namespace blink 75 } // namespace blink
53 76
54 #endif // Worklet_h 77 #endif // Worklet_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698