OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ModuleTreeLinker_h |
| 6 #define ModuleTreeLinker_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "core/dom/AncestorList.h" |
| 10 #include "core/dom/Modulator.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class ModuleScriptFetchRequest; |
| 15 enum class ModuleGraphLevel; |
| 16 class ModuleTreeLinkerRegistry; |
| 17 |
| 18 // A ModuleTreeLinker is responsible for running and keeping intermediate states |
| 19 // for "internal module script graph fetching procedure" for a module graph tree |
| 20 // node. |
| 21 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-script
-graph-fetching-procedure |
| 22 class CORE_EXPORT ModuleTreeLinker final |
| 23 : public GarbageCollectedFinalized<ModuleTreeLinker>, |
| 24 public SingleModuleClient { |
| 25 USING_GARBAGE_COLLECTED_MIXIN(ModuleTreeLinker); |
| 26 |
| 27 public: |
| 28 static ModuleTreeLinker* Fetch(const ModuleScriptFetchRequest&, |
| 29 const AncestorList&, |
| 30 ModuleGraphLevel, |
| 31 Modulator*, |
| 32 ModuleTreeLinkerRegistry*, |
| 33 ModuleTreeClient*); |
| 34 virtual ~ModuleTreeLinker() = default; |
| 35 DECLARE_TRACE(); |
| 36 |
| 37 bool IsFetching() const { |
| 38 return State::kFetchingSelf <= state_ && state_ < State::kFinished; |
| 39 } |
| 40 bool HasFinished() const { return state_ == State::kFinished; } |
| 41 |
| 42 private: |
| 43 ModuleTreeLinker(const AncestorList& ancestor_list_with_url, |
| 44 Modulator*, |
| 45 ModuleTreeLinkerRegistry*, |
| 46 ModuleTreeClient*); |
| 47 |
| 48 enum class State { |
| 49 kInitial, |
| 50 // Running fetch of the module script corresponding to the target node. |
| 51 kFetchingSelf, |
| 52 // Running fetch of descendants of the target node. |
| 53 kFetchingDependencies, |
| 54 // Instantiating m_moduleScript and the node descendants. |
| 55 kInstantiating, |
| 56 kFinished, |
| 57 }; |
| 58 #if DCHECK_IS_ON() |
| 59 static const char* StateToString(State); |
| 60 #endif |
| 61 void AdvanceState(State); |
| 62 |
| 63 void FetchSelf(const ModuleScriptFetchRequest&, ModuleGraphLevel); |
| 64 // Implements SingleModuleClient |
| 65 void NotifyModuleLoadFinished(ModuleScript*) override; |
| 66 |
| 67 void FetchDescendants(); |
| 68 enum class DescendantLoad { kFailed, kSuccess }; |
| 69 void NotifyOneDescendantFinished(DescendantLoad was_success); |
| 70 |
| 71 void Instantiate(); |
| 72 HeapHashSet<Member<ModuleScript>> UninstantiatedInclusiveDescendants(); |
| 73 |
| 74 class DependencyModuleClient; |
| 75 friend class DependencyModuleClient; |
| 76 |
| 77 Member<Modulator> modulator_; |
| 78 Member<ModuleTreeLinkerRegistry> registry_; |
| 79 Member<ModuleTreeClient> client_; |
| 80 HashSet<KURL> ancestor_list_with_url_; |
| 81 State state_ = State::kInitial; |
| 82 Member<ModuleScript> module_script_; |
| 83 size_t num_incomplete_descendants_ = 0; |
| 84 HeapHashSet<Member<DependencyModuleClient>> dependency_clients_; |
| 85 }; |
| 86 |
| 87 } // namespace blink |
| 88 |
| 89 #endif |
OLD | NEW |