/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
namespace loader { class ScriptExecutorRunnable; class ScriptLoaderRunnable; class CachePromiseHandler; class CacheLoadHandler; class CacheCreator; class NetworkLoadHandler;
/* * [DOMDOC] WorkerScriptLoader * * The WorkerScriptLoader is the primary class responsible for loading all * Workers, including: ServiceWorkers, SharedWorkers, RemoteWorkers, and * dedicated Workers. Our implementation also includes a subtype of dedicated * workers: ChromeWorker, which exposes information that isn't normally * accessible on a dedicated worker. See [1] for more information. * * Due to constraints around fetching, this class currently delegates the * "Fetch" portion of its work load to the main thread. Unlike the DOM * ScriptLoader, the WorkerScriptLoader is not persistent and is not reused for * subsequent loads. That means for each iteration of loading (for example, * loading the main script, followed by a load triggered by ImportScripts), we * recreate this class, and handle the case independently. * * The flow of requests across the boundaries looks like this: * * +----------------------------+ * | new WorkerScriptLoader(..) | * +----------------------------+ * | * V * +-------------------------------------------+ * | WorkerScriptLoader::DispatchLoadScripts() | * +-------------------------------------------+ * | * V * +............................+ * | new ScriptLoaderRunnable() | * +............................+ * : * V * ##################################################################### * Enter Main thread * ##################################################################### * : * V * +.............................+ For each: Is a normal Worker? * | ScriptLoaderRunnable::Run() |----------------------------------+ * +.............................+ | * | V * | +----------------------------------+ * | | WorkerScriptLoader::LoadScript() | * | +----------------------------------+ * | | * | For each request: Is a ServiceWorker? | * | | * V V * +==================+ No script in cache? +====================+ * | CacheLoadHandler |------------------------>| NetworkLoadHandler | * +==================+ +====================+ * : : * : Loaded from Cache : Loaded by Network * : +..........................................+ : * +---| ScriptLoaderRunnable::OnStreamComplete() |<----+ * +..........................................+ * | * | A request is ready, is it in post order? * | * | call DispatchPendingProcessRequests() * | This creates ScriptExecutorRunnable * +..............................+ * | new ScriptLoaderExecutable() | * +..............................+ * : * V * ##################################################################### * Enter worker thread * ##################################################################### * : * V * +...............................+ All Scripts Executed? * | ScriptLoaderExecutable::Run() | -------------+ * +...............................+ : * : * : yes. Do execution * : then shutdown. * : * V * +--------------------------------------------+ * | WorkerScriptLoader::ShutdownScriptLoader() | * +--------------------------------------------+
*/
class WorkerScriptLoader : public JS::loader::ScriptLoaderInterface, public nsINamed { friendclass ScriptExecutorRunnable; friendclass ScriptLoaderRunnable; friendclass CachePromiseHandler; friendclass CacheLoadHandler; friendclass CacheCreator; friendclass NetworkLoadHandler; friendclass WorkerModuleLoader;
// Count of loading module requests. mLoadingRequests doesn't keep track of // child module requests. // This member should be accessed on worker thread.
uint32_t mLoadingModuleRequestCount;
// Worker cancellation related Mutex // // Modified on the worker thread. // It is ok to *read* this without a lock on the worker. // Main thread must always acquire a lock. bool mCleanedUp MOZ_GUARDED_BY(
mCleanUpLock); // To specify if the cleanUp() has been done.
// Ensure the worker and the main thread won't race to access |mCleanedUp|. // Should be a MutexSingleWriter, but that causes a lot of issues when you // expose the lock via Lock().
Mutex mCleanUpLock;
// Only used by import maps, crash if we get here. void ReportWarningToConsole(
ScriptLoadRequest* aRequest, constchar* aMessageName, const nsTArray<nsString>& aParams = nsTArray<nsString>()) const override {
MOZ_CRASH("Import maps have not been implemented for this context");
}
/* ScriptLoaderRunnable * * Responsibilities of this class: * - the actual dispatch * - delegating the load back to WorkerScriptLoader * - handling the collections of scripts being requested * - handling main thread cancellation * - dispatching back to the worker thread
*/ class ScriptLoaderRunnable final : public nsIRunnable, public nsINamed {
RefPtr<WorkerScriptLoader> mScriptLoader;
RefPtr<ThreadSafeWorkerRef> mWorkerRef;
nsTArrayView<RefPtr<ThreadSafeRequestHandle>> mLoadingRequests;
Maybe<nsresult> mCancelMainThread;
RefPtr<CacheCreator> mCacheCreator;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.